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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/yamload/loader.rb +3 -0
- data/lib/yamload/loading/yaml.rb +27 -1
- data/lib/yamload/version.rb +1 -1
- data/spec/fixtures/erb.yml +2 -0
- data/spec/fixtures/erb_bad.yml +1 -0
- data/spec/loader_spec.rb +22 -1
- data/yamload.gemspec +2 -0
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fdcbfb71834348eec7d1a41a9083dcfb84918b564702b6ebc32ac3f69a81dbd
|
4
|
+
data.tar.gz: 9c5859db3d1e10209540447671fa67f7fac5551bd0c0352216df5afd6597029b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17cbf7b431ef2820ff545507bda639713ba2173af7286637be94b7a8820862353b50264933abef8e9d81970dda432b8823dd24292d1b2a1b67f1417fd92de4df
|
7
|
+
data.tar.gz: 36f0e38afbf4817d6a3437bcabbfa9cf73c8f6d6f929dba548371ab13427e1c3aaef7e7fc703555b0f81e4cfd97ba9113118b3cd31fd0ee53ad5bd307ce56d18
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/yamload/loader.rb
CHANGED
data/lib/yamload/loading/yaml.rb
CHANGED
@@ -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
|
data/lib/yamload/version.rb
CHANGED
data/spec/fixtures/erb.yml
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
bad_key: <%= get_parameter 'bad_key' %>
|
data/spec/loader_spec.rb
CHANGED
@@ -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
|
data/yamload.gemspec
CHANGED
@@ -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
|
+
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-
|
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
|