Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load env AWS_SECRETS_PATH #13

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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