cps-property-generator 0.2.8 → 0.2.14

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: 33e9da4826b7c811df4e0bdf35383788e850bb26
4
- data.tar.gz: 47dec9e45bb96c348427ecbaab2a9bc045fada2e
3
+ metadata.gz: a92aa70bf1eb0d003090e5cb5d7d42d6e3fd2353
4
+ data.tar.gz: d313236d4357af37d7ceca7e4e1703cc982971ee
5
5
  SHA512:
6
- metadata.gz: 2a4a98b7de3530d277542c38b1bff58d1b8a1b821eeec9bfe1e5c31222c05d7372fa38882f88f0896dff22da878f76c0427e6dbe21fd346a5b60f667835350fa
7
- data.tar.gz: f135b5a38316ca0db25d998a85867749638ff897d863458b0d0168a9accb4f0b3debd82ff846f04bf29c21dbd74788eabc6fab241c4680cd86bae5253b7c8522
6
+ metadata.gz: 057bd3529819bdcb57760b5692b5f8be89bcd61b00ae0ebbe703030f50c80d534717029dabfea0b0d7eb5f76ae4dc3a325066b39bd0cacba02d6c76914addd4c
7
+ data.tar.gz: beca6f7166b0b8eaa71598433f1b0f81eae384e42ffe31d9a6524f1c3c01ef62e2cbe187d5acadc352085218c629c7848b47df0cfe9eca60332126c7f2adf06d
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.
@@ -24,7 +24,6 @@ class GeneratorCLI < ::Thor
24
24
  else
25
25
  generator.upload(out, options)
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
 
@@ -15,10 +15,11 @@ module PropertyGenerator
15
15
  @configs = PropertyGenerator::Config.new(project_path)
16
16
  @globals = PropertyGenerator::Globals.new(project_path, @configs)
17
17
  @globals = @globals.globals
18
+ @accounts = @configs.accounts
19
+
18
20
  @output_path = "#{File.expand_path(options['output'])}/properties/#{SecureRandom.hex}"
19
21
  puts "Properties will be output here #{@output_path}"
20
22
  @service_list = PropertyGenerator.read_services(project_path)
21
-
22
23
  end
23
24
 
24
25
  def generate
@@ -29,20 +30,31 @@ module PropertyGenerator
29
30
  service_instance.service
30
31
  service_instance.interpolate
31
32
 
32
- out = PropertyGenerator.writer(service, service_instance.service, @configs, @output_path)
33
+ out = PropertyGenerator.writer(service, service_instance.service, @configs, @output_path, service_instance.additional_options)
33
34
  (output << out).flatten!
34
35
  end
35
36
  output
36
37
  end
37
38
 
38
39
  def upload(out, config)
40
+ account = config['upload_account']
41
+
42
+ if !@accounts.include?(account.to_i)
43
+ abort("The specified account (#{account}) is not configured, please add it to config/config.yml")
44
+ end
45
+
39
46
  upload_account = config['upload_account']
40
47
  upload_region = config['upload_region']
41
48
  upload_bucket = config['upload_bucket']
42
- out.each do |file|
43
- next unless file.include?("#{upload_account}") && file.include?("#{upload_region}")
44
- file_region = file.split("/")[-2]
45
- PropertyGenerator.sync(upload_region, upload_account, upload_bucket, file, file_region)
49
+
50
+ upload_out = out.select { |file| file.include?("#{upload_account}") && file.include?("#{upload_region}") }
51
+ upload_out.each_slice(20) do |file_slice|
52
+ file_slice.map do |file|
53
+ Thread.new do
54
+ file_region = file.split("/")[-2]
55
+ PropertyGenerator.sync(upload_region, upload_account, upload_bucket, file, file_region)
56
+ end
57
+ end.each(&:join)
46
58
  end
47
59
  end
48
60
 
@@ -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.merge(encrypted)
48
+ end
44
49
  end
45
50
  end
46
51
  data
@@ -10,6 +10,8 @@ module PropertyGenerator
10
10
  @environments = config.environments
11
11
  @globals = globals
12
12
  @environment_configs = config.environment_configs
13
+ @configmapname = service_data['configname'].nil? ? nil : service_data['configname']
14
+ set_additional_options
13
15
  set_service
14
16
  end
15
17
 
@@ -18,10 +20,26 @@ module PropertyGenerator
18
20
  @service = merge_service_with_globals(@globals, service_data, @environments)
19
21
  end
20
22
 
23
+ def set_additional_options
24
+ @additional_options = {}
25
+ @additional_options['configname'] = @service_data['configname'].nil? ? nil : @service_data['configname']
26
+ @additional_options['stringdata'] = @service_data['stringdata'].nil? ? nil : @service_data['stringdata']
27
+ @additional_options['configlabels'] = @service_data['configlabels'].nil? ? nil : @service_data['configlabels']
28
+ @additional_options['secretlabels'] = @service_data['secretlabels'].nil? ? nil : @service_data['secretlabels']
29
+ end
30
+
31
+ def additional_options
32
+ @additional_options
33
+ end
34
+
21
35
  def service
22
36
  @service
23
37
  end
24
38
 
39
+ def configmap_name
40
+ @configmapname
41
+ end
42
+
25
43
  def interpolate
26
44
  environments = @environments
27
45
  #read in config
@@ -54,14 +54,18 @@ module PropertyGenerator
54
54
  end
55
55
  end
56
56
 
57
- def writer(service_name, finalized, configs, output_path)
57
+ def writer(service_name, finalized, configs, output_path, additional_options)
58
58
  output = []
59
59
  envs = configs.environments
60
60
  environmental_configs = configs.environment_configs
61
61
  envs.each do | env|
62
62
  account = environmental_configs[env]["account"]
63
63
  region = environmental_configs[env]["region"]
64
- json = JSON.pretty_generate({"properties" => finalized[env]})
64
+ hash = { "properties" => finalized[env] }
65
+ ['configname', 'stringdata', 'configlabels', 'secretlabels'].each do |setting|
66
+ hash[setting] = additional_options[setting] if [setting] unless additional_options[setting].nil?
67
+ end
68
+ json = JSON.pretty_generate(hash)
65
69
  #IF users are specifing a vpc then we will drop property files under the dir that corresponds to the vpc
66
70
  if environmental_configs[env].key?("vpc") && !environmental_configs[env]["vpc"].nil?
67
71
  vpc_dir = "#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}"
@@ -48,7 +48,7 @@ module PropertyGenerator
48
48
 
49
49
  def services_have_accepted_keys
50
50
  status = {status: 'pass', error: ''}
51
- accepted_keys = ['default', 'environments', 'encrypted']
51
+ accepted_keys = ['default', 'environments', 'encrypted', 'configname', 'stringdata', 'configlabels', 'secretlabels']
52
52
  services_with_unacceptable_keys = []
53
53
  @services.each do |path, loaded|
54
54
  loaded.keys.each do |service_key|
@@ -59,7 +59,7 @@ module PropertyGenerator
59
59
  end
60
60
  if services_with_unacceptable_keys != []
61
61
  status[:status] = 'fail'
62
- status[:error] = "Service files: #{services_with_unacceptable_keys} have keys other than 'default', 'environments', or 'encrypted'."
62
+ status[:error] = "Service files: #{services_with_unacceptable_keys} have keys other than 'default', 'environments', 'encrypted', 'configname', 'stringdata' 'configlabels' or 'secretlabels'"
63
63
  end
64
64
  status
65
65
  end
@@ -16,11 +16,11 @@ 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'},
23
+ expect(global.condense_globals).to eq({'my-test-env1'=>{'foo' => 'bar', 'my_account'=>123456789012, 'my_env'=>'my-test-env1', 'test_encrypted' => { '$ssm' => { 'region' => 'region', 'encrypted' => 'encrypted_value' }}},
24
24
  'my-test-env2' => {'foo' => 'bar'}})
25
25
  end
26
26
 
@@ -1,18 +1,19 @@
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
8
  subject(:config) {PropertyGenerator::Config.new(File.expand_path("./spec/resources"))}
9
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)}
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
12
+ it "Parses and condenses a service\"s defaults and environment definitions" do
13
13
  expect(service.service).to eq({"my-test-env1"=> {"foo"=>"bar",
14
14
  "my_account"=>123456789012,
15
15
  "my_env"=>"my-test-env1",
16
+ "test_encrypted" => { "$ssm" => { "region" => "region", "encrypted" => "encrypted_value" }},
16
17
  "database.host"=>"my.database.{domain}",
17
18
  "database.port"=>3306},
18
19
  "my-test-env2"=> {"foo"=>"bar",
@@ -20,10 +21,11 @@ module PropertyGenerator
20
21
  "database.port"=>3306}})
21
22
  end
22
23
 
23
- it 'Tests interpolations work for a service' do
24
+ it "Tests interpolations work for a service" do
24
25
  expect(service.interpolate).to eq({"my-test-env1"=> {"foo"=>"bar",
25
26
  "my_account"=>123456789012,
26
27
  "my_env"=>"my-test-env1",
28
+ "test_encrypted" => { "$ssm" => { "region" => "region", "encrypted" => "encrypted_value" }},
27
29
  "database.host"=>"my.database.my1.com",
28
30
  "database.port"=>3306},
29
31
  "my-test-env2"=> {"foo"=>"bar",
@@ -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
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.8
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Call