awsecrets 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c29dad4f0bd8650501761e00a49f27dbd12fe6fc
4
- data.tar.gz: 103c6541fbb299a1797568244453116dd74e665f
3
+ metadata.gz: a8c263296a3ce4e2f9fb5a69662b5ddc3a3b741f
4
+ data.tar.gz: 75c2f9275a2c2cf08b4ba70a91515edef7d74912
5
5
  SHA512:
6
- metadata.gz: 1ea8c0062f11c4a21b29a9079c0c196ed3d7b3292bc4322c1f18be772e87fdf4ec5d9f7e1f49b29a202385ce77cacc268ad174e5df6df0e575242245e53444ae
7
- data.tar.gz: 6653379bc0220dc0d61485b68a786c1f4ff5e8f2a109c87ddf3127fec25caea5f90cfce070c80f19db1c3c8d223ff55f0c98ea2fce9aa87a94aa48d0383f6343
6
+ metadata.gz: d9cbebe3ea145b2835b20cdda2a4326f602e1b8dee814538fbecf9d5bbd5b2145b384ee0e177a2f04aa278e47224a9bdc63e31891081c086dc72c20370c8655d
7
+ data.tar.gz: e68e024855b51cd54d33dc94660ab148019695bb724cd4dd797e96b2cae6c1c58630dad036158ee54f8aaa06dba52ba59447ad57d64c73b9cde239adf4199a47
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
1
4
  Lint/Eval:
2
5
  Enabled: false
3
6
 
@@ -25,6 +28,12 @@ Metrics/MethodLength:
25
28
  Metrics/PerceivedComplexity:
26
29
  Max: 15
27
30
 
31
+ Performance/StringReplacement:
32
+ Enabled: false
33
+
34
+ Style/Alias:
35
+ Enabled: false
36
+
28
37
  Style/BarePercentLiterals:
29
38
  Enabled: false
30
39
 
@@ -34,6 +43,12 @@ Style/ClassAndModuleChildren:
34
43
  Style/Documentation:
35
44
  Enabled: false
36
45
 
46
+ Style/MutableConstant:
47
+ Enabled: false
48
+
49
+ Style/MultilineOperationIndentation:
50
+ Enabled: false
51
+
37
52
  Style/StabbyLambdaParentheses:
38
53
  Enabled: false
39
54
 
data/README.md CHANGED
@@ -1,7 +1,17 @@
1
- # awsecrets
1
+ # awsecrets [![Gem](https://img.shields.io/gem/v/awsecrets.svg)](https://rubygems.org/gems/awsecrets) [![Travis](https://img.shields.io/travis/k1LoW/awsecrets.svg)](https://travis-ci.org/k1LoW/awsecrets)
2
2
 
3
3
  AWS credentials loader
4
4
 
5
+ ## awsecrets config precedence
6
+
7
+ 1. Command Line Options
8
+ 2. Environment Variables
9
+ 3. YAML file (secrets.yml)
10
+ 4. The AWS credentials file
11
+ 5. The CLI configuration file
12
+
13
+ (See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#config-settings-and-precedence)
14
+
5
15
  ## Installation
6
16
 
7
17
  Add this line to your application's Gemfile:
@@ -1,3 +1,3 @@
1
1
  module Awsecrets
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/awsecrets.rb CHANGED
@@ -4,26 +4,69 @@ require 'aws_config'
4
4
  require 'yaml'
5
5
 
6
6
  module Awsecrets
7
- def self.load(profile: nil, secrets_path: 'secrets.yml')
8
- profile = ENV['AWS_PROFILE'] if profile.nil?
9
- if profile
10
- # SharedCredentials
11
- aws_config = AWSConfig.profiles[profile]
12
- aws_config = AWSConfig.profiles['default'] unless aws_config
13
- Aws.config[:region] = aws_config.config_hash[:region] if aws_config
14
- Aws.config[:credentials] = Aws::SharedCredentials.new(profile_name: profile)
15
- else
16
- # secrets.yml
17
- creds = YAML.load_file(secrets_path) if File.exist?(secrets_path)
18
- return if creds.nil?
19
- Aws.config.update({
20
- region: creds['region']
21
- }) if creds.include?('region')
22
- Aws.config.update({
23
- credentials: Aws::Credentials.new(
24
- creds['aws_access_key_id'],
25
- creds['aws_secret_access_key'])
26
- }) if creds.include?('aws_access_key_id') && creds.include?('aws_secret_access_key')
7
+ def self.load(profile: nil, region: nil, secrets_path: 'secrets.yml')
8
+ @profile = profile
9
+ @secrets_path = secrets_path
10
+ @region = region
11
+ @credentials = nil
12
+
13
+ # 1. Command Line Options
14
+ load_command
15
+ # 2. Environment Variables
16
+ load_env
17
+ # 3. YAML file (secrets.yml)
18
+ load_yaml
19
+ # 4. The AWS credentials file
20
+ load_creds
21
+ # 5. The CLI configuration file
22
+ load_config
23
+
24
+ Aws.config[:region] = @region
25
+ Aws.config[:credentials] = @credentials
26
+ end
27
+
28
+ def self.load_command
29
+ return unless @profile
30
+ aws_config = AWSConfig.profiles[@profile]
31
+ @region = aws_config.config_hash[:region] if aws_config
32
+ @credentials = Aws::SharedCredentials.new(profile_name: @profile)
33
+ end
34
+
35
+ def self.load_env
36
+ @region = ENV['AWS_REGION'] unless @region
37
+ @region = ENV['AWS_DEFAULT_REGION'] unless @region
38
+ if @credentials.nil? && ENV['AWS_PROFILE']
39
+ @credentials = Aws::SharedCredentials.new(profile_name: ENV['AWS_PROFILE'])
40
+ @profile = ENV['AWS_PROFILE']
27
41
  end
42
+ if @credentials.nil? && ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
43
+ @credentials = @credentials = Aws::Credentials.new(
44
+ ENV['AWS_ACCESS_KEY_ID'],
45
+ ENV['AWS_SECRET_ACCESS_KEY'])
46
+ end
47
+ end
48
+
49
+ def self.load_yaml
50
+ creds = YAML.load_file(@secrets_path) if File.exist?(@secrets_path)
51
+ if @region.nil? && creds
52
+ @region = creds['region'] if creds.include?('region')
53
+ end
54
+ if @credentials.nil? && creds && creds.include?('aws_access_key_id') && creds.include?('aws_secret_access_key')
55
+ @credentials = Aws::Credentials.new(
56
+ creds['aws_access_key_id'],
57
+ creds['aws_secret_access_key'])
58
+ end
59
+ end
60
+
61
+ def self.load_creds
62
+ return unless @credentials.nil?
63
+ @credentials = Aws::SharedCredentials.new(profile_name: nil)
64
+ end
65
+
66
+ def self.load_config
67
+ return unless @region.nil?
68
+ aws_config = AWSConfig.profiles[@profile]
69
+ aws_config = AWSConfig.profiles['default'] unless aws_config
70
+ @region = aws_config.config_hash[:region] if aws_config
28
71
  end
29
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsecrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.2.2
165
+ rubygems_version: 2.4.5.1
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: AWS credentials loader