Ejemplo n.º 1
0
        public AppConfigCSMConfigs(CSMFallbackConfigChain cSMFallbackConfigChain)
        {
            var csmConfiguration = cSMFallbackConfigChain.CSMConfiguration;
            var logger           = Logger.GetLogger(typeof(AppConfigCSMConfigs));

            if (!AWSConfigs.CSMConfig.CSMEnabled.HasValue)
            {
                return;
            }
            cSMFallbackConfigChain.IsConfigSet = true;
            if (!AWSConfigs.CSMConfig.CSMEnabled.GetValueOrDefault())
            {
                return;
            }
            cSMFallbackConfigChain.ConfigSource = "app config";
            csmConfiguration.Enabled            = AWSConfigs.CSMConfig.CSMEnabled.GetValueOrDefault();
            if (csmConfiguration.Enabled)
            {
                if (!string.IsNullOrEmpty(AWSConfigs.CSMConfig.CSMClientId))
                {
                    csmConfiguration.ClientId = AWSConfigs.CSMConfig.CSMClientId;
                }
                csmConfiguration.Host = AWSConfigs.CSMConfig.CSMHost;
                csmConfiguration.Port = AWSConfigs.CSMConfig.CSMPort;

                logger.InfoFormat(string.Format(CultureInfo.InvariantCulture,
                                                "CSM configurations found using application configuration file. values are CSM enabled = {0}, host = {1}, port = {2}, clientid = {3}",
                                                csmConfiguration.Enabled, csmConfiguration.Host, csmConfiguration.Port, csmConfiguration.ClientId));
            }
        }
Ejemplo n.º 2
0
        private void Setup(CSMFallbackConfigChain cSMFallbackConfigChain, IDictionary <string, string> profileProperties)
        {
            var    logger           = Logger.GetLogger(typeof(ProfileCSMConfigs));
            var    csmConfiguration = cSMFallbackConfigChain.CSMConfiguration;
            string csm_enabled;

            if (!profileProperties.TryGetValue(CSM_ENABLED, out csm_enabled))
            {
                return;
            }
            cSMFallbackConfigChain.IsConfigSet  = true;
            cSMFallbackConfigChain.ConfigSource = "shared profile";
            bool enabled;

            if (bool.TryParse(csm_enabled, out enabled))
            {
                csmConfiguration.Enabled = enabled;
            }
            else
            {
                throw new AmazonClientException("Unexpected profile variable value type " + CSM_ENABLED + ". Set a valid boolean value.");
            }
            if (csmConfiguration.Enabled)
            {
                string clientId;
                if (profileProperties.TryGetValue(CSM_CLIENTID, out clientId))
                {
                    csmConfiguration.ClientId = clientId;
                }
                string csm_port;
                if (profileProperties.TryGetValue(CSM_PORT, out csm_port))
                {
                    int port;
                    if (int.TryParse(csm_port, out port))
                    {
                        csmConfiguration.Port = port;
                    }
                    else
                    {
                        throw new AmazonClientException("Unexpected profile variable value type " + CSM_PORT + ". Set a valid integer value.");
                    }
                }
                string csm_host;
                if (profileProperties.TryGetValue(CSM_HOST, out csm_host))
                {
                    if (!string.IsNullOrEmpty(csm_host))
                    {
                        csmConfiguration.Host = csm_host;
                    }
                }
            }
            logger.InfoFormat(string.Format(CultureInfo.InvariantCulture,
                                            "CSM configurations found using profile store for the profile = {0}: values are CSM enabled = {1}, host = {2}, port = {3}, clientid = {4}",
                                            ProfileName, csmConfiguration.Enabled, csmConfiguration.Host, csmConfiguration.Port, csmConfiguration.ClientId));
        }
Ejemplo n.º 3
0
        public ProfileCSMConfigs(ICredentialProfileSource source, CSMFallbackConfigChain cSMFallbackConfigChain)
        {
            ProfileName = FallbackCredentialsFactory.GetProfileName();
            CredentialProfile profile;

            if (!source.TryGetProfile(ProfileName, out profile))
            {
                return;
            }
            Setup(cSMFallbackConfigChain, profile.Properties);
        }
Ejemplo n.º 4
0
        private void SetupConfiguration(CSMFallbackConfigChain cSMFallbackConfigChain)
        {
            var csmConfiguration = cSMFallbackConfigChain.CSMConfiguration;
            var logger           = Logger.GetLogger(typeof(EnvironmentVariableCSMConfigs));
            var enabled          = environmentRetriever.GetEnvironmentVariable(CSM_ENABLED);

            if (string.IsNullOrEmpty(enabled))
            {
                return;
            }
            cSMFallbackConfigChain.IsConfigSet  = true;
            cSMFallbackConfigChain.ConfigSource = "environment variable";
            bool csm_enabled;

            if (bool.TryParse(enabled, out csm_enabled))
            {
                csmConfiguration.Enabled = csm_enabled;
            }
            else
            {
                throw new AmazonClientException("Unexpected environment variable value type " + CSM_ENABLED + ". Set a valid boolean value.");
            }
            if (csmConfiguration.Enabled)
            {
                csmConfiguration.ClientId = environmentRetriever.GetEnvironmentVariable(CSM_CLIENTID) ?? csmConfiguration.ClientId;
                string portValue = environmentRetriever.GetEnvironmentVariable(CSM_PORT);
                if (!string.IsNullOrEmpty(portValue))
                {
                    int port;
                    if (int.TryParse(portValue, out port))
                    {
                        csmConfiguration.Port = port;
                    }
                    else
                    {
                        throw new AmazonClientException("Unexpected environment variable value type " + CSM_PORT + ". Set a valid integer value.");
                    }
                }

                string hostValue = environmentRetriever.GetEnvironmentVariable(CSM_HOST);
                if (!string.IsNullOrEmpty(hostValue))
                {
                    csmConfiguration.Host = hostValue;
                }
            }

            logger.InfoFormat(string.Format(CultureInfo.InvariantCulture,
                                            "CSM configurations found using environment variable. values are CSM enabled = {0}, host = {1}, port = {2}, clientid = {3}",
                                            csmConfiguration.Enabled, csmConfiguration.Host, csmConfiguration.Port, csmConfiguration.ClientId));
        }
Ejemplo n.º 5
0
        public ProfileCSMConfigs(ICredentialProfileSource source, CSMFallbackConfigChain cSMFallbackConfigChain)
        {
            ProfileName = AWSConfigs.AWSProfileName ?? Environment.GetEnvironmentVariable(FallbackCredentialsFactory.AWS_PROFILE_ENVIRONMENT_VARIABLE);

            if (string.IsNullOrEmpty(ProfileName))
            {
                ProfileName = FallbackCredentialsFactory.DefaultProfileName;
            }
            CredentialProfile profile;

            if (!source.TryGetProfile(ProfileName, out profile))
            {
                return;
            }
            Setup(cSMFallbackConfigChain, profile.Properties);
        }
Ejemplo n.º 6
0
 public EnvironmentVariableCSMConfigs(CSMFallbackConfigChain cSMFallbackConfigChain)
 {
     SetupConfiguration(cSMFallbackConfigChain);
 }
Ejemplo n.º 7
0
 public EnvironmentVariableCSMConfigs(IEnvironmentVariableRetriever environmentRetriever, CSMFallbackConfigChain cSMFallbackConfigChain)
 {
     this.environmentRetriever = environmentRetriever;
     SetupConfiguration(cSMFallbackConfigChain);
 }
Ejemplo n.º 8
0
 public ProfileCSMConfigs(CSMFallbackConfigChain cSMFallbackConfigChain, string profileName, IDictionary <string, string> profileProperties)
 {
     ProfileName = profileName;
     Setup(cSMFallbackConfigChain, profileProperties);
 }