/// <summary> /// Constructor that takes IAM token options. /// </summary> /// <param name="iamTokenOptions"></param> public Credentials(IamTokenOptions iamTokenOptions, string serviceUrl = null) { if (!string.IsNullOrEmpty(serviceUrl)) { Url = serviceUrl; } SetCredentials(iamTokenOptions, serviceUrl); }
private void SetCredentials(IamTokenOptions iamTokenOptions, string serviceUrl = null) { if (iamTokenOptions.IamApiKey.StartsWith(ICP_PREFIX)) { SetCredentials(APIKEY_AS_USERNAME, iamTokenOptions.IamApiKey, serviceUrl); } else { iamTokenManager = new IamTokenManager(iamTokenOptions); iamTokenManager.GetToken(); } }
private void SetCredentials(string username, string password, string url = null) { if (username == APIKEY_AS_USERNAME && !password.StartsWith(ICP_PREFIX)) { IamTokenOptions tokenOptions = new IamTokenOptions() { IamApiKey = password }; SetCredentials(tokenOptions, url); } else { Username = username; Password = password; } if (!string.IsNullOrEmpty(url)) { Url = url; } }
private IEnumerator CreateService() { if (string.IsNullOrEmpty(iamApikey)) { throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector."); } IamTokenOptions tokenOptions = new IamTokenOptions() { IamApiKey = iamApikey }; Credentials credentials = new Credentials(tokenOptions, serviceUrl); while (!credentials.HasTokenData()) { yield return(null); } service = new NaturalLanguageUnderstandingService(versionDate, credentials); Runnable.Run(ExampleAnalyze()); Runnable.Run(ExampleListModels()); Runnable.Run(ExampleDeleteModel()); }
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() + "_IAM_APIKEY"); // check for old IAM API key name as well if (string.IsNullOrEmpty(ApiKey)) { 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"); string AuthenticationType = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_AUTHENTICATION_TYPE"); string Icp4dAccessToken = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_ICP4D_ACCESS_TOKEN"); string Icp4dUrl = Environment.GetEnvironmentVariable(serviceId.ToUpper() + "_ICP4D_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) || AuthenticationType == "iam") { IamTokenOptions tokenOptions = new IamTokenOptions() { IamApiKey = ApiKey }; credentials = new Credentials(tokenOptions, ServiceUrl); } if (!string.IsNullOrEmpty(Icp4dAccessToken) || AuthenticationType == "icp4d") { Icp4dTokenOptions tokenOptions = new Icp4dTokenOptions() { Username = Username, Password = Password, AccessToken = Icp4dAccessToken, Url = Icp4dUrl }; credentials = new Credentials(tokenOptions, ServiceUrl); if (string.IsNullOrEmpty(credentials.Url)) { credentials.Url = url; } } else if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { credentials = new Credentials(Username, Password, url); } } }