cps-property-generator 0.1.3 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/generator/generator.rb +1 -0
- data/lib/generator/service.rb +10 -9
- data/lib/helpers/helpers.rb +23 -3
- data/lib/linter/report.rb +3 -0
- data/lib/linter/services_linter.rb +49 -17
- 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: 3c31e3fada8f2c72f084530355f4e90890603365
|
4
|
+
data.tar.gz: 552763cf891e7aabfb280c7e43cb95b0ef0fe8ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 588cc805729bbd8968579b8324aaaf33987ef3e19c0ed9bfb220d1892cfdf5b116aa04c244a2aa92d8d0475907725c5ad68526f2e8400257c42801680bf1b3a6
|
7
|
+
data.tar.gz: 6a2cabd3dcdce3ceac2a88f4f6bf5829946509a9804cb85a4142b8d0cecdb663b4a885d73970516d9143cb297d9f96ebbddd587e8cb805042d3353c4303582b3
|
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
|
@@ -108,8 +109,10 @@ encrypted:
|
|
108
109
|
###### Adding interpolations
|
109
110
|
An interpolation is a value that will be dynamically substituted during generation with the correct value for the environment being generated. Interpolations are declared in the config for a given environment. Once declared an interpolation can be used in a property definition by referencing it in braces. If we were to reference the domain interpolation from the example config above we would use `{domain}`.
|
110
111
|
|
112
|
+
Note: values that start with an interpolation must be placed in quotes (ex. "{xxx}.xxx.xxx.{xxx}").
|
113
|
+
|
111
114
|
##### Step 4: Generating Your Properties (Using the CLI)
|
112
115
|
The bin directory contains the generator.rb cli. An example of running the cli is below. The `project_path` argument specifies the path to the properties repo we are generating a uploading properties from. You must be able to create a session with s3 to upload.
|
113
116
|
```sh
|
114
117
|
./generator.rb generate --project_path "~/projects/project-properties" --upload true --upload_account "123456789012" --upload_region "us-east-1" --upload_bucket "propertiesbucket.my-cloud.com"
|
115
|
-
```
|
118
|
+
```
|
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/report.rb
CHANGED
@@ -41,6 +41,9 @@ module PropertyGenerator
|
|
41
41
|
end
|
42
42
|
table = Terminal::Table.new :headings => ['Files'], :title => 'Files Failing to Load', :rows => rows, :style => {:width => 200}
|
43
43
|
puts table
|
44
|
+
puts "*****************"
|
45
|
+
puts "Check for property values that start with an interpolated value \nIf the first character of the value is a bracket yaml will fail to load \nPlace the value in quotes"
|
46
|
+
puts "*****************"
|
44
47
|
end
|
45
48
|
|
46
49
|
def make_pass_table
|
@@ -13,17 +13,39 @@ module PropertyGenerator
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run_services_tests
|
16
|
-
tests = [
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
+
]
|
23
26
|
results = PropertyGenerator.test_runner(self, tests)
|
24
27
|
results
|
25
28
|
end
|
26
29
|
|
30
|
+
def service_environments_are_not_empty
|
31
|
+
status = {status: 'pass', error: ''}
|
32
|
+
services_empty_environments = []
|
33
|
+
@services.each do |path, loaded|
|
34
|
+
unless loaded['environments'] == nil
|
35
|
+
loaded['environments'].each do |environments, properties|
|
36
|
+
if properties == nil
|
37
|
+
services_empty_environments << {path => environments}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if services_empty_environments != []
|
43
|
+
status[:status] = 'fail'
|
44
|
+
status[:error] = "Service files #{services_empty_environments} have empty environments, these should be omitted."
|
45
|
+
end
|
46
|
+
status
|
47
|
+
end
|
48
|
+
|
27
49
|
def services_have_accepted_keys
|
28
50
|
status = {status: 'pass', error: ''}
|
29
51
|
accepted_keys = ['default', 'environments', 'encrypted']
|
@@ -91,9 +113,11 @@ module PropertyGenerator
|
|
91
113
|
@services.each do |path, loaded|
|
92
114
|
unless loaded['environments'] == nil
|
93
115
|
loaded['environments'].each do |environments, properties|
|
94
|
-
properties
|
95
|
-
|
96
|
-
|
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
|
97
121
|
end
|
98
122
|
end
|
99
123
|
end
|
@@ -132,15 +156,23 @@ module PropertyGenerator
|
|
132
156
|
|
133
157
|
def service_encrypted_fields_are_correct
|
134
158
|
status = {status: 'pass', error: ''}
|
135
|
-
accepted_keys = ['region', 'encrypted']
|
159
|
+
accepted_keys = ['region', 'encrypted', 'service']
|
136
160
|
services_with_unacceptable_keys = []
|
137
161
|
@services.each do |path, loaded|
|
138
162
|
if loaded['encrypted'] != nil
|
139
|
-
loaded['encrypted'].each do |environment,
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
163
|
+
loaded['encrypted'].each do |environment, properties|
|
164
|
+
properties.each do |property, value|
|
165
|
+
if value == nil
|
166
|
+
services_with_unacceptable_keys << {path => {environment => property}}
|
167
|
+
elsif value['$ssm'] == nil
|
168
|
+
services_with_unacceptable_keys << {path => {environment => property}}
|
169
|
+
else
|
170
|
+
if value['$ssm'] != nil
|
171
|
+
value['$ssm'].keys.each do |key|
|
172
|
+
unless accepted_keys.include?(key)
|
173
|
+
services_with_unacceptable_keys << {path => {environment => property}}
|
174
|
+
end
|
175
|
+
end
|
144
176
|
end
|
145
177
|
end
|
146
178
|
end
|
@@ -149,7 +181,7 @@ module PropertyGenerator
|
|
149
181
|
end
|
150
182
|
if services_with_unacceptable_keys != []
|
151
183
|
status[:status] = 'fail'
|
152
|
-
status[:error] = "Service files: #{services_with_unacceptable_keys} have encrypted properties with keys other than 'region' and 'encrypted'."
|
184
|
+
status[:error] = "Service files: #{services_with_unacceptable_keys} have encrypted properties with bad indentation or keys other than 'region' and 'encrypted'."
|
153
185
|
end
|
154
186
|
status
|
155
187
|
end
|