Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5534de4
Showing
195 changed files
with
14,666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright 2019 IBM Corp. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using IBM.Cloud.SDK.Utilities; | ||
using System; | ||
|
||
namespace IBM.Cloud.SDK | ||
{ | ||
public class BaseService | ||
{ | ||
protected Credentials credentials; | ||
protected string url; | ||
|
||
public BaseService(string serviceId) | ||
{ | ||
var credentialsPaths = Utility.GetCredentialsPaths(); | ||
if (credentialsPaths.Count > 0) | ||
{ | ||
foreach (string path in credentialsPaths) | ||
{ | ||
if (Utility.LoadEnvFile(path)) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
string ApiKey = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_APIKEY"); | ||
string Username = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_USERNAME"); | ||
string Password = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_PASSWORD"); | ||
string ServiceUrl = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_URL"); | ||
|
||
if (string.IsNullOrEmpty(ApiKey) && (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))) | ||
{ | ||
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())); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(ApiKey)) | ||
{ | ||
TokenOptions tokenOptions = new TokenOptions() | ||
{ | ||
IamApiKey = ApiKey | ||
}; | ||
|
||
credentials = new Credentials(tokenOptions, ServiceUrl); | ||
|
||
if (string.IsNullOrEmpty(credentials.Url)) | ||
{ | ||
credentials.Url = url; | ||
} | ||
} | ||
|
||
if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) | ||
{ | ||
credentials = new Credentials(Username, Password, url); | ||
} | ||
} | ||
} | ||
|
||
public BaseService(string versionDate, string serviceId) : this(serviceId) { } | ||
|
||
public BaseService(string versionDate, Credentials credentials, string serviceId) { } | ||
|
||
public BaseService(Credentials credentials, string serviceId) { } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2019 IBM Corp. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace IBM.Cloud.SDK | ||
{ | ||
/// <summary> | ||
/// Success callback delegate. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the returned object.</typeparam> | ||
/// <param name="response">The returned DetailedResponse.</param> | ||
/// <param name="customData">user defined custom data including raw json.</param> | ||
public delegate void Callback<T>(DetailedResponse<T> response, IBMError error, Dictionary<string, object> customData); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.