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 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 Dispose() { foreach (KeyValuePair <string, string> envVariable in originalEnvironmentVariables) { Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value); } FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); FallbackInternalConfigurationFactory.Reset(); }
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(); FallbackInternalConfigurationFactory.Reset(); }
public FallbackFactoryTestFixture(string sharedCredsFileContent, string awsProfileValue, Dictionary <string, string> newEnvironmentVariables = 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)); originalConfigurationChain = (CredentialProfileStoreChain)ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain"); ReflectionHelpers.Invoke(typeof(FallbackInternalConfigurationFactory), "_credentialProfileChain", new CredentialProfileStoreChain(sharedFixture.CredentialsFilePath)); originalAWSProfileValue = Environment.GetEnvironmentVariable(AWS_PROFILE_ENVIRONMENT_VARIABLE); 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); } } // reset before use to ensure the new credentialProfileChains are used. FallbackCredentialsFactory.Reset(); FallbackRegionFactory.Reset(); FallbackEndpointDiscoveryEnabledFactory.Reset(); FallbackInternalConfigurationFactory.Reset(); }
private static void SetEC2InstanceMetadataEndpoint(string address) { Environment.SetEnvironmentVariable("AWS_EC2_METADATA_SERVICE_ENDPOINT", address); FallbackInternalConfigurationFactory.Reset(); }