Ejemplo n.º 1
0
            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();
            }
Ejemplo n.º 2
0
            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();
            }
Ejemplo n.º 3
0
            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;
                }
            }
Ejemplo n.º 4
0
        public void Dispose()
        {
            foreach (KeyValuePair <string, string> envVariable in originalEnvironmentVariables)
            {
                Environment.SetEnvironmentVariable(envVariable.Key, envVariable.Value);
            }

            FallbackCredentialsFactory.Reset();
            FallbackRegionFactory.Reset();
            FallbackEndpointDiscoveryEnabledFactory.Reset();
        }
Ejemplo n.º 5
0
            public void Dispose()
            {
                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();
            }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
            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();
            }