yamload 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 40beadb62d3a94fe8748b01bcfc6a6bbdceab9b2b1fc3714c0d3f11ebb3b60a5
4
- data.tar.gz: 7d7ed0b674fb0789713cd3e1f17e1a3d209481958211ed4f11af1a0afc10c5fb
3
+ metadata.gz: 4fdcbfb71834348eec7d1a41a9083dcfb84918b564702b6ebc32ac3f69a81dbd
4
+ data.tar.gz: 9c5859db3d1e10209540447671fa67f7fac5551bd0c0352216df5afd6597029b
5
5
  SHA512:
6
- metadata.gz: '0149617ac1537ae5506b2607d8b8bae3bd91df1f5b6a53dbc1532eaf659afa52457c99fd277e318cc13ad18c5ed67f2aed68890ee8796b3731463dbb815de5ea'
7
- data.tar.gz: a0bb5514455b867b09023ffe2df09427a9c717d6bb2e6cf567e80d328a27ebbb37929df0d21580abcd54a95e9905fd74face6a7488a26926948b9b90d1e41361
6
+ metadata.gz: 17cbf7b431ef2820ff545507bda639713ba2173af7286637be94b7a8820862353b50264933abef8e9d81970dda432b8823dd24292d1b2a1b67f1417fd92de4df
7
+ data.tar.gz: 36f0e38afbf4817d6a3437bcabbfa9cf73c8f6d6f929dba548371ab13427e1c3aaef7e7fc703555b0f81e4cfd97ba9113118b3cd31fd0ee53ad5bd307ce56d18
@@ -11,3 +11,5 @@ notifications:
11
11
  secure: UInYCeoRfF7FEnNgW38nZDk3SXWfWN5rm+tKDWX/eWGIIUuynspe6A8776w+wG+9jSuzGt9J3WEIxxognkYiWmud96NYiKZIQDLx/6ql15A9jEvWwqnWbnaL4F368ujhwLo6V42Z6wRfTUqNeRQKki2WCw0NVmT6Y1bdTeNNy70=
12
12
  sudo: false
13
13
  cache: bundler
14
+ env:
15
+ - AWS_REGION: us-east-1
@@ -1,3 +1,7 @@
1
+ ## 0.5.0 (2020-07-02)
2
+
3
+ - [TT-7683] Add support for AWS SSM and AWS Secrets Manager
4
+
1
5
  ## 0.4.0 (2020-05-20)
2
6
 
3
7
  - [TT-7323] Bring all dependencies up to date
@@ -1,5 +1,8 @@
1
1
  require 'yaml'
2
2
  require 'ice_nine'
3
+ require 'aws-sdk-secretsmanager'
4
+ require 'aws-sdk-ssm'
5
+
3
6
  require 'yamload/loading'
4
7
  require 'yamload/conversion'
5
8
  require 'yamload/defaults'
@@ -33,7 +33,7 @@ module Yamload
33
33
 
34
34
  def erb_parsed_content
35
35
  raw_content = File.read(filepath, encoding: 'bom|utf-8', mode: 'r')
36
- ERB.new(raw_content).result
36
+ ERB.new(raw_content).result(binding)
37
37
  end
38
38
 
39
39
  def filepath
@@ -41,6 +41,32 @@ module Yamload
41
41
  fail IOError, "#{@dir} is not a valid directory" unless File.directory?(@dir)
42
42
  File.join(@dir, "#{@file}.yml")
43
43
  end
44
+
45
+ def secrets_client
46
+ options = {}
47
+ options[:endpoint] = ENV['AWS_SECRETS_MANAGER_ENDPOINT'] if ENV.has_key?('AWS_SECRETS_MANAGER_ENDPOINT')
48
+ @secrets_client ||= Aws::SecretsManager::Client.new(options)
49
+ end
50
+
51
+ def get_secret(key)
52
+ secrets_client.get_secret_value(secret_id: key).secret_string
53
+ end
54
+
55
+ def ssm_client
56
+ options = {}
57
+ options[:endpoint] = ENV['AWS_SSM_ENDPOINT'] if ENV.has_key?('AWS_SSM_ENDPOINT')
58
+ @ssm_client ||= Aws::SSM::Client.new(options)
59
+ end
60
+
61
+ def get_parameter(key, encrypted: true)
62
+ ssm_client.get_parameter(
63
+ name: key,
64
+ with_decryption: encrypted
65
+ ).parameter.value
66
+ rescue Aws::SSM::Errors::ParameterNotFound => e
67
+ puts "Parameter #{key} not found"
68
+ raise e
69
+ end
44
70
  end
45
71
  end
46
72
  end
@@ -1,3 +1,3 @@
1
1
  module Yamload
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,2 +1,4 @@
1
1
  ---
2
2
  erb_var: <%= 'ERB RAN!' %>
3
+ ssm_var: <%= get_parameter 'ssm_var' %>
4
+ secret_var: <%= get_secret 'secret_var' %>
@@ -0,0 +1 @@
1
+ bad_key: <%= get_parameter 'bad_key' %>
@@ -32,10 +32,31 @@ describe Yamload::Loader do
32
32
  end
33
33
 
34
34
  context 'with a file containing ERB' do
35
+ before do
36
+ allow_any_instance_of(Aws::SSM::Client).to receive(:get_parameter).
37
+ with({ name: 'ssm_var', with_decryption: true }).
38
+ and_return(double(parameter: double(value: 'SSM SUCCESS')))
39
+ allow_any_instance_of(Aws::SecretsManager::Client).to receive(:get_secret_value).
40
+ with({ secret_id: 'secret_var' }).
41
+ and_return(double(secret_string: 'SECRET SUCCESS'))
42
+ end
43
+
35
44
  let(:file) { :erb }
36
- let(:expected_content) { { "erb_var" => "ERB RAN!" } }
45
+ let(:expected_content) { { "erb_var" => "ERB RAN!", "ssm_var" => "SSM SUCCESS", "secret_var" => "SECRET SUCCESS" } }
37
46
  specify { expect(loader).to exist }
38
47
  specify { expect(content).to eq expected_content }
48
+
49
+ context 'with bad parameter key' do
50
+ before do
51
+ allow_any_instance_of(Aws::SSM::Client).to receive(:get_parameter).
52
+ with({ name: 'bad_key', with_decryption: true }).
53
+ and_raise(Aws::SSM::Errors::ParameterNotFound.new(Seahorse, 'bad_key'))
54
+ end
55
+ let(:file) { :erb_bad }
56
+ specify {
57
+ expect { content }.to raise_error Aws::SSM::Errors::ParameterNotFound
58
+ }
59
+ end
39
60
  end
40
61
 
41
62
  context 'with a file defining an array' do
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'anima', '>= 0.2'
24
24
  spec.add_dependency 'facets', '>= 3.0'
25
+ spec.add_dependency 'aws-sdk-secretsmanager'
26
+ spec.add_dependency 'aws-sdk-ssm'
25
27
 
26
28
  spec.add_development_dependency 'bundler', '>= 1.7'
27
29
  spec.add_development_dependency 'rake', '>= 10.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Berardi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-05-20 00:00:00.000000000 Z
12
+ date: 2020-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anima
@@ -39,6 +39,34 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '3.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: aws-sdk-secretsmanager
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: aws-sdk-ssm
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
42
70
  - !ruby/object:Gem::Dependency
43
71
  name: bundler
44
72
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +212,7 @@ files:
184
212
  - spec/fixtures/array.yml
185
213
  - spec/fixtures/empty.yml
186
214
  - spec/fixtures/erb.yml
215
+ - spec/fixtures/erb_bad.yml
187
216
  - spec/fixtures/string.yml
188
217
  - spec/fixtures/test.yml
189
218
  - spec/loader_spec.rb
@@ -218,6 +247,7 @@ test_files:
218
247
  - spec/fixtures/array.yml
219
248
  - spec/fixtures/empty.yml
220
249
  - spec/fixtures/erb.yml
250
+ - spec/fixtures/erb_bad.yml
221
251
  - spec/fixtures/string.yml
222
252
  - spec/fixtures/test.yml
223
253
  - spec/loader_spec.rb