lib/awsecrets.rb in awsecrets-1.0.0 vs lib/awsecrets.rb in awsecrets-1.1.0

- old
+ new

@@ -1,6 +1,7 @@ require 'awsecrets/version' +require 'optparse' require 'aws-sdk' require 'aws_config' require 'yaml' module Awsecrets @@ -9,11 +10,11 @@ @secrets_path = secrets_path @region = region @credentials = nil # 1. Command Line Options - load_command + load_options if load_method_args # 2. Environment Variables load_env # 3. YAML file (secrets.yml) load_yaml # 4. The AWS credentials file @@ -23,13 +24,29 @@ Aws.config[:region] = @region Aws.config[:credentials] = @credentials end - def self.load_command + def self.load_method_args + return false unless @profile + aws_config = AWSConfig.profiles[@profile] + @region = aws_config.config_hash[:region] if aws_config && @region.nil? + @credentials = Aws::SharedCredentials.new(profile_name: @profile) + true + end + + def self.load_options + opt = OptionParser.new + opt.on('--profile PROFILE') { |v| @profile = v } unless @profile + opt.on('--region REGION') { |v| @region = v } unless @region + opt.on('--secrets_path SECRETS_PATH') { |v| @secrets_path = v } unless @secrets_path + begin + opt.parse!(ARGV) + rescue OptionParser::InvalidOption + end return unless @profile aws_config = AWSConfig.profiles[@profile] - @region = aws_config.config_hash[:region] if aws_config + @region = aws_config.config_hash[:region] if aws_config && @region.nil? @credentials = Aws::SharedCredentials.new(profile_name: @profile) end def self.load_env @region = ENV['AWS_REGION'] unless @region