Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mediumTaj committed Mar 4, 2019
0 parents commit 5534de4
Show file tree
Hide file tree
Showing 195 changed files with 14,666 additions and 0 deletions.
79 changes: 79 additions & 0 deletions BaseService.cs
@@ -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) { }
}
}
11 changes: 11 additions & 0 deletions BaseService.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions CallbackDelegates.cs
@@ -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);
}
11 changes: 11 additions & 0 deletions CallbackDelegates.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Connection.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5534de4

Please sign in to comment.