cps-property-generator 0.2.3 → 0.2.5

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: 0e042787e3f93b205ab6f01979e6005523d00976
4
- data.tar.gz: 47083d9c1317d0979a22dbe0a87f658a68985c53
3
+ metadata.gz: 20120f86a00ba65b0baba64bb5d61da9eed6eb5d
4
+ data.tar.gz: 30816859903c594ad93257ad4b4e65ad3ec460ae
5
5
  SHA512:
6
- metadata.gz: d166611b8b66e5e4cafb267ac05bf549e19df8b0fc3fecea94f4db05b0e558c4480372fb597c096131ab8719bb3ff737c8b225c5e4d08618df4481ffef2c2a9c
7
- data.tar.gz: 18522c9a10a3254c07c29bab837771f1c0ee4421b002d4abcde010da2aab1a91b0eeeea4faf6d4beb2600f5f949e4b97330df94ca89c38bb1974d0f773611ebb
6
+ metadata.gz: c9fcc43c61a741fbfdceb4dc1a9054fe0d0b9d1f56c14c7e7cefe4bb18a1a5580c0f0f79dd4673a3f24d577b6a7a16edc0766753abe91ff08bed64f26820d0a4
7
+ data.tar.gz: 4b30b89007e03f55bfd570745111a1fb539ab485309ebce5647cfc68436e551bdee78604b733150439ec01d2cc205e075ec0eecb5c02067021e6bd869106b86c
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
@@ -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
@@ -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
- @service[env].each do | property_key, property_value|
31
- property_value_dup = property_value.dup
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},
@@ -62,8 +62,15 @@ 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
- FileUtils.mkdir_p("#{output_path}/#{account}/#{region}/") unless Dir.exist?("#{output_path}/#{account}/#{region}/")
66
- File.write("#{output_path}/#{account}/#{region}/#{service_name}.json", json)
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
+ else
71
+ FileUtils.mkdir_p("#{output_path}/#{account}/#{region}/") unless Dir.exist?("#{output_path}/#{account}/#{region}/")
72
+ File.write("#{output_path}/#{account}/#{region}/#{service_name}.json", json)
73
+ end
67
74
  output << "#{output_path}/#{account}/#{region}/#{service_name}.json"
68
75
  end
69
76
  output
@@ -78,5 +85,17 @@ module PropertyGenerator
78
85
  obj.upload_file(file)
79
86
  end
80
87
 
88
+ #Force users to specify VPCs for all environments if specified for one environment.
89
+ #This allows us to skip having conditional logic downstream in CPS requests
90
+ def config_enforcer(environment_configs)
91
+ a_vpc_exists = false
92
+ environment_configs.each do |environment, config|
93
+ if config.key?("vpc")
94
+ a_vpc_exists = true
95
+ elsif a_vpc_exists
96
+ raise("If you are using VPCs then a VPC must be specified for all environments in the environment_configs")
97
+ end
98
+ end
99
+ end
81
100
  end
82
101
  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.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Call