cps-property-generator 0.2.16 → 0.3.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
  SHA1:
3
- metadata.gz: 84b92342668cccfdeb1e097c19fdd1641fef1589
4
- data.tar.gz: d4c5c0bf42cbbec4a3a2203a4fbdd990f88a9a97
3
+ metadata.gz: ee35c7e51b0de1094566e73a39784a663442903c
4
+ data.tar.gz: 16ade81e5e6922856112a7516dd768e029935374
5
5
  SHA512:
6
- metadata.gz: 4883e4c5fef3a9ea680b6401c9b3629371f16b967ab634a9fb2c041ee60940cab2e16c5469a2191a7964ee947fc80a6b190862aa3b0193caeb22c87be29849ba
7
- data.tar.gz: 9381609f8a882ade931cb10c438b0fb6b9ad3619e4620d80929b8d52693bb2fdd6d245e65e68ebe805a5108ba444225976c565d82152d18c3eca9c5b5193b0de
6
+ metadata.gz: 81d1e90f92865481d6c6ce7242c0bba8c1802ab92ef8c04b961310ef4aa730b50358a68addc1912530ebc045aa3edd77525dfeffcda9bb6be83096a12f334a4c
7
+ data.tar.gz: 4363ca29e85b30e93ab04615fabc809cc285592f9e3f49e9b640ec36ce5bd81e59be05f533c1556d49ae9b4fd8c9c365f0d9b950963743901a7740c0f4d3a521
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
2
  require 'thor'
4
3
  require 'yaml'
5
- require_relative '../lib/generator/generator.rb'
6
- require_relative '../lib/linter/linter.rb'
7
- class GeneratorCLI < ::Thor
4
+ require_relative '../lib/generator/generator'
5
+ require_relative '../lib/linter/linter'
8
6
 
7
+ class GeneratorCLI < ::Thor
9
8
  desc 'generate', 'Generate properties'
10
9
  option 'project_path', banner: 'PROJECT_PATH', type: :string, desc: 'Path to the property project to generate properties for'
11
10
  option 'output', banner: 'OUTPUT', type: :string, desc: 'Output path for locally dumping generated outputs', :default => '/tmp/'
@@ -13,17 +12,18 @@ class GeneratorCLI < ::Thor
13
12
  option 'upload_account', banner: 'UPLOAD_ACCOUNT', type: :string, desc: 'The account you are uploading properties to'
14
13
  option 'upload_region', banner: 'UPLOAD_REGION', type: :string, desc: 'The region your property bucket is in'
15
14
  option 'upload_bucket', banner: 'UPLOAD_BUCKET', type: :string, desc: 'The bucket you are uploading properties to.'
15
+ option 'upload_all', banner: 'UPLOAD_ALL', type: :boolean, desc: 'Whether to upload all envs and accounts to a single bucket', :default => false
16
16
 
17
17
  def generate
18
-
19
18
  generator = PropertyGenerator::Generator.new(options)
20
19
  out = generator.generate
21
20
  if options['upload']
22
- if options['upload_account'].nil? || options['upload_region'].nil? && options['upload_bucket'].nil?
23
- puts 'Please specify upload configs'
24
- else
25
- generator.upload(out, options)
26
- end
21
+ abort('Did not specify an upload bucket') if options['upload_bucket'].nil?
22
+ abort('Did not specify an upload region') if options['upload_region'].nil?
23
+
24
+ abort('Did not specify upload configs') if !options['upload_all'] && options['upload_account'].nil?
25
+
26
+ generator.upload(out, options)
27
27
  end
28
28
  end
29
29
 
@@ -1,7 +1,6 @@
1
1
  module PropertyGenerator
2
2
  require 'yaml'
3
3
  class Config
4
-
5
4
  attr_accessor :configs
6
5
 
7
6
  def initialize(project_path)
@@ -29,4 +28,4 @@ module PropertyGenerator
29
28
  YAML.load_file(file)
30
29
  end
31
30
  end
32
- end
31
+ end
@@ -11,20 +11,20 @@ module PropertyGenerator
11
11
  # purpose: initialize globals and configs
12
12
  # serve as a broker between tasks
13
13
  def initialize(options)
14
- project_path = File.expand_path(options['project_path'])
14
+ project_path = File.expand_path(options['project_path'])
15
15
  @configs = PropertyGenerator::Config.new(project_path)
16
16
  @globals = PropertyGenerator::Globals.new(project_path, @configs)
17
17
  @globals = @globals.globals
18
18
  @accounts = @configs.accounts
19
19
 
20
- @output_path = "#{File.expand_path(options['output'])}/properties/#{SecureRandom.hex}"
20
+ @output_path = "#{File.expand_path(options['output'])}/properties/#{SecureRandom.hex}"
21
21
  puts "Properties will be output here #{@output_path}"
22
22
  @service_list = PropertyGenerator.read_services(project_path)
23
23
  end
24
24
 
25
25
  def generate
26
26
  output = []
27
- @service_list.each do | service, path|
27
+ @service_list.each do |service, path|
28
28
  PropertyGenerator.config_enforcer(@configs.environment_configs)
29
29
  service_instance = PropertyGenerator::Service.new(YAML.load_file(path), @configs, @globals)
30
30
  service_instance.service
@@ -37,27 +37,38 @@ module PropertyGenerator
37
37
  end
38
38
 
39
39
  def upload(out, config)
40
- account = config['upload_account']
40
+ upload_bucket = config['upload_bucket']
41
+ upload_region = config['upload_region']
41
42
 
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
43
+ if config['upload_all']
44
+ _upload_files(out.sort) do |file|
45
+ file_region = file.split('/')[-2]
46
+ file_account = file.split('/')[-3]
45
47
 
46
- upload_account = config['upload_account']
47
- upload_region = config['upload_region']
48
- upload_bucket = config['upload_bucket']
48
+ PropertyGenerator.sync(upload_region, file_account, upload_bucket, file, file_region)
49
+ end
50
+ else
51
+ upload_account = config['upload_account'].strip
52
+ unless @accounts.map { |a| a.to_s.strip }.include?(upload_account)
53
+ abort("The specified account (#{upload_account}) is not configured, please add it to config/config.yml")
54
+ end
49
55
 
50
- upload_out = out.select { |file| file.include?("#{upload_account}") && file.include?("#{upload_region}") }
51
- upload_out.each_slice(20) do |file_slice|
56
+ upload_out = out.select { |file| file.include?(upload_account) && file.include?(upload_region) }
57
+ _upload_files(upload_out) do |file|
58
+ file_region = file.split('/')[-2]
59
+ PropertyGenerator.sync(upload_region, upload_account, upload_bucket, file, file_region)
60
+ end
61
+ end
62
+ end
63
+
64
+ def _upload_files(files)
65
+ files.each_slice(20) do |file_slice|
52
66
  file_slice.map do |file|
53
67
  Thread.new do
54
- file_region = file.split("/")[-2]
55
- PropertyGenerator.sync(upload_region, upload_account, upload_bucket, file, file_region)
68
+ yield file
56
69
  end
57
70
  end.each(&:join)
58
71
  end
59
72
  end
60
-
61
73
  end
62
74
  end
63
-
@@ -14,10 +14,9 @@ module PropertyGenerator
14
14
  @globals ||= condense_globals
15
15
  end
16
16
 
17
-
18
17
  def get_main_global
19
18
  top_level = {}
20
- if File.exists?("#{@project_path}/globals/globals.yml")
19
+ if File.exist?("#{@project_path}/globals/globals.yml")
21
20
  top_level = YAML.load_file("#{@project_path}/globals/globals.yml")
22
21
  end
23
22
  top_level
@@ -26,9 +25,10 @@ module PropertyGenerator
26
25
  def get_account_globals
27
26
  data = {}
28
27
  @accounts.each do |account|
29
- next unless Dir.exists?("#{@project_path}/globals/accounts/#{account}")
28
+ next unless Dir.exist?("#{@project_path}/globals/accounts/#{account}")
29
+
30
30
  account_default_file = "#{@project_path}/globals/accounts/#{account}/#{account}.yml"
31
- data[account] = YAML.load_file(account_default_file) if File.exists?(account_default_file)
31
+ data[account] = YAML.load_file(account_default_file) if File.exist?(account_default_file)
32
32
  end
33
33
  data
34
34
  end
@@ -36,23 +36,24 @@ module PropertyGenerator
36
36
  def get_environment_globals
37
37
  data = {}
38
38
  @accounts.each do |account|
39
- next unless Dir.exists?("#{@project_path}/globals/accounts/#{account}/environments")
39
+ next unless Dir.exist?("#{@project_path}/globals/accounts/#{account}/environments")
40
+
40
41
  data[account] = {}
41
42
  @environments.each do |env|
42
- next unless File.exists?("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml")
43
+ next unless File.exist?("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml")
44
+
43
45
  data[account][env] = YAML.load_file("#{@project_path}/globals/accounts/#{account}/environments/#{env}.yml")
44
46
  unless data[account][env]['encrypted'].nil?
45
47
  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
+ not_encrypted = data[account][env].reject { |k, _| k == 'encrypted' }
49
+ data[account][env] = not_encrypted.deep_merge(encrypted)
48
50
  end
49
51
  end
50
52
  end
51
53
  data
52
54
  end
53
55
 
54
-
55
- #merge environment globals with account globals.
56
+ # merge environment globals with account globals.
56
57
  def condense_globals
57
58
  condensed = {}
58
59
  # get account and the environmental hash's for said account
@@ -62,12 +63,12 @@ module PropertyGenerator
62
63
  # nothing to do here if everything is empty
63
64
  return condensed if environment_globals.empty? && account_globals.empty? && main_global.empty?
64
65
 
65
- environment_globals.each do |account, env_global |
66
+ environment_globals.each do |account, env_global|
66
67
  # get the env and the values
67
68
  env_global.each do |env, hash|
68
69
  account_globals[account] ||= {}
69
70
  # set the environment globals to be the account global merged with the env globals
70
- env_global[env] = account_globals[account].merge(hash) unless hash.empty?
71
+ env_global[env] = account_globals[account].deep_merge(hash) unless hash.empty?
71
72
  condensed[env] = env_global[env]
72
73
  end
73
74
  end
@@ -80,11 +81,10 @@ module PropertyGenerator
80
81
  # We need to merge into the globals so any env configs overwrite main global configs.
81
82
  # Dup so we dont modify the original object
82
83
  main_global_dup = main_global.dup
83
- condensed[env] = main_global_dup.merge(condensed[env])
84
+ condensed[env] = main_global_dup.deep_merge(condensed[env])
84
85
  end
85
86
  end
86
87
  condensed
87
88
  end
88
-
89
89
  end
90
90
  end
@@ -1,9 +1,9 @@
1
1
  module PropertyGenerator
2
-
3
2
  class Service
4
3
  require 'active_support/core_ext/hash'
5
4
 
6
5
  attr_accessor :service
6
+ attr_reader :additional_options
7
7
 
8
8
  def initialize(service_data, config, globals)
9
9
  @service_data = service_data
@@ -28,42 +28,41 @@ module PropertyGenerator
28
28
  @additional_options['secretlabels'] = @service_data['secretlabels'].nil? ? nil : @service_data['secretlabels']
29
29
  end
30
30
 
31
- def additional_options
32
- @additional_options
33
- end
34
-
35
- def service
36
- @service
37
- end
38
-
39
31
  def configmap_name
40
32
  @configmapname
41
33
  end
42
34
 
43
35
  def interpolate
44
36
  environments = @environments
45
- #read in config
46
- #interate through environment and substitute config for values for that environment
47
- environments.each do | env|
48
- #get the map of config for a env
37
+ # read in config
38
+ # interate through environment and substitute config for values for that environment
39
+ environments.each do |env|
40
+ # get the map of config for a env
49
41
  interpolations = @environment_configs[env]['interpolations']
50
42
 
51
43
  # Recursively interate through the properties for an environment and gsub the config
52
44
  # with defined interpolations.
53
- interpolate_nested_properties(@service[env], interpolations)
45
+ service_env = Marshal.load(Marshal.dump(@service[env]))
46
+ interpolate_nested_properties(service_env, interpolations)
47
+ @service[env] = service_env
54
48
  end
55
49
  service
56
50
  end
57
51
 
58
52
  def interpolate_nested_properties(service_env, interpolations)
59
53
  interpolations.each do |matcher_key, matcher_value|
60
- 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 }
54
+ service_env.each { |k, v| service_env[k] = v.gsub("{#{matcher_key}}", matcher_value) if v.class == String && v.include?("{#{matcher_key}}") }
55
+ service_env.values.each do |v|
56
+ interpolate_nested_properties(v, interpolations) if v.class == Hash
57
+ v.each_with_index do |val, idx|
58
+ v[idx] = val.gsub("{#{matcher_key}}", matcher_value) if val.class == String && val.include?("{#{matcher_key}}")
59
+ end if v.class == Array
60
+ end
62
61
  end
63
62
  end
64
63
 
65
64
  def merge_env_default(data, environments)
66
- #creates a hash of the enviornments merged with the defaults
65
+ # creates a hash of the environments merged with the defaults
67
66
  # {service => {env1 => {properties},
68
67
  # env2 => {properties}
69
68
  # }
@@ -73,7 +72,7 @@ module PropertyGenerator
73
72
 
74
73
  environments.each do |env|
75
74
  default_clone = default.dup
76
- #if nil, use set to environments as nothing to merge env with
75
+ # if nil, use set to environments as nothing to merge env with
77
76
  data['environments'] ||= {}
78
77
  data['environments'][env] ||= {}
79
78
  environment_data = data['environments'][env].dup
@@ -84,7 +83,7 @@ module PropertyGenerator
84
83
  if default_clone.nil?
85
84
  merged = environment_data
86
85
  else
87
- merged = default_clone.merge(environment_data)
86
+ merged = default_clone.deep_merge(environment_data)
88
87
  end
89
88
  output[env] = merged
90
89
  end
@@ -92,7 +91,7 @@ module PropertyGenerator
92
91
  end
93
92
 
94
93
  def merge_service_with_globals(globals_data, service_data, environments)
95
- #service will now overwrite globals, merging will be done for each environment
94
+ # service will now overwrite globals, merging will be done for each environment
96
95
  output = {}
97
96
  envs = environments
98
97
  envs.each do |env|
@@ -100,13 +99,11 @@ module PropertyGenerator
100
99
  if globals_clone[env].nil? || globals_clone[env] == false
101
100
  merged = service_data[env]
102
101
  else
103
- merged = globals_clone[env].merge(service_data[env])
102
+ merged = globals_clone[env].deep_merge(service_data[env])
104
103
  end
105
104
  output[env] = merged
106
105
  end
107
106
  output
108
107
  end
109
-
110
108
  end
111
-
112
109
  end
@@ -1,10 +1,10 @@
1
1
  require_relative '../helpers/helpers'
2
+
2
3
  module PropertyGenerator
3
4
  require 'json'
4
5
  require 'fileutils'
5
6
  require 'aws-sdk-s3'
6
7
  class << self
7
-
8
8
  def test_runner(object, test_list)
9
9
  results = {}
10
10
  test_list.each do |test|
@@ -14,9 +14,9 @@ module PropertyGenerator
14
14
  end
15
15
 
16
16
  def get_list_of_files(path, ignore_list)
17
- #Returns a list of files in given path
18
- #Ignores files in a given ignore list
19
- Dir.glob(path + "/**/*").select{ |e| File.file? e unless ignore_list.include?(e.split('/')[(e.split('/')).length - 1])}
17
+ # Returns a list of files in given path
18
+ # Ignores files in a given ignore list
19
+ Dir.glob("#{path}/**/*").select { |e| File.file?(e) unless ignore_list.include?(e.split('/')[-1]) }
20
20
  end
21
21
 
22
22
  def valid_paths(path)
@@ -26,7 +26,7 @@ module PropertyGenerator
26
26
  begin
27
27
  YAML.load_file(file_path)
28
28
  valid_paths << file_path
29
- rescue
29
+ rescue StandardError
30
30
  next
31
31
  end
32
32
  end
@@ -39,7 +39,7 @@ module PropertyGenerator
39
39
  list_of_file_paths.each do |file_path|
40
40
  begin
41
41
  YAML.load_file(file_path)
42
- rescue
42
+ rescue StandardError
43
43
  invalid_paths << file_path
44
44
  end
45
45
  end
@@ -57,21 +57,21 @@ module PropertyGenerator
57
57
  def writer(service_name, finalized, configs, output_path, additional_options)
58
58
  output = []
59
59
  envs = configs.environments
60
- environmental_configs = configs.environment_configs
61
- envs.each do | env|
62
- account = environmental_configs[env]["account"]
63
- region = environmental_configs[env]["region"]
64
- hash = { "properties" => finalized[env] }
60
+ environmental_configs = configs.environment_configs
61
+ envs.each do |env|
62
+ account = environmental_configs[env]['account']
63
+ region = environmental_configs[env]['region']
64
+ hash = { 'properties' => finalized[env] }
65
65
  ['configname', 'stringdata', 'configlabels', 'secretlabels'].each do |setting|
66
- hash[setting] = additional_options[setting] if [setting] unless additional_options[setting].nil?
66
+ hash[setting] = additional_options[setting] unless additional_options[setting].nil?
67
67
  end
68
68
  json = JSON.pretty_generate(hash)
69
- #IF users are specifing a vpc then we will drop property files under the dir that corresponds to the vpc
70
- if environmental_configs[env].key?("vpc") && !environmental_configs[env]["vpc"].nil?
71
- vpc_dir = "#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}"
69
+ # IF users are specifing a vpc then we will drop property files under the dir that corresponds to the vpc
70
+ if environmental_configs[env].key?('vpc') && !environmental_configs[env]['vpc'].nil?
71
+ vpc_dir = "#{output_path}/#{account}/#{region}/#{environmental_configs[env]['vpc']}"
72
72
  FileUtils.mkdir_p("#{vpc_dir}/") unless Dir.exist?(vpc_dir)
73
- File.write("#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}/#{service_name}.json", json)
74
- output << "#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}/#{service_name}.json"
73
+ File.write("#{output_path}/#{account}/#{region}/#{environmental_configs[env]['vpc']}/#{service_name}.json", json)
74
+ output << "#{output_path}/#{account}/#{region}/#{environmental_configs[env]['vpc']}/#{service_name}.json"
75
75
  else
76
76
  FileUtils.mkdir_p("#{output_path}/#{account}/#{region}/") unless Dir.exist?("#{output_path}/#{account}/#{region}/")
77
77
  File.write("#{output_path}/#{account}/#{region}/#{service_name}.json", json)
@@ -83,22 +83,22 @@ module PropertyGenerator
83
83
 
84
84
  def sync(region, account, bucket, file, file_region)
85
85
  s3 = Aws::S3::Resource.new(region: region)
86
- filename = file.split("/").last
86
+ filename = file.split('/').last
87
87
  puts "Destination: #{account}/#{file_region}/#{filename}"
88
88
  puts "Uploading: #{file}"
89
89
  obj = s3.bucket(bucket).object("#{account}/#{file_region}/#{filename}")
90
90
  obj.upload_file(file)
91
91
  end
92
92
 
93
- #Force users to specify VPCs for all environments if specified for one environment.
94
- #This allows us to skip having conditional logic downstream in CPS requests
93
+ # Force users to specify VPCs for all environments if specified for one environment.
94
+ # This allows us to skip having conditional logic downstream in CPS requests
95
95
  def config_enforcer(environment_configs)
96
96
  a_vpc_exists = false
97
97
  environment_configs.each do |environment, config|
98
- if config.key?("vpc")
98
+ if config.key?('vpc')
99
99
  a_vpc_exists = true
100
100
  elsif a_vpc_exists
101
- raise("If you are using VPCs then a VPC must be specified for all environments in the environment_configs")
101
+ raise('If you are using VPCs then a VPC must be specified for all environments in the environment_configs')
102
102
  end
103
103
  end
104
104
  end
@@ -1,50 +1,53 @@
1
1
  module PropertyGenerator
2
2
  require 'yaml'
3
3
  class ConfigLinter
4
+ TESTS = [
5
+ 'config_has_correct_keys',
6
+ 'environment_configs_match_environments_list',
7
+ 'environment_configs_have_valid_region_and_account_values',
8
+ 'environment_configs_have_well_formatted_interpolations',
9
+ 'config_file_is_present'
10
+ ].freeze
4
11
 
5
12
  attr_accessor :configs
6
13
 
7
- def initialize(path)
14
+ def initialize(path, ignored_tests)
8
15
  @configs = check_for_config(path)
16
+ @ignored_tests = ignored_tests
9
17
  end
10
18
 
11
19
  def run_config_tests
12
20
  if @configs == {}
13
21
  tests = ['config_file_is_present']
14
22
  else
15
- tests = ['config_has_correct_keys',
16
- 'environment_configs_match_environments_list',
17
- 'environment_configs_have_valid_region_and_account_values',
18
- 'environment_configs_have_well_formatted_interpolations',
19
- 'config_file_is_present']
23
+ tests = TESTS
20
24
  end
21
- results = PropertyGenerator.test_runner(self, tests)
22
- results
25
+ tests -= @ignored_tests
26
+
27
+ PropertyGenerator.test_runner(self, tests)
23
28
  end
24
29
 
25
30
  def check_for_config(path)
26
- #Tries to load the config file - if is unable to load config.yml it returns an empty hash
27
- #Empty hash is returned so that the rest of the files are still able to be linted instead of stopping at this point.
28
- begin
29
- YAML.load_file(path)
30
- rescue
31
- {}
32
- end
31
+ # Tries to load the config file - if is unable to load config.yml it returns an empty hash
32
+ # Empty hash is returned so that the rest of the files are still able to be linted instead of stopping at this point.
33
+
34
+ YAML.load_file(path)
35
+ rescue StandardError
36
+ {}
33
37
  end
34
38
 
35
39
  def config_file_is_present
36
- status = {status: 'pass', error: ''}
40
+ status = { status: 'pass', error: '' }
37
41
  if @configs == {}
38
42
  status[:status] = 'fail'
39
- status[:error] = "Config.yml file is missing, it is required."
43
+ status[:error] = 'Config.yml file is missing, it is required.'
40
44
  end
41
45
  status
42
46
  end
43
47
 
44
48
  def config_has_correct_keys
45
- status = {status: 'pass', error: ''}
46
- config_keys = ['environments', 'accounts',
47
- 'environment_configs']
49
+ status = { status: 'pass', error: '' }
50
+ config_keys = ['environments', 'accounts', 'environment_configs']
48
51
  if @configs.keys != config_keys
49
52
  status[:status] = 'fail'
50
53
  status[:error] = "Config keys should be 'environments', 'accounts', and 'environment_configs'."
@@ -53,40 +56,37 @@ module PropertyGenerator
53
56
  end
54
57
 
55
58
  def environment_configs_match_environments_list
56
- status = {status: 'pass', error: ''}
59
+ status = { status: 'pass', error: '' }
57
60
  if @configs['environments'] != @configs['environment_configs'].keys
58
61
  status[:status] = 'fail'
59
- status[:error] = "Environments in environment_configs do not match environments listed in config environments."
62
+ status[:error] = 'Environments in environment_configs do not match environments listed in config environments.'
60
63
  end
61
64
  status
62
65
  end
63
66
 
64
67
  def environment_configs_have_valid_region_and_account_values
65
- status = {status: 'pass', error: ''}
66
- environments_missmatch_values = []
67
- any_missmatches = false
68
- @configs['environment_configs'].keys.each do |environment|
69
- unless (@configs['environment_configs'][environment].key?('region')) && @configs['accounts'].include?(@configs['environment_configs'][environment]['account'])
70
- environments_missmatch_values << environment
71
- any_missmatches = true
72
- end
73
- if any_missmatches
74
- status[:status] = 'fail'
75
- status[:error] = "Environments: #{environments_missmatch_values} in environment_configs have a region or account value not listed in top level."
76
- end
68
+ status = { status: 'pass', error: '' }
69
+ environments_missmatch_values = @configs['environment_configs'].reject do |_, env_config|
70
+ env_config.key?('region') && @configs['accounts'].include?(env_config['account'])
71
+ end.keys
72
+
73
+ unless environments_missmatch_values.empty?
74
+ status[:status] = 'fail'
75
+ status[:error] = "Environments: #{environments_missmatch_values} in environment_configs have a region or account value not listed in top level."
77
76
  end
77
+
78
78
  status
79
79
  end
80
80
 
81
81
  def environment_configs_have_well_formatted_interpolations
82
- status = {status: 'pass', error: ''}
82
+ status = { status: 'pass', error: '' }
83
83
  environments_with_bad_interpolations = []
84
84
  any_mistakes = false
85
85
  @configs['environment_configs'].keys.each do |environment|
86
86
  if @configs['environment_configs'][environment]['interpolations'].class == Hash
87
87
  @configs['environment_configs'][environment]['interpolations'].each do |interpolation, value|
88
88
  if value.class != String && value.class != Integer && value.class != Float && value.class != Fixnum
89
- environments_with_bad_interpolations << {environment => interpolation}
89
+ environments_with_bad_interpolations << { environment => interpolation }
90
90
  any_mistakes = true
91
91
  end
92
92
  end
@@ -101,6 +101,5 @@ module PropertyGenerator
101
101
  end
102
102
  status
103
103
  end
104
-
105
104
  end
106
105
  end