cps-property-generator 0.2.3 → 0.2.9
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/bin/cps-property-generator +0 -1
- data/lib/generator/generator.rb +9 -1
- data/lib/generator/service.rb +16 -11
- data/lib/helpers/helpers.rb +23 -3
- data/lib/linter/config_linter.rb +3 -3
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fed7d34a4ba2506161886daa161deea7189afdf
|
4
|
+
data.tar.gz: 4a0fc3a7f7ec689e8b4fa6471b94ab4858bd29aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f0f0c82351be0c09c9c6aeffee78c78ab6d2aacfbed0adbd4603cf3e9ab0a1910897b8e1dedd8c99dcf4837d9f01d8bd7ce1225b12add1d9fed39b07bd36d2
|
7
|
+
data.tar.gz: 1dc74865f74328811d78feb315630ac3747f954a7c8de041011b3c493c1ed10acdfa4e518172900e3d25021c7433650bceb4d4e201aece24331ddcff1eaf7083
|
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/bin/cps-property-generator
CHANGED
data/lib/generator/generator.rb
CHANGED
@@ -15,15 +15,17 @@ 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
|
25
26
|
output = []
|
26
27
|
@service_list.each do | service, path|
|
28
|
+
PropertyGenerator.config_enforcer(@configs.environment_configs)
|
27
29
|
service_instance = PropertyGenerator::Service.new(YAML.load_file(path), @configs, @globals)
|
28
30
|
service_instance.service
|
29
31
|
service_instance.interpolate
|
@@ -35,6 +37,12 @@ module PropertyGenerator
|
|
35
37
|
end
|
36
38
|
|
37
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
|
+
|
38
46
|
upload_account = config['upload_account']
|
39
47
|
upload_region = config['upload_region']
|
40
48
|
upload_bucket = config['upload_bucket']
|
data/lib/generator/service.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module PropertyGenerator
|
2
|
+
|
2
3
|
class Service
|
4
|
+
require 'active_support/core_ext/hash'
|
5
|
+
|
3
6
|
attr_accessor :service
|
7
|
+
|
4
8
|
def initialize(service_data, config, globals)
|
5
9
|
@service_data = service_data
|
6
10
|
@environments = config.environments
|
@@ -26,19 +30,20 @@ module PropertyGenerator
|
|
26
30
|
#get the map of config for a env
|
27
31
|
interpolations = @environment_configs[env]['interpolations']
|
28
32
|
|
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
|
33
|
+
# Recursively interate through the properties for an environment and gsub the config
|
34
|
+
# with defined interpolations.
|
35
|
+
interpolate_nested_properties(@service[env], interpolations)
|
38
36
|
end
|
39
37
|
service
|
40
38
|
end
|
41
39
|
|
40
|
+
def interpolate_nested_properties(service_env, interpolations)
|
41
|
+
interpolations.each do |matcher_key, matcher_value|
|
42
|
+
service_env.each { |k,v| service_env[k] = v.gsub("{#{matcher_key}}", matcher_value) if v.class == String && v.include?("{#{matcher_key}}")}
|
43
|
+
service_env.values.each { |v| interpolate_nested_properties(v, interpolations) if v.class == Hash }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
42
47
|
def merge_env_default(data, environments)
|
43
48
|
#creates a hash of the enviornments merged with the defaults
|
44
49
|
# {service => {env1 => {properties},
|
@@ -56,7 +61,7 @@ module PropertyGenerator
|
|
56
61
|
environment_data = data['environments'][env].dup
|
57
62
|
if data['encrypted']
|
58
63
|
encrypted = data['encrypted'][env].dup unless data['encrypted'][env].nil?
|
59
|
-
environment_data = data['environments'][env].
|
64
|
+
environment_data = data['environments'][env].deep_merge(encrypted) unless encrypted.nil?
|
60
65
|
end
|
61
66
|
if default_clone.nil?
|
62
67
|
merged = environment_data
|
@@ -84,6 +89,6 @@ module PropertyGenerator
|
|
84
89
|
output
|
85
90
|
end
|
86
91
|
|
87
|
-
|
88
92
|
end
|
93
|
+
|
89
94
|
end
|
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
|
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.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Call
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.11.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.11.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: terminal-table
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|