Skip to content

Commit 5534de4

Browse files
committed
inital commit
0 parents  commit 5534de4

File tree

195 files changed

+14666
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+14666
-0
lines changed

BaseService.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2019 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.Cloud.SDK.Utilities;
19+
using System;
20+
21+
namespace IBM.Cloud.SDK
22+
{
23+
public class BaseService
24+
{
25+
protected Credentials credentials;
26+
protected string url;
27+
28+
public BaseService(string serviceId)
29+
{
30+
var credentialsPaths = Utility.GetCredentialsPaths();
31+
if (credentialsPaths.Count > 0)
32+
{
33+
foreach (string path in credentialsPaths)
34+
{
35+
if (Utility.LoadEnvFile(path))
36+
{
37+
break;
38+
}
39+
}
40+
41+
string ApiKey = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_APIKEY");
42+
string Username = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_USERNAME");
43+
string Password = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_PASSWORD");
44+
string ServiceUrl = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_URL");
45+
46+
if (string.IsNullOrEmpty(ApiKey) && (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password)))
47+
{
48+
throw new NullReferenceException(string.Format("Either {0}_APIKEY or {0}_USERNAME and {0}_PASSWORD did not exist. Please add credentials with this key in ibm-credentials.env.", serviceId.ToUpper()));
49+
}
50+
51+
if (!string.IsNullOrEmpty(ApiKey))
52+
{
53+
TokenOptions tokenOptions = new TokenOptions()
54+
{
55+
IamApiKey = ApiKey
56+
};
57+
58+
credentials = new Credentials(tokenOptions, ServiceUrl);
59+
60+
if (string.IsNullOrEmpty(credentials.Url))
61+
{
62+
credentials.Url = url;
63+
}
64+
}
65+
66+
if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
67+
{
68+
credentials = new Credentials(Username, Password, url);
69+
}
70+
}
71+
}
72+
73+
public BaseService(string versionDate, string serviceId) : this(serviceId) { }
74+
75+
public BaseService(string versionDate, Credentials credentials, string serviceId) { }
76+
77+
public BaseService(Credentials credentials, string serviceId) { }
78+
}
79+
}

BaseService.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CallbackDelegates.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2019 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using System.Collections.Generic;
19+
20+
namespace IBM.Cloud.SDK
21+
{
22+
/// <summary>
23+
/// Success callback delegate.
24+
/// </summary>
25+
/// <typeparam name="T">Type of the returned object.</typeparam>
26+
/// <param name="response">The returned DetailedResponse.</param>
27+
/// <param name="customData">user defined custom data including raw json.</param>
28+
public delegate void Callback<T>(DetailedResponse<T> response, IBMError error, Dictionary<string, object> customData);
29+
}

CallbackDelegates.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Connection.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)