/// <summary> /// Default constructor /// </summary> public AmazonIdentityManagementServiceConfig() { this.AuthenticationServiceName = "iam"; var region = FallbackRegionFactory.GetRegionEndpoint(false); this.RegionEndpoint = region ?? RegionEndpoint.USEast1; }
/// <summary> /// Default constructor /// </summary> public AmazonSecurityTokenServiceConfig() { this.AuthenticationServiceName = "sts"; var region = FallbackRegionFactory.GetRegionEndpoint(false); this.RegionEndpoint = region ?? RegionEndpoint.USEast1; }
public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, string enableEndpointDiscoveryValue = null) { sharedFixture = new SharedCredentialsFileTestFixture(sharedCredsFileContent); netSdkFixture = new NetSDKCredentialsFileTestFixture(); originalCredsChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalRegionChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalEndpointDiscoveryEnabledChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalAWSProfileValue = Environment.GetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE); Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, awsProfileValue); originalAWSEnableEndpointDiscoveryValue = Environment.GetEnvironmentVariable(AWS_ENABLE_ENDPOINT_DISCOVERY_ENVIRONMENT_VARIABLE); Environment.SetEnvironmentVariable(AWS_ENABLE_ENDPOINT_DISCOVERY_ENVIRONMENT_VARIABLE, enableEndpointDiscoveryValue); // reset before use to ensure the new credentialProfileChains are used. FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); }
private IAmazonS3 GetAmazonS3Client(AWSS3Labs.Web.Configuration.AmazonS3Config config) { var credentials = GetAwsCredentials(config); RegionEndpoint region = null; if (!string.IsNullOrEmpty(config.Region)) { region = RegionEndpoint.GetBySystemName(config.Region); if (region.DisplayName == "Unknown") { region = FallbackRegionFactory.GetRegionEndpoint(); } } if (string.IsNullOrEmpty(_serviceUrl)) { return(new AmazonS3Client(credentials, region)); } else { var s3Config = new Amazon.S3.AmazonS3Config { ServiceURL = _serviceUrl, RegionEndpoint = region }; return(new AmazonS3Client(credentials, s3Config)); } }
public void Dispose() { foreach (var envVariable in originalEnvironmentVariables) { Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); } Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, originalAWSProfileValue); AWSConfigs.AWSProfileName = originalAwsconfigAwsProfileName; AWSConfigs.AWSProfilesLocation = originalAwsconfigAwsProfilesLocation; ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", originalRegionChain); ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", originalCredsChain); ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain", originalEndpointDiscoveryEnabledChain); ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain", originalConfigurationChain); netSdkFixture.Dispose(); sharedFixture.Dispose(); FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); FallbackInternalConfigurationFactory.Reset(); }
public RegionEndpoint DetermineAWSRegion() { // See if a region has been set but don't prompt if not set. var regionName = this.GetStringValueOrDefault(this.Region, CommonDefinedCommandOptions.ARGUMENT_AWS_REGION, false); if (!string.IsNullOrWhiteSpace(regionName)) { return(RegionEndpoint.GetBySystemName(regionName)); } // See if we can find a region using the region fallback logic. if (string.IsNullOrWhiteSpace(regionName)) { var region = FallbackRegionFactory.GetRegionEndpoint(true); if (region != null) { return(region); } } // If we still don't have a region prompt the user for a region. regionName = this.GetStringValueOrDefault(this.Region, CommonDefinedCommandOptions.ARGUMENT_AWS_REGION, true); if (!string.IsNullOrWhiteSpace(regionName)) { return(RegionEndpoint.GetBySystemName(regionName)); } throw new ToolsException("Can not determine AWS region. Either configure a default region or use the --region option.", ToolsException.CommonErrorCode.RegionNotConfigured); }
private static void ConfigureSTSRegionalEndpoint(IConfiguration config) { // Don't set unless the user has specified in the config that they want to use the regional endpoint. if (!bool.TryParse(config[ConfigConstants.USE_STS_REGIONAL_ENDPOINTS], out bool useRegionalSTSEndpoint)) { return; } if (!useRegionalSTSEndpoint) { return; } // Don't overwrite an existing value if it has already been set. if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ConfigConstants.STS_REGIONAL_ENDPOINTS_ENV_VARIABLE))) { return; } // Don't set if we can't automatically resolve the region (required for using regional endpoints). var autoDiscoveredRegion = FallbackRegionFactory.GetRegionEndpoint(); if (autoDiscoveredRegion == null || autoDiscoveredRegion.DisplayName == "Unknown") { return; } // Set the AWS_STS_REGIONAL_ENDPOINTS environment variable to Regional. // This will mean that customers don't have to set the system-level variable. Environment.SetEnvironmentVariable(ConfigConstants.STS_REGIONAL_ENDPOINTS_ENV_VARIABLE, StsRegionalEndpointsValue.Regional.ToString()); }
public AwsCognitoUser(string _usrId, string _clientId, string _poolId, RegionEndpoint _regionEndpoint = null) { userId = _usrId; clientId = _clientId; poolId = _poolId; regionEndpoint = _regionEndpoint ?? FallbackRegionFactory.GetRegionEndpoint(); }
public S3FileStorage(S3FileStorageOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _bucket = options.Bucket; _serializer = options.Serializer ?? DefaultSerializer.Instance; _useChunkEncoding = options.UseChunkEncoding ?? true; _cannedAcl = options.CannedACL; _logger = options.LoggerFactory?.CreateLogger(typeof(S3FileStorage)) ?? NullLogger.Instance; var credentials = options.Credentials ?? FallbackCredentialsFactory.GetCredentials(); if (String.IsNullOrEmpty(options.ServiceUrl)) { var region = options.Region ?? FallbackRegionFactory.GetRegionEndpoint(); _client = new AmazonS3Client(credentials, region); } else { _client = new AmazonS3Client(credentials, new AmazonS3Config { RegionEndpoint = RegionEndpoint.USEast1, ServiceURL = options.ServiceUrl, ForcePathStyle = true, HttpClientFactory = options.HttpClientFactory }); } }
private static (AWSCredentials Creds, RegionEndpoint Region) GetAWSConfig(string profileName = null) { if (!string.IsNullOrEmpty(profileName)) { var chain = new CredentialProfileStoreChain(); AWSCredentials creds; RegionEndpoint region; if (chain.TryGetProfile(profileName, out var profile)) { region = profile.Region; } else { throw new ArgumentException($"No region profile with the name '{profileName}' was found."); } if (chain.TryGetAWSCredentials(profileName, out var credentials)) { creds = credentials; } else { throw new ArgumentException($"No credential profile with credentials found with the name '{profileName}'."); } } return(FallbackCredentialsFactory.GetCredentials(), FallbackRegionFactory.GetRegionEndpoint()); }
public AmazonSecurityTokenServiceConfig() : this() { this.set_AuthenticationServiceName("sts"); RegionEndpoint regionEndpoint = FallbackRegionFactory.GetRegionEndpoint(false); this.set_RegionEndpoint(regionEndpoint ?? RegionEndpoint.USEast1); }
/// <summary> /// Default constructor /// </summary> public AmazonSecurityTokenServiceConfig() : base(new Amazon.Runtime.Internal.DefaultConfigurationProvider(AmazonSecurityTokenServiceDefaultConfiguration.GetAllConfigurations())) { this.AuthenticationServiceName = "sts"; var region = FallbackRegionFactory.GetRegionEndpoint(false); this.RegionEndpoint = region ?? RegionEndpoint.USEast1; }
public SQSQueue(SQSQueueOptions <T> options) : base(options) { // TODO: Flow through the options like retries and the like. _client = new Lazy <AmazonSQSClient>(() => { var credentials = options.Credentials ?? FallbackCredentialsFactory.GetCredentials(); var region = options.Region ?? FallbackRegionFactory.GetRegionEndpoint() ?? RegionEndpoint.USEast1; return(new AmazonSQSClient(credentials, region)); }); }
private static RegionEndpoint GetRegionEndpoint(ProgramArgs args) { if (String.IsNullOrEmpty(args.RegionName)) { return(FallbackRegionFactory.GetRegionEndpoint(includeInstanceMetadata: true)); } return(RegionEndpoint.GetBySystemName(args.RegionName)); }
public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, Dictionary <string, string> newEnvironmentVariables = null, bool setAwsConfigsProfileValue = false) { sharedFixture = new SharedCredentialsFileTestFixture(sharedCredsFileContent); netSdkFixture = new NetSDKCredentialsFileTestFixture(); originalCredsChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalRegionChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalEndpointDiscoveryEnabledChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalConfigurationChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalAWSProfileValue = Environment.GetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE); if (!setAwsConfigsProfileValue) { Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, awsProfileValue); } if (newEnvironmentVariables != null) { foreach (var envVariable in newEnvironmentVariables) { var originalValue = Environment.GetEnvironmentVariable(envVariable.Key); Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); originalEnvironmentVariables.Add(envVariable.Key, originalValue); } } originalAwsconfigAwsProfileName = AWSConfigs.AWSProfileName; originalAwsconfigAwsProfilesLocation = AWSConfigs.AWSProfilesLocation; if (setAwsConfigsProfileValue) { AWSConfigs.AWSProfileName = awsProfileValue; AWSConfigs.AWSProfilesLocation = sharedFixture.CredentialsFilePath; } try { // reset before use to ensure the new credentialProfileChains are used. FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); FallbackInternalConfigurationFactory.Reset(); } catch (Exception ex) { // If any exceptions happen during the intial resets, perhaps due to invalid config // dispose right away to reset back to the initial configuration Dispose(); throw ex; } }
public void TestOtherProfile() { using (new FallbackFactoryTestFixture(ProfileText, "other")) { var creds = FallbackCredentialsFactory.GetCredentials(); Assert.AreEqual("other_aws_access_key_id", creds.GetCredentials().AccessKey); var region = FallbackRegionFactory.GetRegionEndpoint(false); Assert.AreEqual(RegionEndpoint.USWest1, region); } }
public void Dispose() { foreach (KeyValuePair <string, string> envVariable in originalEnvironmentVariables) { Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); } FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); }
/* * Activation of this module requires an app.config file with a MySQL section, this applies to both .NET Framework and .NET Core applications * first add a new section to config sections for MySQL * <section name="MySQL" type="MySql.Data.MySqlClient.MySqlConfiguration,MySql.Data"/> * then add a MySQL section that looks like this * <MySQL> * <Replication> * <ServerGroups> * </ServerGroups> * </Replication> * <CommandInterceptors/> * <ExceptionInterceptors/> * <AuthenticationPlugins> * <add name="mysql_clear_password" type="ReportingXpress.Common.AWS.RDS.MySQLRoleAuthenticationPlugin, ReportingXpress.Common"></add> * </AuthenticationPlugins> * </MySQL> */ ///// <summary> ///// generate a new RDS authentication ticket ///// </summary> ///// <param name="serverName"></param> ///// <param name="portNumber"></param> ///// <param name="userId"></param> ///// <returns></returns> protected override ExpiringRDSTicket GetRDSAuthenticationTicket(string serverName, int portNumber, string userId) { serverName = VerifyRdsAddress(serverName); ExpiringRDSTicket returnValue = new ExpiringRDSTicket(); RegionEndpoint regionEndPoint = FallbackRegionFactory.GetRegionEndpoint(); AWSCredentials roleCredentials = new InstanceProfileAWSCredentials(); returnValue.AuthorizationTicket = RDSAuthTokenGenerator.GenerateAuthToken(roleCredentials, regionEndPoint, serverName, portNumber, userId); //tickets expire in 15 minutes, but Windows time drift is up to a minute in this case, so give it a buffer of 3 minutes returnValue.ExpiresUtc = DateTime.UtcNow.AddMinutes(14); return(returnValue); }
public S3FileStorage(S3FileStorageOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } _credentials = options.Credentials ?? FallbackCredentialsFactory.GetCredentials(); _region = options.Region ?? FallbackRegionFactory.GetRegionEndpoint(); _bucket = options.Bucket; _serializer = options.Serializer ?? DefaultSerializer.Instance; }
public void TestAwsConfigsAwsProfileNameProfile() { using (new FallbackFactoryTestFixture(ProfileText, "awsConfigsAwsProfileName", null, true)) { var creds = FallbackCredentialsFactory.GetCredentials(); Assert.AreEqual("awsprofilename_aws_access_key_id", creds.GetCredentials().AccessKey); Assert.AreEqual("awsprofilename_aws_secret_access_key", creds.GetCredentials().SecretKey); var region = FallbackRegionFactory.GetRegionEndpoint(false); Assert.AreEqual(RegionEndpoint.EUNorth1, region); } }
public void TestProcessCredentialProfile() { using (new FallbackFactoryTestFixture(ProfileText, "processCredential")) { var credentials = FallbackCredentialsFactory.GetCredentials().GetCredentials(); Assert.AreEqual(ProcessAWSCredentialsTest.ActualAccessKey, credentials.AccessKey); Assert.AreEqual(ProcessAWSCredentialsTest.ActualSecretKey, credentials.SecretKey); var region = FallbackRegionFactory.GetRegionEndpoint(false); Assert.AreEqual(RegionEndpoint.USWest1, region); } }
public CloudWatchMetricsClient(CloudWatchMetricsClientOptions options) : base(options) { _options = options; _namespace = options.Namespace; _dimensions = options.Dimensions; _client = new Lazy <AmazonCloudWatchClient>(() => new AmazonCloudWatchClient( options.Credentials ?? FallbackCredentialsFactory.GetCredentials(), new AmazonCloudWatchConfig { LogResponse = false, DisableLogging = true, RegionEndpoint = options.Region ?? FallbackRegionFactory.GetRegionEndpoint() })); }
public void Dispose() { Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, originalAWSProfileValue); ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", originalRegionChain); ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", originalCredsChain); netSdkFixture.Dispose(); sharedFixture.Dispose(); FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); }
public void TestDefaultProfile() { using (new FallbackFactoryTestFixture(ProfileText, null)) { var creds = FallbackCredentialsFactory.GetCredentials(); Assert.AreEqual("default_aws_access_key_id", creds.GetCredentials().AccessKey); var region = FallbackRegionFactory.GetRegionEndpoint(false); Assert.AreEqual(RegionEndpoint.USWest2, region); var enabled = FallbackEndpointDiscoveryEnabledFactory.GetEnabled(); Assert.IsFalse(enabled.HasValue); } }
/// <inheritdoc/> public virtual TAWSClient GetPrimaryRegionClient() { // Get Client Credentials and Primary Region var(credentials, regionEndpoint) = AWSUtilities.GetAWSCredentialsRegion(_context); // If RegionEndpoint is null if (regionEndpoint is null) { regionEndpoint = FallbackRegionFactory.GetRegionEndpoint(); } // Setup Client with Primary Region // Check Primary Region is available return(GetOrCreateRegionClient(credentials, regionEndpoint, true, true)); }
public FallbackFactoryTestFixture(Dictionary <string, string> newEnvironmentVariables = null) { if (newEnvironmentVariables != null) { foreach (KeyValuePair <string, string> envVariable in newEnvironmentVariables) { var originalValue = Environment.GetEnvironmentVariable(envVariable.Key); Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); originalEnvironmentVariables.Add(envVariable.Key, originalValue); } } // reset before use to ensure the new credentialProfileChains are used. FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); }
public void TestOtherProfile() { using (new FallbackFactoryTestFixture(ProfileText, "other")) { var creds = FallbackCredentialsFactory.GetCredentials(); Assert.AreEqual("other_aws_access_key_id", creds.GetCredentials().AccessKey); var region = FallbackRegionFactory.GetRegionEndpoint(false); Assert.AreEqual(RegionEndpoint.USWest1, region); var enabled = FallbackEndpointDiscoveryEnabledFactory.GetEnabled(); Assert.IsTrue(enabled.HasValue); Assert.IsFalse(enabled.Value); enabled = FallbackInternalConfigurationFactory.EndpointDiscoveryEnabled; Assert.IsTrue(enabled.HasValue); Assert.IsFalse(enabled.Value); } }
public SQSQueue(SQSQueueOptions <T> options) : base(options) { // TODO: Flow through the options like retries and the like. _client = new Lazy <AmazonSQSClient>(() => { var credentials = options.Credentials ?? FallbackCredentialsFactory.GetCredentials(); if (String.IsNullOrEmpty(options.ServiceUrl)) { var region = options.Region ?? FallbackRegionFactory.GetRegionEndpoint(); return(new AmazonSQSClient(credentials, region)); } return(new AmazonSQSClient( credentials, new AmazonSQSConfig { RegionEndpoint = RegionEndpoint.USEast1, ServiceURL = options.ServiceUrl })); }); }
public void Dispose() { foreach (var envVariable in originalEnvironmentVariables) { Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); } Environment.SetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE, originalAWSProfileValue); Environment.SetEnvironmentVariable(AWS_ENABLE_ENDPOINT_DISCOVERY_ENVIRONMENT_VARIABLE, originalAWSEnableEndpointDiscoveryValue); ReflectionHelpers.Invoke(typeof(FallbackRegionFactory), "credentialProfileChain", originalRegionChain); ReflectionHelpers.Invoke(typeof(FallbackCredentialsFactory), "credentialProfileChain", originalCredsChain); ReflectionHelpers.Invoke(typeof(FallbackEndpointDiscoveryEnabledFactory), "credentialProfileChain", originalEndpointDiscoveryEnabledChain); netSdkFixture.Dispose(); sharedFixture.Dispose(); FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); }
public void TestRegionFoundFromEnvironmentVariable() { var existingValue = Environment.GetEnvironmentVariable("AWS_REGION"); try { FallbackRegionFactory.Reset(); Environment.SetEnvironmentVariable("AWS_REGION", RegionEndpoint.APSouth1.SystemName); var builder = new ConfigurationBuilder(); IConfiguration config = builder.Build(); var options = config.GetAWSOptions(); IAmazonS3 client = options.CreateServiceClient <IAmazonS3>(); Assert.Equal(RegionEndpoint.APSouth1, client.Config.RegionEndpoint); } finally { Environment.SetEnvironmentVariable("AWS_REGION", existingValue); FallbackRegionFactory.Reset(); } }