Example #1
0
        private IAmazonEC2 GetAwsClient(ConDepSettings settings, AwsEc2DiscoverOptionsValues awsOptions)
        {
            var creds  = GetAwsCredentials(settings, awsOptions);
            var region = GetAwsRegion(settings, awsOptions);

            return(new AmazonEC2Client(creds, region));
        }
Example #2
0
        private AWSCredentials GetAwsCredentials(ConDepSettings settings, AwsEc2DiscoverOptionsValues awsOptions)
        {
            if (awsOptions.Credentials != null)
            {
                return(awsOptions.Credentials);
            }

            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;

            if (dynamicAwsConfig != null)
            {
                string profileName = dynamicAwsConfig.Credentials.ProfileName;
                if (string.IsNullOrEmpty(profileName))
                {
                    if (dynamicAwsConfig.Credentials.AccessKey == null)
                    {
                        throw new OperationConfigException(string.Format("Configuration in environment configuration file for Credentials.AccessKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.", GetType().Name));
                    }
                    if (dynamicAwsConfig.Credentials.SecretKey == null)
                    {
                        throw new OperationConfigException(string.Format("Configuration in environment configuration file for Credentials.SecretKey must be present for operation {0}. Optionally you can use AWS credential profile instead, but then ProfileName must be present.", GetType().Name));
                    }

                    return(new BasicAWSCredentials((string)dynamicAwsConfig.Credentials.AccessKey, (string)dynamicAwsConfig.Credentials.SecretKey));
                }

                return(new StoredProfileAWSCredentials((string)dynamicAwsConfig.Credentials.ProfileName));
            }

            throw new OperationConfigException(string.Format("AWS Credentials must be provided either through DSL or in configuration for operation {0}.", GetType().Name));
        }
Example #3
0
        private RegionEndpoint GetAwsRegion(ConDepSettings settings, AwsEc2DiscoverOptionsValues awsOptions)
        {
            if (awsOptions.RegionEndpoint != null)
            {
                return(awsOptions.RegionEndpoint);
            }

            var dynamicAwsConfig = settings.Config.OperationsConfig.Aws;

            if (dynamicAwsConfig != null)
            {
                if (!string.IsNullOrWhiteSpace((string)dynamicAwsConfig.Region))
                {
                    return(RegionEndpoint.GetBySystemName((string)dynamicAwsConfig.Region));
                }
            }

            throw new OperationConfigException(string.Format("AWS Region must be provided either through DSL or in configuration for operation {0}.", GetType().Name));
        }
Example #4
0
 public AwsEc2DiscoverOperation(List <KeyValuePair <string, string> > tagValues, AwsEc2DiscoverOptionsValues awsOptions)
 {
     _tags       = tagValues;
     _awsOptions = awsOptions;
 }