cps-property-generator 0.2.13 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/generator/globals.rb +7 -2
- data/lib/generator/service.rb +12 -5
- data/lib/linter/globals_linter.rb +0 -1
- data/lib/linter/services_linter.rb +4 -48
- data/spec/lib/global_spec.rb +27 -5
- data/spec/lib/service_spec.rb +79 -27
- data/spec/resources/globals/accounts/123456789012/environments/my-test-env1.yml +6 -1
- data/spec/resources/globals/globals.yml +5 -1
- data/spec/resources/services/my-microservice-1.yml +15 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0cc064b6d0d8fafe9847384a929bd11f5bb9a54
|
4
|
+
data.tar.gz: 62a7bc3e50dfd64f1573098a37c762470d7ac481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a447cbbe279d63222df061d4154b07d177ff433a54949a8d94d136ddbb37ae7893d689845460b68f10a144253ab29c0c4bf9b2e908d317f281ae242c5c09eb5b
|
7
|
+
data.tar.gz: a22afe3b1933db8c83a9b43f16da69b6fefdcd364182a8f733da9588b7a84e1b98ddb0399a07cc84374658c36106ff724f7b959e22c2beb94ca0b75f67760439
|
data/README.md
CHANGED
@@ -77,6 +77,21 @@ touch globals.yml
|
|
77
77
|
1. Create a folder called `environments` inside your folder named after your account.
|
78
78
|
2. Inside the `environments` folder create a yaml file named after the environment you would like to define globals for. Only environments defined in your config are supported. The environment must also be mapped in the config to the account the sharing the same name as the folder the environment global yaml file lives in.
|
79
79
|
3. In the newly created environment's yaml file you may define your globals.
|
80
|
+
###### Encrypted Properties in Environment Globals
|
81
|
+
If you would like to pass in an encrypted property to all services in a given environment, you can pass in ckrt encrypted values by having an `encrypted` block in your environment global file.
|
82
|
+
```yaml
|
83
|
+
property_name_1: value
|
84
|
+
property_name_2: value
|
85
|
+
encrypted:
|
86
|
+
encrypted_property_1:
|
87
|
+
$ssm:
|
88
|
+
region: region
|
89
|
+
encrypted: encrypted_value
|
90
|
+
encrypted_property_2:
|
91
|
+
$ssm:
|
92
|
+
region: region
|
93
|
+
encrypted: encrypted_value
|
94
|
+
```
|
80
95
|
|
81
96
|
##### Step 3: Creating your service definitions
|
82
97
|
Service definitions have the highest level of supersedence and will overwrite matching global definitions.
|
data/lib/generator/globals.rb
CHANGED
@@ -41,6 +41,11 @@ module PropertyGenerator
|
|
41
41
|
@environments.each do |env|
|
42
42
|
next unless File.exists?("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml")
|
43
43
|
data[account][env] = YAML.load_file("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml")
|
44
|
+
unless data[account][env]['encrypted'].nil?
|
45
|
+
encrypted = data[account][env]['encrypted'].dup
|
46
|
+
not_encrypted = data[account][env].reject { |k,_| k == 'encrypted' }
|
47
|
+
data[account][env] = not_encrypted.deep_merge(encrypted)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
data
|
@@ -62,7 +67,7 @@ module PropertyGenerator
|
|
62
67
|
env_global.each do |env, hash|
|
63
68
|
account_globals[account] ||= {}
|
64
69
|
# set the environment globals to be the account global merged with the env globals
|
65
|
-
env_global[env] = account_globals[account].
|
70
|
+
env_global[env] = account_globals[account].deep_merge(hash) unless hash.empty?
|
66
71
|
condensed[env] = env_global[env]
|
67
72
|
end
|
68
73
|
end
|
@@ -75,7 +80,7 @@ module PropertyGenerator
|
|
75
80
|
# We need to merge into the globals so any env configs overwrite main global configs.
|
76
81
|
# Dup so we dont modify the original object
|
77
82
|
main_global_dup = main_global.dup
|
78
|
-
condensed[env] = main_global_dup.
|
83
|
+
condensed[env] = main_global_dup.deep_merge(condensed[env])
|
79
84
|
end
|
80
85
|
end
|
81
86
|
condensed
|
data/lib/generator/service.rb
CHANGED
@@ -50,7 +50,9 @@ module PropertyGenerator
|
|
50
50
|
|
51
51
|
# Recursively interate through the properties for an environment and gsub the config
|
52
52
|
# with defined interpolations.
|
53
|
-
|
53
|
+
service_env = Marshal.load(Marshal.dump(@service[env]))
|
54
|
+
interpolate_nested_properties(service_env, interpolations)
|
55
|
+
@service[env] = service_env
|
54
56
|
end
|
55
57
|
service
|
56
58
|
end
|
@@ -58,12 +60,17 @@ module PropertyGenerator
|
|
58
60
|
def interpolate_nested_properties(service_env, interpolations)
|
59
61
|
interpolations.each do |matcher_key, matcher_value|
|
60
62
|
service_env.each { |k,v| service_env[k] = v.gsub("{#{matcher_key}}", matcher_value) if v.class == String && v.include?("{#{matcher_key}}")}
|
61
|
-
service_env.values.each
|
63
|
+
service_env.values.each do |v|
|
64
|
+
interpolate_nested_properties(v, interpolations) if v.class == Hash
|
65
|
+
v.each_with_index do |val, idx|
|
66
|
+
v[idx] = val.gsub("{#{matcher_key}}", matcher_value) if val.class == String && val.include?("{#{matcher_key}}")
|
67
|
+
end if v.class == Array
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
64
71
|
|
65
72
|
def merge_env_default(data, environments)
|
66
|
-
#creates a hash of the
|
73
|
+
#creates a hash of the environments merged with the defaults
|
67
74
|
# {service => {env1 => {properties},
|
68
75
|
# env2 => {properties}
|
69
76
|
# }
|
@@ -84,7 +91,7 @@ module PropertyGenerator
|
|
84
91
|
if default_clone.nil?
|
85
92
|
merged = environment_data
|
86
93
|
else
|
87
|
-
merged = default_clone.
|
94
|
+
merged = default_clone.deep_merge(environment_data)
|
88
95
|
end
|
89
96
|
output[env] = merged
|
90
97
|
end
|
@@ -100,7 +107,7 @@ module PropertyGenerator
|
|
100
107
|
if globals_clone[env].nil? || globals_clone[env] == false
|
101
108
|
merged = service_data[env]
|
102
109
|
else
|
103
|
-
merged = globals_clone[env].
|
110
|
+
merged = globals_clone[env].deep_merge(service_data[env])
|
104
111
|
end
|
105
112
|
output[env] = merged
|
106
113
|
end
|
@@ -16,9 +16,7 @@ module PropertyGenerator
|
|
16
16
|
tests = [
|
17
17
|
'services_have_accepted_keys',
|
18
18
|
'service_environments_are_not_empty',
|
19
|
-
'service_defaults_have_no_hashes_as_values',
|
20
19
|
'service_environments_match_config_environments',
|
21
|
-
'service_environments_have_no_hashes_as_values',
|
22
20
|
'service_encrypted_environments_match_config_environments',
|
23
21
|
'service_encrypted_fields_are_correct',
|
24
22
|
'service_encrypted_region_field_is_accepted'
|
@@ -48,7 +46,7 @@ module PropertyGenerator
|
|
48
46
|
|
49
47
|
def services_have_accepted_keys
|
50
48
|
status = {status: 'pass', error: ''}
|
51
|
-
accepted_keys = ['default', 'environments', 'encrypted', 'configname', 'stringdata', 'configlabels', 'secretlabels']
|
49
|
+
accepted_keys = ['default', 'environments', 'encrypted', 'configname', 'stringdata', 'configlabels', 'secretlabels', 'label']
|
52
50
|
services_with_unacceptable_keys = []
|
53
51
|
@services.each do |path, loaded|
|
54
52
|
loaded.keys.each do |service_key|
|
@@ -59,26 +57,7 @@ module PropertyGenerator
|
|
59
57
|
end
|
60
58
|
if services_with_unacceptable_keys != []
|
61
59
|
status[:status] = 'fail'
|
62
|
-
status[:error] = "Service files: #{services_with_unacceptable_keys} have keys other than 'default', 'environments', 'encrypted', 'configname', 'stringdata' 'configlabels' or '
|
63
|
-
end
|
64
|
-
status
|
65
|
-
end
|
66
|
-
|
67
|
-
def service_defaults_have_no_hashes_as_values
|
68
|
-
status = {status: 'pass', error: ''}
|
69
|
-
services_with_hashes_in_defaults = []
|
70
|
-
@services.each do |path, loaded|
|
71
|
-
unless loaded['default'] == nil
|
72
|
-
loaded['default'].each do |defaultkey, defaultvalue|
|
73
|
-
if defaultvalue.class == Hash
|
74
|
-
services_with_hashes_in_defaults << {path => defaultkey}
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
if services_with_hashes_in_defaults != []
|
80
|
-
status[:status] = 'fail'
|
81
|
-
status[:error] = "Service files: #{services_with_hashes_in_defaults} have default properties with values as hashes."
|
60
|
+
status[:error] = "Service files: #{services_with_unacceptable_keys} have keys other than 'default', 'environments', 'encrypted', 'configname', 'stringdata', 'configlabels', 'secretlabels' or 'label'"
|
82
61
|
end
|
83
62
|
status
|
84
63
|
end
|
@@ -107,29 +86,6 @@ module PropertyGenerator
|
|
107
86
|
status
|
108
87
|
end
|
109
88
|
|
110
|
-
def service_environments_have_no_hashes_as_values
|
111
|
-
status = {status: 'pass', error: ''}
|
112
|
-
services_with_hashes_in_environments = []
|
113
|
-
@services.each do |path, loaded|
|
114
|
-
unless loaded['environments'] == nil
|
115
|
-
loaded['environments'].each do |environments, properties|
|
116
|
-
unless properties == nil
|
117
|
-
properties.each do |key, value|
|
118
|
-
if value.class == Hash
|
119
|
-
services_with_hashes_in_environments << {path => {environments => key}}
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
if services_with_hashes_in_environments != []
|
127
|
-
status[:status] = 'fail'
|
128
|
-
status[:error] = "Service files #{services_with_hashes_in_environments} have environment properties with values as hashes."
|
129
|
-
end
|
130
|
-
status
|
131
|
-
end
|
132
|
-
|
133
89
|
def service_encrypted_environments_match_config_environments
|
134
90
|
status = {status: 'pass', error: ''}
|
135
91
|
missmatched_environments = []
|
@@ -156,7 +112,7 @@ module PropertyGenerator
|
|
156
112
|
|
157
113
|
def service_encrypted_fields_are_correct
|
158
114
|
status = {status: 'pass', error: ''}
|
159
|
-
accepted_keys = ['region', 'encrypted', 'service']
|
115
|
+
accepted_keys = ['region', 'encrypted', 'service', 'label']
|
160
116
|
services_with_unacceptable_keys = []
|
161
117
|
@services.each do |path, loaded|
|
162
118
|
if loaded['encrypted'] != nil
|
@@ -181,7 +137,7 @@ module PropertyGenerator
|
|
181
137
|
end
|
182
138
|
if services_with_unacceptable_keys != []
|
183
139
|
status[:status] = 'fail'
|
184
|
-
status[:error] = "Service files: #{services_with_unacceptable_keys} have encrypted properties with bad indentation or keys other than 'region'
|
140
|
+
status[:error] = "Service files: #{services_with_unacceptable_keys} have encrypted properties with bad indentation or keys other than 'region', 'encrypted' or 'label'."
|
185
141
|
end
|
186
142
|
status
|
187
143
|
end
|
data/spec/lib/global_spec.rb
CHANGED
@@ -8,7 +8,7 @@ module PropertyGenerator
|
|
8
8
|
subject(:global) {described_class.new(File.expand_path("./spec/resources"), config)}
|
9
9
|
|
10
10
|
it 'should read the main global file' do
|
11
|
-
expect(global.get_main_global).to eq({'foo'=>'bar'})
|
11
|
+
expect(global.get_main_global).to eq({'foo'=>'bar', 'map' => {'key1' => 'val1', 'key2' => 'val2', 'key4' => '{domain}'}})
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should read the account globals' do
|
@@ -16,13 +16,35 @@ module PropertyGenerator
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should read the environment globals' do
|
19
|
-
expect(global.get_environment_globals).to eq({123456789012=>{'my-test-env1'=>{'my_env'=>'my-test-env1'}}})
|
19
|
+
expect(global.get_environment_globals).to eq({123456789012=>{'my-test-env1'=>{'my_env'=>'my-test-env1', 'test_encrypted' => { '$ssm' => { 'region' => 'region', 'encrypted' => 'encrypted_value' }}}}})
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should condense the globals accurately' do
|
23
|
-
expect(global.condense_globals).to eq({'my-test-env1'=>{
|
24
|
-
|
23
|
+
expect(global.condense_globals).to eq({'my-test-env1'=>{
|
24
|
+
'foo' => 'bar',
|
25
|
+
'map' => {
|
26
|
+
'key1' => 'val1',
|
27
|
+
'key2' => 'val2',
|
28
|
+
'key4' => '{domain}'
|
29
|
+
},
|
30
|
+
'my_account'=>123456789012,
|
31
|
+
'my_env'=>'my-test-env1',
|
32
|
+
'test_encrypted' => {
|
33
|
+
'$ssm' => {
|
34
|
+
'region' => 'region',
|
35
|
+
'encrypted' => 'encrypted_value'
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
'my-test-env2' => {
|
40
|
+
'foo' => 'bar',
|
41
|
+
'map' => {
|
42
|
+
'key1' => 'val1',
|
43
|
+
'key2' => 'val2',
|
44
|
+
'key4' => '{domain}'
|
45
|
+
}
|
46
|
+
}})
|
25
47
|
end
|
26
48
|
|
27
49
|
end
|
28
|
-
end
|
50
|
+
end
|
data/spec/lib/service_spec.rb
CHANGED
@@ -1,35 +1,87 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "../../lib/generator/service"
|
3
|
+
require_relative "../../lib/generator/globals"
|
4
|
+
require_relative "../../lib/generator/config"
|
5
|
+
require "pp"
|
6
6
|
module PropertyGenerator
|
7
7
|
describe Service do
|
8
|
-
subject(:config) {PropertyGenerator::Config.new(File.expand_path("./spec/resources"))}
|
9
|
-
subject(:globals) {PropertyGenerator::Globals.new(File.expand_path("./spec/resources"), config)}
|
10
|
-
subject(:service) {described_class.new(YAML.load_file(
|
8
|
+
subject(:config) { PropertyGenerator::Config.new(File.expand_path("./spec/resources")) }
|
9
|
+
subject(:globals) { PropertyGenerator::Globals.new(File.expand_path("./spec/resources"), config) }
|
10
|
+
subject(:service) { described_class.new(YAML.load_file("./spec/resources/services/my-microservice-1.yml"), config, globals.globals) }
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(service.service).to eq({
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
it "Parses and condenses a service\"s defaults and environment definitions" do
|
13
|
+
expect(service.service).to eq({
|
14
|
+
"my-test-env1" => {
|
15
|
+
"foo" => "bar",
|
16
|
+
"map" => {
|
17
|
+
"key1" => "notval1",
|
18
|
+
"key2" => "val2",
|
19
|
+
"key3" => "{cloud}-{region}",
|
20
|
+
"key4" => "{domain}",
|
21
|
+
"arr" => %w[one two {domain}]
|
22
|
+
},
|
23
|
+
"my_account" => 123456789012,
|
24
|
+
"my_env" => "my-test-env1",
|
25
|
+
"test_encrypted" => {
|
26
|
+
"$ssm" => {
|
27
|
+
"region" => "region",
|
28
|
+
"encrypted" => "encrypted_value"
|
29
|
+
}
|
30
|
+
},
|
31
|
+
"database.host" => "my.database.{domain}",
|
32
|
+
"database.port" => 3306,
|
33
|
+
"thread.pool.size" => 12
|
34
|
+
},
|
35
|
+
"my-test-env2" => {
|
36
|
+
"foo" => "bar",
|
37
|
+
"map" => {
|
38
|
+
"key1" => "notval1",
|
39
|
+
"key2" => "val2",
|
40
|
+
"key3" => "{cloud}-{region}",
|
41
|
+
"key4" => "{domain}",
|
42
|
+
"arr" => %w[one two {domain}]
|
43
|
+
},
|
44
|
+
"database.host" => "my.database.{domain}",
|
45
|
+
"database.port" => 3306,
|
46
|
+
"thread.pool.size" => 8,
|
47
|
+
"new_arr" => %w[{region} {cloud} {domain}]
|
48
|
+
}
|
49
|
+
})
|
21
50
|
end
|
22
51
|
|
23
|
-
it
|
24
|
-
expect(service.interpolate).to eq({
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
52
|
+
it "Tests interpolations work for a service" do
|
53
|
+
expect(service.interpolate).to eq({
|
54
|
+
"my-test-env1" => {
|
55
|
+
"foo" => "bar",
|
56
|
+
"map" => {
|
57
|
+
"key1" => "notval1",
|
58
|
+
"key2" => "val2",
|
59
|
+
"key3" => "test-cloud-1-us-east-1",
|
60
|
+
"key4" => "my1.com",
|
61
|
+
"arr" => %w[one two my1.com]
|
62
|
+
},
|
63
|
+
"my_account" => 123456789012,
|
64
|
+
"my_env" => "my-test-env1",
|
65
|
+
"test_encrypted" => { "$ssm" => { "region" => "region", "encrypted" => "encrypted_value" } },
|
66
|
+
"database.host" => "my.database.my1.com",
|
67
|
+
"database.port" => 3306,
|
68
|
+
"thread.pool.size" => 12
|
69
|
+
},
|
70
|
+
"my-test-env2" => {
|
71
|
+
"foo" => "bar",
|
72
|
+
"map" => {
|
73
|
+
"key1" => "notval1",
|
74
|
+
"key2" => "val2",
|
75
|
+
"key3" => "test-cloud-2-eu-central-1",
|
76
|
+
"key4" => "my2.com",
|
77
|
+
"arr" => %w[one two my2.com]
|
78
|
+
},
|
79
|
+
"database.host" => "my.database.my2.com",
|
80
|
+
"database.port" => 3306,
|
81
|
+
"thread.pool.size" => 8,
|
82
|
+
"new_arr" => %w[eu-central-1 test-cloud-2 my2.com]
|
83
|
+
} })
|
32
84
|
end
|
33
85
|
|
34
86
|
end
|
35
|
-
end
|
87
|
+
end
|
@@ -1,16 +1,27 @@
|
|
1
1
|
default:
|
2
2
|
database.host: 'my.database.{domain}'
|
3
3
|
database.port: 3306
|
4
|
+
map:
|
5
|
+
key1: notval1
|
6
|
+
key3: '{cloud}-{region}'
|
7
|
+
arr:
|
8
|
+
- one
|
9
|
+
- two
|
10
|
+
- '{domain}'
|
4
11
|
|
5
12
|
environments:
|
6
|
-
my-test-
|
13
|
+
my-test-env1:
|
7
14
|
thread.pool.size: 12
|
8
|
-
my-test-
|
15
|
+
my-test-env2:
|
9
16
|
thread.pool.size: 8
|
17
|
+
new_arr:
|
18
|
+
- '{region}'
|
19
|
+
- '{cloud}'
|
20
|
+
- '{domain}'
|
10
21
|
|
11
22
|
#encrypted:
|
12
|
-
# my-test-
|
23
|
+
# my-test-env1:
|
13
24
|
# my.encrypted.property:
|
14
25
|
# $ssm:
|
15
26
|
# region: us-east-1
|
16
|
-
# encrypted: PRETEND_ENCRYPTED_PROPERTY_CIPHERTEXT
|
27
|
+
# encrypted: PRETEND_ENCRYPTED_PROPERTY_CIPHERTEXT
|