canzea 0.1.174 → 0.1.175

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: 2633717fb7c604f0fdd5f4fb418d0435d7100c63
4
- data.tar.gz: 2d3928ae33acaa35848de526b108902478d373ae
3
+ metadata.gz: 06c6af1d3baa89dbc5ddd02ac89307047152a705
4
+ data.tar.gz: 9a6e14edf20bb9ee9337dce4e1da93a654c97c58
5
5
  SHA512:
6
- metadata.gz: '06887890541f9fc7466061264dd02b3714d980daff0afbc2d78c7a33dde21c465f40e3a194a3de5b6b886f1b8744802d2b0111c57c14aede5be54e387ea047b2'
7
- data.tar.gz: 927534226af28afba4bac2d2b7c05f15ea2de272047a2089dca4df28d96447dbfce522deb56d267b499f07fa16250abc8c92e102b65cb289b5c8b775a43790a7
6
+ metadata.gz: c3a4b4618343f70c9c12c2ae706705a4642406192daee7ae583254cec5ef48bdae101c584c5cfbc4464aef40d5ab30f33fe2f4dc208e8466288e1cef36c798ab
7
+ data.tar.gz: 8e4fae3c36f6653f3f3e1f5b1869a6c7a62c1e9905b4ab55e609d2ce72e214033492584ca840cd7668f8b17517e6714b92423f7597d3443d4612749334c236cc
@@ -1,3 +1,3 @@
1
1
  module Canzea
2
- VERSION = "0.1.174"
2
+ VERSION = "0.1.175"
3
3
  end
data/lib/canzea.rb CHANGED
@@ -7,6 +7,7 @@ require "canzea/version"
7
7
  require "canzea/environment"
8
8
  require "helper-run-class"
9
9
  require "trace-component"
10
+ require "prepare-environment"
10
11
  require "plan-step-class"
11
12
  require "ssh-base-cmd-class"
12
13
  require "template-runner"
@@ -69,6 +70,7 @@ module Canzea
69
70
  option nil, :catalogTag, 'Specific tag of the catalog', argument: :required
70
71
  option nil, :gitRoot, 'Git root', argument: :required
71
72
  option nil, :gitUri, 'Git URI', argument: :required
73
+ option nil, :env, 'Dynamic environment json', argument: :required
72
74
 
73
75
  option nil, :commit, 'Commit', argument: :required
74
76
  option nil, :role, 'Role', argument: :required
@@ -129,6 +131,10 @@ module Canzea
129
131
  puts "Catalog: #{ENV['CATALOG_BRANCH']} ( #{ENV['CATALOG_COMMIT']} )"
130
132
  end
131
133
 
134
+ if (opts[:env])
135
+ env = JSON.parse(opts.fetch(:env, '{}')
136
+ PrepareEnvironment.new.addToEnvFromJSON(env)
137
+ end
132
138
 
133
139
  if (opts[:util])
134
140
  AddEnv.new(opts.fetch(:raw, false)).injectEnvironmentVariables
@@ -11,14 +11,20 @@ class PrepareEnvironment
11
11
  end
12
12
 
13
13
  def addToEnv (envFile)
14
- log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
15
-
16
- r = Registry.new
17
14
 
18
15
  file = File.read(envFile)
19
16
 
20
17
  serviceLookups = JSON.parse(file)
21
18
 
19
+ addToEnvFromJSON(serviceLookups)
20
+ end
21
+
22
+ def addToEnvFromJSON (serviceLookups)
23
+ log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
24
+
25
+ r = Registry.new
26
+
27
+
22
28
  if (serviceLookups.has_key?('environment'))
23
29
  serviceLookups['environment'].each do |svc|
24
30
 
@@ -28,157 +34,162 @@ class PrepareEnvironment
28
34
  end
29
35
  end
30
36
 
31
- serviceLookups['keyvalues'].each do |svc|
32
-
33
- pputs("-- Looking up...#{svc['name']}")
34
-
35
- uri = URI.parse(ENV["CONSUL_URL"] + '/v1/kv/' + svc['name'])
36
- http = Net::HTTP.new(uri.host, uri.port)
37
-
38
- if (Canzea::config[:consul_tls])
39
- pemCert = File.read(Canzea::config[:consul_tls_cert_file])
40
- pemKey = File.read(Canzea::config[:consul_tls_key_file])
41
-
42
- http.use_ssl = true
43
- http.ca_file = Canzea::config[:consul_tls_ca_file]
44
- http.cert = OpenSSL::X509::Certificate.new(pemCert)
45
- http.key = OpenSSL::PKey::RSA.new(pemKey)
46
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
47
- # http.set_debug_output($stdout)
48
- http.ssl_version = :SSLv23
49
- end
50
- request = Net::HTTP::Get.new(uri.request_uri)
51
- resp = http.request(request)
52
-
53
- if Integer(resp.code) != 200
54
- log.warn("KEY VALUE NOT FOUND! " + svc['name'])
55
- puts "-- KEY VALUE NOT FOUND! " + svc['name']
56
- abort("Problem, response code #{resp.code}")
57
- end
58
-
59
- result = JSON.parse(resp.body)
60
- s = Base64.decode64(result[0]["Value"])
61
-
62
- if (s.nil? == false)
63
- # puts s
64
-
65
- key = "" + svc['name'].upcase
66
- key = key.gsub(/\./, '').gsub(/-/, '_').gsub(/\//, '_')
67
- log.info("Setting: " + key + " : " + s)
68
- ENV.store(key, s)
69
- else
70
- log.warn("KEY VALUE NOT FOUND! " + svc['name'])
71
- pputs "-- KEY VALUE NOT FOUND! " + svc['name']
72
- abort()
73
- end
37
+ if (serviceLookups.has_key?('keyvalues'))
38
+ serviceLookups['keyvalues'].each do |svc|
39
+
40
+ pputs("-- Looking up...#{svc['name']}")
41
+
42
+ uri = URI.parse(ENV["CONSUL_URL"] + '/v1/kv/' + svc['name'])
43
+ http = Net::HTTP.new(uri.host, uri.port)
44
+
45
+ if (Canzea::config[:consul_tls])
46
+ pemCert = File.read(Canzea::config[:consul_tls_cert_file])
47
+ pemKey = File.read(Canzea::config[:consul_tls_key_file])
48
+
49
+ http.use_ssl = true
50
+ http.ca_file = Canzea::config[:consul_tls_ca_file]
51
+ http.cert = OpenSSL::X509::Certificate.new(pemCert)
52
+ http.key = OpenSSL::PKey::RSA.new(pemKey)
53
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
54
+ # http.set_debug_output($stdout)
55
+ http.ssl_version = :SSLv23
56
+ end
57
+ request = Net::HTTP::Get.new(uri.request_uri)
58
+ resp = http.request(request)
59
+
60
+ if Integer(resp.code) != 200
61
+ log.warn("KEY VALUE NOT FOUND! " + svc['name'])
62
+ puts "-- KEY VALUE NOT FOUND! " + svc['name']
63
+ abort("Problem, response code #{resp.code}")
64
+ end
65
+
66
+ result = JSON.parse(resp.body)
67
+ s = Base64.decode64(result[0]["Value"])
68
+
69
+ if (s.nil? == false)
70
+ # puts s
71
+
72
+ key = "" + svc['name'].upcase
73
+ key = key.gsub(/\./, '').gsub(/-/, '_').gsub(/\//, '_')
74
+ log.info("Setting: " + key + " : " + s)
75
+ ENV.store(key, s)
76
+ else
77
+ log.warn("KEY VALUE NOT FOUND! " + svc['name'])
78
+ pputs "-- KEY VALUE NOT FOUND! " + svc['name']
79
+ abort()
80
+ end
81
+ end
74
82
  end
75
83
 
84
+ if (serviceLookups.has_key?('services'))
85
+ serviceLookups['services'].each do |svc|
76
86
 
77
- serviceLookups['services'].each do |svc|
78
-
79
- pputs "-- Looking up...#{svc['name']}"
80
-
81
- uri = URI.parse(ENV["CONSUL_URL"] + '/v1/catalog/service/' + svc['name'])
82
- http = Net::HTTP.new(uri.host, uri.port)
83
-
84
- if (Canzea::config[:consul_tls])
85
- pemCert = File.read(Canzea::config[:consul_tls_cert_file])
86
- pemKey = File.read(Canzea::config[:consul_tls_key_file])
87
-
88
- http.use_ssl = true
89
- http.ca_file = Canzea::config[:consul_tls_ca_file]
90
- http.cert = OpenSSL::X509::Certificate.new(pemCert)
91
- http.key = OpenSSL::PKey::RSA.new(pemKey)
92
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
93
- # http.set_debug_output($stdout)
94
- http.ssl_version = :SSLv23
95
- end
96
- request = Net::HTTP::Get.new(uri.request_uri)
97
- resp = http.request(request)
98
-
99
- services = JSON.parse(resp.body)
100
-
101
- if (services.nil? == false)
102
-
103
- services.each { | s |
104
-
105
- key = "" + svc['name'].upcase + "_ADDRESS"
106
- key = key.gsub(/\./, '')
107
- key = key.gsub(/-/, '_')
108
- log.info("Setting: " + key + " : " + s["ServiceAddress"])
109
- ENV.store(key, s["ServiceAddress"])
110
-
111
- key = "" + svc['name'].upcase + "_PORT"
112
- key = key.gsub(/\./, '')
113
- key = key.gsub(/-/, '_')
114
- log.info("Setting: " + key + " : " + String(s["ServicePort"]))
115
- ENV.store(key, String(s["ServicePort"]))
116
-
117
- key = "" + svc['name'].upcase + "_URL"
118
- key = key.gsub(/\./, '')
119
- key = key.gsub(/-/, '_')
120
- val = "http://" + s["ServiceAddress"] + ":" + String(s["ServicePort"])
121
- log.info("Setting: " + key + " : " + val)
122
- ENV.store(key, val)
123
- }
124
- else
125
- log.warn("SERVICE NOT FOUND! " + svc['name'])
126
- pputs "-- SERVICE NOT FOUND! " + svc['name']
127
- abort()
128
- end
87
+ pputs "-- Looking up...#{svc['name']}"
88
+
89
+ uri = URI.parse(ENV["CONSUL_URL"] + '/v1/catalog/service/' + svc['name'])
90
+ http = Net::HTTP.new(uri.host, uri.port)
91
+
92
+ if (Canzea::config[:consul_tls])
93
+ pemCert = File.read(Canzea::config[:consul_tls_cert_file])
94
+ pemKey = File.read(Canzea::config[:consul_tls_key_file])
95
+
96
+ http.use_ssl = true
97
+ http.ca_file = Canzea::config[:consul_tls_ca_file]
98
+ http.cert = OpenSSL::X509::Certificate.new(pemCert)
99
+ http.key = OpenSSL::PKey::RSA.new(pemKey)
100
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
101
+ # http.set_debug_output($stdout)
102
+ http.ssl_version = :SSLv23
103
+ end
104
+ request = Net::HTTP::Get.new(uri.request_uri)
105
+ resp = http.request(request)
106
+
107
+ services = JSON.parse(resp.body)
108
+
109
+ if (services.nil? == false)
110
+
111
+ services.each { | s |
112
+
113
+ key = "" + svc['name'].upcase + "_ADDRESS"
114
+ key = key.gsub(/\./, '')
115
+ key = key.gsub(/-/, '_')
116
+ log.info("Setting: " + key + " : " + s["ServiceAddress"])
117
+ ENV.store(key, s["ServiceAddress"])
118
+
119
+ key = "" + svc['name'].upcase + "_PORT"
120
+ key = key.gsub(/\./, '')
121
+ key = key.gsub(/-/, '_')
122
+ log.info("Setting: " + key + " : " + String(s["ServicePort"]))
123
+ ENV.store(key, String(s["ServicePort"]))
124
+
125
+ key = "" + svc['name'].upcase + "_URL"
126
+ key = key.gsub(/\./, '')
127
+ key = key.gsub(/-/, '_')
128
+ val = "http://" + s["ServiceAddress"] + ":" + String(s["ServicePort"])
129
+ log.info("Setting: " + key + " : " + val)
130
+ ENV.store(key, val)
131
+ }
132
+ else
133
+ log.warn("SERVICE NOT FOUND! " + svc['name'])
134
+ pputs "-- SERVICE NOT FOUND! " + svc['name']
135
+ abort()
136
+ end
137
+ end
129
138
  end
130
139
 
131
- serviceLookups['secrets'].each do |svc|
140
+ if (serviceLookups.has_key?('secrets'))
141
+ serviceLookups['secrets'].each do |svc|
132
142
 
133
- pputs "-- Looking up secret...#{svc['name']}"
143
+ pputs "-- Looking up secret...#{svc['name']}"
134
144
 
135
- uri = URI.parse(ENV["VAULT_URL"] + '/v1/secret/' + svc['name'])
136
- http = Net::HTTP.new(uri.host, uri.port)
145
+ uri = URI.parse(ENV["VAULT_URL"] + '/v1/secret/' + svc['name'])
146
+ http = Net::HTTP.new(uri.host, uri.port)
137
147
 
138
- if (Canzea::config[:consul_tls])
148
+ if (Canzea::config[:consul_tls])
139
149
 
140
- pemCert = File.read(Canzea::config[:vault_tls_cert_file])
141
- pemKey = File.read(Canzea::config[:vault_tls_key_file])
150
+ pemCert = File.read(Canzea::config[:vault_tls_cert_file])
151
+ pemKey = File.read(Canzea::config[:vault_tls_key_file])
142
152
 
143
- http.use_ssl = true
144
- http.ca_file = Canzea::config[:consul_tls_ca_file]
145
- http.cert = OpenSSL::X509::Certificate.new(pemCert)
146
- http.key = OpenSSL::PKey::RSA.new(pemKey)
147
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
148
- # http.set_debug_output($stdout)
149
- http.ssl_version = :SSLv23
150
- end
153
+ http.use_ssl = true
154
+ http.ca_file = Canzea::config[:consul_tls_ca_file]
155
+ http.cert = OpenSSL::X509::Certificate.new(pemCert)
156
+ http.key = OpenSSL::PKey::RSA.new(pemKey)
157
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
158
+ # http.set_debug_output($stdout)
159
+ http.ssl_version = :SSLv23
160
+ end
151
161
 
152
- request = Net::HTTP::Get.new(uri.request_uri)
162
+ request = Net::HTTP::Get.new(uri.request_uri)
153
163
 
154
- request['X-Vault-Token'] = ENV["VAULT_TOKEN"]
155
- request['Content-type'] = 'application/json'
164
+ request['X-Vault-Token'] = ENV["VAULT_TOKEN"]
165
+ request['Content-type'] = 'application/json'
156
166
 
157
- resp = http.request(request)
167
+ resp = http.request(request)
158
168
 
159
- # puts resp.body
169
+ # puts resp.body
160
170
 
161
- if (Integer(resp.code) == 200)
171
+ if (Integer(resp.code) == 200)
162
172
 
163
- data = JSON.parse(resp.body)
173
+ data = JSON.parse(resp.body)
164
174
 
165
- s = data['data']
166
- s.each do |k|
167
- key = "" + svc['name'].upcase + "_" + k[0].upcase
168
- key = key.gsub(/\./, '').gsub(/-/, '_').gsub(/\//, '_')
175
+ s = data['data']
176
+ s.each do |k|
177
+ key = "" + svc['name'].upcase + "_" + k[0].upcase
178
+ key = key.gsub(/\./, '').gsub(/-/, '_').gsub(/\//, '_')
169
179
 
170
- log.info("Setting: " + key)
171
- if k[1].is_a? String
172
- ENV.store(key, k[1])
180
+ log.info("Setting: " + key)
181
+ if k[1].is_a? String
182
+ ENV.store(key, k[1])
183
+ end
184
+ end
185
+ else
186
+ log.warn( "SECRET NOT FOUND! " + svc['name'])
187
+ log.warn( "ERROR FROM VAULT " + resp.body)
188
+ pputs "-- SECRET NOT FOUND! " + svc['name']
189
+ pputs "-- ERROR FROM VAULT " + resp.body
190
+ abort()
173
191
  end
174
192
  end
175
- else
176
- log.warn( "SECRET NOT FOUND! " + svc['name'])
177
- log.warn( "ERROR FROM VAULT " + resp.body)
178
- pputs "-- SECRET NOT FOUND! " + svc['name']
179
- pputs "-- ERROR FROM VAULT " + resp.body
180
- abort()
181
- end
182
193
  end
183
194
  end
184
195
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canzea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.174
4
+ version: 0.1.175
5
5
  platform: ruby
6
6
  authors:
7
7
  - Canzea Technologies