public SenderCredentials(SdkConfig config) { string envProfileName = Environment.GetEnvironmentVariable(SenderProfileEnvName); if (String.IsNullOrWhiteSpace(envProfileName)) { envProfileName = DefaultSenderProfile; } if (String.IsNullOrWhiteSpace(config.ProfileName)) { config.ProfileName = envProfileName; } if (String.IsNullOrWhiteSpace(config.SenderId)) { config.SenderId = Environment.GetEnvironmentVariable(SenderIdEnvName); } if (String.IsNullOrWhiteSpace(config.SenderPassword)) { config.SenderPassword = Environment.GetEnvironmentVariable(SenderPasswordEnvName); } if ( String.IsNullOrWhiteSpace(config.SenderId) && String.IsNullOrWhiteSpace(config.SenderPassword) && !String.IsNullOrWhiteSpace(config.ProfileName) ) { ProfileCredentialProvider profileProvider = new ProfileCredentialProvider(); SdkConfig profileCreds = profileProvider.GetSenderCredentials(config); config.SenderId = !String.IsNullOrWhiteSpace(profileCreds.SenderId) ? profileCreds.SenderId : config.SenderId; config.SenderPassword = !String.IsNullOrWhiteSpace(profileCreds.SenderPassword) ? profileCreds.SenderPassword : config.SenderPassword; // Stop overwriting the Endpoint URL if it was passed in already config.EndpointUrl = !String.IsNullOrWhiteSpace(config.EndpointUrl) ? config.EndpointUrl : profileCreds.EndpointUrl; } if (String.IsNullOrWhiteSpace(config.SenderId)) { throw new ArgumentException("Required SenderId not supplied in params or env variable \"" + SenderIdEnvName + "\""); } if (String.IsNullOrWhiteSpace(config.SenderPassword)) { throw new ArgumentException("Required SenderPassword not supplied in params or env variable \"" + SenderPasswordEnvName + "\""); } SenderId = config.SenderId; Password = config.SenderPassword; Endpoint = new Endpoint(config); }
public LoginCredentials(SdkConfig config, SenderCredentials senderCreds) { string envProfileName = Environment.GetEnvironmentVariable(CompanyProfileEnvName); if (String.IsNullOrWhiteSpace(envProfileName)) { envProfileName = DefaultCompanyProfile; } if (String.IsNullOrWhiteSpace(config.ProfileName)) { config.ProfileName = envProfileName; } if (String.IsNullOrWhiteSpace(config.CompanyId)) { config.CompanyId = Environment.GetEnvironmentVariable(CompanyIdEnvName); } if (String.IsNullOrWhiteSpace(config.UserId)) { config.UserId = Environment.GetEnvironmentVariable(UserIdEnvName); } if (String.IsNullOrWhiteSpace(config.UserPassword)) { config.UserPassword = Environment.GetEnvironmentVariable(UserPasswordEnvName); } if ( String.IsNullOrWhiteSpace(config.CompanyId) && String.IsNullOrWhiteSpace(config.UserId) && String.IsNullOrWhiteSpace(config.UserPassword) && !String.IsNullOrWhiteSpace(config.ProfileName) ) { ProfileCredentialProvider profileProvider = new ProfileCredentialProvider(); SdkConfig profileCreds = profileProvider.GetLoginCredentials(config); config.CompanyId = !String.IsNullOrWhiteSpace(profileCreds.CompanyId) ? profileCreds.CompanyId : config.CompanyId; config.UserId = !String.IsNullOrWhiteSpace(profileCreds.UserId) ? profileCreds.UserId : config.UserId; config.UserPassword = !String.IsNullOrWhiteSpace(profileCreds.UserPassword) ? profileCreds.UserPassword : config.UserPassword; } if (String.IsNullOrWhiteSpace(config.CompanyId)) { throw new ArgumentException("Required CompanyId not supplied in params or env variable \"" + CompanyIdEnvName + "\""); } if (String.IsNullOrWhiteSpace(config.UserId)) { throw new ArgumentException("Required UserId not supplied in params or env variable \"" + UserIdEnvName + "\""); } if (String.IsNullOrWhiteSpace(config.UserPassword)) { throw new ArgumentException("Required UserPassword not supplied in params or env variable \"" + UserPasswordEnvName + "\""); } CompanyId = config.CompanyId; UserId = config.UserId; Password = config.UserPassword; SenderCreds = senderCreds; MockHandler = config.MockHandler; Logger = config.Logger; LogMessageFormat = config.LogFormatter; LogLevel = config.LogLevel; }