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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 202188fe59edafc4ddb51f8b4d285dc8a38ede94
4
- data.tar.gz: 387b7905cfdb7472d09a426fda83f633c41794d7
3
+ metadata.gz: a0cc064b6d0d8fafe9847384a929bd11f5bb9a54
4
+ data.tar.gz: 62a7bc3e50dfd64f1573098a37c762470d7ac481
5
5
  SHA512:
6
- metadata.gz: cd5b14643b19438c1be8cc65b90c5d4bda7bcf5bd710d1a228396982b41c809a2d0c844930c175dae3026f6eb8c4da20b79477045181d3bbe515f8c15f8c1043
7
- data.tar.gz: 3002871e1b5f17a67e5a5b38f84781e4147d1dacbbb5bc6f30c02cc8ec5af4c3d8397243a0fe8ac42d31a4a8a9e6d9d5f33e4055436d3478e47d7117a77508f6
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.
@@ -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].merge(hash) unless hash.empty?
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.merge(condensed[env])
83
+ condensed[env] = main_global_dup.deep_merge(condensed[env])
79
84
  end
80
85
  end
81
86
  condensed
@@ -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
- interpolate_nested_properties(@service[env], interpolations)
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 { |v| interpolate_nested_properties(v, interpolations) if v.class == Hash }
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 enviornments merged with the defaults
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.merge(environment_data)
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].merge(service_data[env])
110
+ merged = globals_clone[env].deep_merge(service_data[env])
104
111
  end
105
112
  output[env] = merged
106
113
  end
@@ -14,7 +14,6 @@ module PropertyGenerator
14
14
 
15
15
  def run_globals_tests
16
16
  tests = ['globals_load_as_hashes',
17
- 'globals_have_no_hashes_as_values',
18
17
  'globals_are_defined_for_valid_environemnts',
19
18
  ]
20
19
  results = PropertyGenerator.test_runner(self, tests)
@@ -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 'secretlabels'"
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' and 'encrypted'."
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
@@ -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'=>{'foo' => 'bar', 'my_account'=>123456789012, 'my_env'=>'my-test-env1'},
24
- 'my-test-env2' => {'foo' => 'bar'}})
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
@@ -1,35 +1,87 @@
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'
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('./spec/resources/services/my-microservice-1.yml'), config, globals.globals)}
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 'Parses and condenses a service\'s defaults and environment definitions' do
13
- expect(service.service).to eq({"my-test-env1"=> {"foo"=>"bar",
14
- "my_account"=>123456789012,
15
- "my_env"=>"my-test-env1",
16
- "database.host"=>"my.database.{domain}",
17
- "database.port"=>3306},
18
- "my-test-env2"=> {"foo"=>"bar",
19
- "database.host"=>"my.database.{domain}",
20
- "database.port"=>3306}})
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 'Tests interpolations work for a service' do
24
- expect(service.interpolate).to eq({"my-test-env1"=> {"foo"=>"bar",
25
- "my_account"=>123456789012,
26
- "my_env"=>"my-test-env1",
27
- "database.host"=>"my.database.my1.com",
28
- "database.port"=>3306},
29
- "my-test-env2"=> {"foo"=>"bar",
30
- "database.host"=>"my.database.my2.com",
31
- "database.port"=>3306}})
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 +1,6 @@
1
- my_env: 'my-test-env1'
1
+ my_env: 'my-test-env1'
2
+ encrypted:
3
+ test_encrypted:
4
+ $ssm:
5
+ region: region
6
+ encrypted: encrypted_value
@@ -1 +1,5 @@
1
- foo: "bar"
1
+ foo: "bar"
2
+ map:
3
+ key1: val1
4
+ key2: val2
5
+ key4: '{domain}'
@@ -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-env-1:
13
+ my-test-env1:
7
14
  thread.pool.size: 12
8
- my-test-env-2:
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-env-1:
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cps-property-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Call