Skip to content

Commit

Permalink
Merge pull request #13 from k1LoW/aws-secrets-path
Browse files Browse the repository at this point in the history
load env `AWS_SECRETS_PATH`
  • Loading branch information
k1LoW authored Apr 19, 2017
2 parents 72495d4 + 32ee8ff commit ac7c29f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
AllCops:
TargetRubyVersion: 2.1

Lint/Eval:
Enabled: false

Lint/HandleExceptions:
Enabled: false

Expand Down
6 changes: 4 additions & 2 deletions lib/awsecrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'yaml'

module Awsecrets
def self.load(profile: nil, region: nil, secrets_path: 'secrets.yml')
def self.load(profile: nil, region: nil, secrets_path: nil)
@profile = profile
@region = region
@secrets_path = secrets_path
Expand Down Expand Up @@ -48,6 +48,7 @@ def self.load_env
@region ||= ENV['AWS_REGION']
@region ||= ENV['AWS_DEFAULT_REGION']
@profile ||= ENV['AWS_PROFILE']
@secrets_path ||= ENV['AWS_SECRETS_PATH']
return if @access_key_id
return unless ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
@access_key_id ||= ENV['AWS_ACCESS_KEY_ID']
Expand All @@ -56,7 +57,8 @@ def self.load_env
end

def self.load_yaml
creds = YAML.load_file(@secrets_path) if File.exist?(@secrets_path)
@secrets_path ||= 'secrets.yml'
creds = YAML.load_file(@secrets_path) if File.exist?(File.expand_path(@secrets_path))
@region ||= creds['region'] if creds && creds.include?('region')
return if @access_key_id
return unless creds &&
Expand Down
9 changes: 9 additions & 0 deletions spec/configration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
expect(Aws.config[:credentials].credentials.session_token).to eq(nil)
end

it 'load secrets_other.yml via AWS_SECRETS_PATH' do
stub_const('ENV', { 'AWS_SECRETS_PATH' => File.expand_path(File.join(fixtures_path, 'secrets_other.yml')) })
Awsecrets.load
expect(Aws.config[:region]).to eq('YAML_OTHER_REGION')
expect(Aws.config[:credentials].credentials.access_key_id).to eq('YAML_OTHER_ACCESS_KEY_ID')
expect(Aws.config[:credentials].credentials.secret_access_key).to eq('YAML_OTHER_SECRET_ACCESS_KEY')
expect(Aws.config[:credentials].credentials.session_token).to eq(nil)
end

it 'load secrets_with_session_token.yml' do
Awsecrets.load(secrets_path: File.expand_path(File.join(fixtures_path, 'secrets_with_session_token.yml')))
expect(Aws.config[:region]).to eq('YAML_REGION')
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/secrets_other.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
region: YAML_OTHER_REGION
aws_access_key_id: YAML_OTHER_ACCESS_KEY_ID
aws_secret_access_key: YAML_OTHER_SECRET_ACCESS_KEY

0 comments on commit ac7c29f

Please sign in to comment.