cps-property-generator 0.1.7 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/generator/generator.rb +1 -0
- data/lib/generator/service.rb +10 -9
- data/lib/helpers/helpers.rb +23 -3
- data/lib/linter/config_linter.rb +3 -3
- data/lib/linter/services_linter.rb +13 -9
- 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: 8c538411f403418186287f058c9e9ceb4d054513
|
4
|
+
data.tar.gz: 76f347bfd52b07b8333ea929345e4b650d8221b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd7d8f5a4cad809bf09d655f026c6c9f12c75e3e28e044a3361bce2eb83748c36512c55668f9b48514b0d085e610d7bf78f3358c81336df93143ecdb7bba5e6
|
7
|
+
data.tar.gz: 5f7b3911296e18c5715de3f43a09a0104c046dacdc32eee97f191281363cc73aeae817ab467590189bfd2584f7f78716b98176ea06bd0e70e72438c214d2586b
|
data/README.md
CHANGED
@@ -24,6 +24,7 @@ In the config.yml file we need three keys set to explain our project to the gene
|
|
24
24
|
* The one to one mapping or aws regions to environments.
|
25
25
|
* The account a environment lives in.
|
26
26
|
* Interpolations for a given environment. Interpolations will be explained in a separate section.
|
27
|
+
4. The `vpc` key can be added under the environment name in the environment configs if you would like to run multiple environments in the same region. If you specify a VPC in one environment then a VPC must be specified in all environments. You can only specify one VPC per environment.
|
27
28
|
|
28
29
|
Here is a example config.yml
|
29
30
|
```yaml
|
data/lib/generator/generator.rb
CHANGED
@@ -24,6 +24,7 @@ module PropertyGenerator
|
|
24
24
|
def generate
|
25
25
|
output = []
|
26
26
|
@service_list.each do | service, path|
|
27
|
+
PropertyGenerator.config_enforcer(@configs.environment_configs)
|
27
28
|
service_instance = PropertyGenerator::Service.new(YAML.load_file(path), @configs, @globals)
|
28
29
|
service_instance.service
|
29
30
|
service_instance.interpolate
|
data/lib/generator/service.rb
CHANGED
@@ -26,19 +26,20 @@ module PropertyGenerator
|
|
26
26
|
#get the map of config for a env
|
27
27
|
interpolations = @environment_configs[env]['interpolations']
|
28
28
|
|
29
|
-
#interate through the properties for an environment and gsub the config
|
30
|
-
|
31
|
-
|
32
|
-
interpolations.each do |matcher_key, matcher_value|
|
33
|
-
if property_value.class == String && property_value_dup.include?("{#{matcher_key}}")
|
34
|
-
@service[env][property_key] = property_value_dup.gsub!("{#{matcher_key}}", matcher_value)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
29
|
+
# Recursively interate through the properties for an environment and gsub the config
|
30
|
+
# with defined interpolations.
|
31
|
+
interpolate_nested_properties(@service[env], interpolations)
|
38
32
|
end
|
39
33
|
service
|
40
34
|
end
|
41
35
|
|
36
|
+
def interpolate_nested_properties(service_env, interpolations)
|
37
|
+
interpolations.each do |matcher_key, matcher_value|
|
38
|
+
service_env.each { |k,v| service_env[k] = v.gsub("{#{matcher_key}}", matcher_value) if v.class == String && v.include?("{#{matcher_key}}")}
|
39
|
+
service_env.values.each { |v| interpolate_nested_properties(v, interpolations) if v.class == Hash }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
42
43
|
def merge_env_default(data, environments)
|
43
44
|
#creates a hash of the enviornments merged with the defaults
|
44
45
|
# {service => {env1 => {properties},
|
data/lib/helpers/helpers.rb
CHANGED
@@ -62,9 +62,17 @@ module PropertyGenerator
|
|
62
62
|
account = environmental_configs[env]["account"]
|
63
63
|
region = environmental_configs[env]["region"]
|
64
64
|
json = JSON.pretty_generate({"properties" => finalized[env]})
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
#IF users are specifing a vpc then we will drop property files under the dir that corresponds to the vpc
|
66
|
+
if environmental_configs[env].key?("vpc") && !environmental_configs[env]["vpc"].nil?
|
67
|
+
vpc_dir = "#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}"
|
68
|
+
FileUtils.mkdir_p("#{vpc_dir}/") unless Dir.exist?(vpc_dir)
|
69
|
+
File.write("#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}/#{service_name}.json", json)
|
70
|
+
output << "#{output_path}/#{account}/#{region}/#{environmental_configs[env]["vpc"]}/#{service_name}.json"
|
71
|
+
else
|
72
|
+
FileUtils.mkdir_p("#{output_path}/#{account}/#{region}/") unless Dir.exist?("#{output_path}/#{account}/#{region}/")
|
73
|
+
File.write("#{output_path}/#{account}/#{region}/#{service_name}.json", json)
|
74
|
+
output << "#{output_path}/#{account}/#{region}/#{service_name}.json"
|
75
|
+
end
|
68
76
|
end
|
69
77
|
output
|
70
78
|
end
|
@@ -78,5 +86,17 @@ module PropertyGenerator
|
|
78
86
|
obj.upload_file(file)
|
79
87
|
end
|
80
88
|
|
89
|
+
#Force users to specify VPCs for all environments if specified for one environment.
|
90
|
+
#This allows us to skip having conditional logic downstream in CPS requests
|
91
|
+
def config_enforcer(environment_configs)
|
92
|
+
a_vpc_exists = false
|
93
|
+
environment_configs.each do |environment, config|
|
94
|
+
if config.key?("vpc")
|
95
|
+
a_vpc_exists = true
|
96
|
+
elsif a_vpc_exists
|
97
|
+
raise("If you are using VPCs then a VPC must be specified for all environments in the environment_configs")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
81
101
|
end
|
82
102
|
end
|
data/lib/linter/config_linter.rb
CHANGED
@@ -14,7 +14,7 @@ module PropertyGenerator
|
|
14
14
|
else
|
15
15
|
tests = ['config_has_correct_keys',
|
16
16
|
'environment_configs_match_environments_list',
|
17
|
-
'
|
17
|
+
'environment_configs_have_valid_region_and_account_values',
|
18
18
|
'environment_configs_have_well_formatted_interpolations',
|
19
19
|
'config_file_is_present']
|
20
20
|
end
|
@@ -61,12 +61,12 @@ module PropertyGenerator
|
|
61
61
|
status
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def environment_configs_have_valid_region_and_account_values
|
65
65
|
status = {status: 'pass', error: ''}
|
66
66
|
environments_missmatch_values = []
|
67
67
|
any_missmatches = false
|
68
68
|
@configs['environment_configs'].keys.each do |environment|
|
69
|
-
unless
|
69
|
+
unless (@configs['environment_configs'][environment].key?('region')) && @configs['accounts'].include?(@configs['environment_configs'][environment]['account'])
|
70
70
|
environments_missmatch_values << environment
|
71
71
|
any_missmatches = true
|
72
72
|
end
|
@@ -13,14 +13,16 @@ module PropertyGenerator
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run_services_tests
|
16
|
-
tests = [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
tests = [
|
17
|
+
'services_have_accepted_keys',
|
18
|
+
'service_environments_are_not_empty',
|
19
|
+
'service_defaults_have_no_hashes_as_values',
|
20
|
+
'service_environments_match_config_environments',
|
21
|
+
'service_environments_have_no_hashes_as_values',
|
22
|
+
'service_encrypted_environments_match_config_environments',
|
23
|
+
'service_encrypted_fields_are_correct',
|
24
|
+
'service_encrypted_region_field_is_accepted'
|
25
|
+
]
|
24
26
|
results = PropertyGenerator.test_runner(self, tests)
|
25
27
|
results
|
26
28
|
end
|
@@ -154,7 +156,7 @@ module PropertyGenerator
|
|
154
156
|
|
155
157
|
def service_encrypted_fields_are_correct
|
156
158
|
status = {status: 'pass', error: ''}
|
157
|
-
accepted_keys = ['region', 'encrypted']
|
159
|
+
accepted_keys = ['region', 'encrypted', 'service']
|
158
160
|
services_with_unacceptable_keys = []
|
159
161
|
@services.each do |path, loaded|
|
160
162
|
if loaded['encrypted'] != nil
|
@@ -162,6 +164,8 @@ module PropertyGenerator
|
|
162
164
|
properties.each do |property, value|
|
163
165
|
if value == nil
|
164
166
|
services_with_unacceptable_keys << {path => {environment => property}}
|
167
|
+
elsif value['$ssm'] == nil
|
168
|
+
services_with_unacceptable_keys << {path => {environment => property}}
|
165
169
|
else
|
166
170
|
if value['$ssm'] != nil
|
167
171
|
value['$ssm'].keys.each do |key|
|