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 +4 -4
- data/lib/canzea/version.rb +1 -1
- data/lib/canzea.rb +6 -0
- data/lib/prepare-environment.rb +145 -134
- 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: 06c6af1d3baa89dbc5ddd02ac89307047152a705
|
4
|
+
data.tar.gz: 9a6e14edf20bb9ee9337dce4e1da93a654c97c58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a4b4618343f70c9c12c2ae706705a4642406192daee7ae583254cec5ef48bdae101c584c5cfbc4464aef40d5ab30f33fe2f4dc208e8466288e1cef36c798ab
|
7
|
+
data.tar.gz: 8e4fae3c36f6653f3f3e1f5b1869a6c7a62c1e9905b4ab55e609d2ce72e214033492584ca840cd7668f8b17517e6714b92423f7597d3443d4612749334c236cc
|
data/lib/canzea/version.rb
CHANGED
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
|
data/lib/prepare-environment.rb
CHANGED
@@ -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
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
140
|
+
if (serviceLookups.has_key?('secrets'))
|
141
|
+
serviceLookups['secrets'].each do |svc|
|
132
142
|
|
133
|
-
|
143
|
+
pputs "-- Looking up secret...#{svc['name']}"
|
134
144
|
|
135
|
-
|
136
|
-
|
145
|
+
uri = URI.parse(ENV["VAULT_URL"] + '/v1/secret/' + svc['name'])
|
146
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
137
147
|
|
138
|
-
|
148
|
+
if (Canzea::config[:consul_tls])
|
139
149
|
|
140
|
-
|
141
|
-
|
150
|
+
pemCert = File.read(Canzea::config[:vault_tls_cert_file])
|
151
|
+
pemKey = File.read(Canzea::config[:vault_tls_key_file])
|
142
152
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
162
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
153
163
|
|
154
|
-
|
155
|
-
|
164
|
+
request['X-Vault-Token'] = ENV["VAULT_TOKEN"]
|
165
|
+
request['Content-type'] = 'application/json'
|
156
166
|
|
157
|
-
|
167
|
+
resp = http.request(request)
|
158
168
|
|
159
|
-
|
169
|
+
# puts resp.body
|
160
170
|
|
161
|
-
|
171
|
+
if (Integer(resp.code) == 200)
|
162
172
|
|
163
|
-
|
173
|
+
data = JSON.parse(resp.body)
|
164
174
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
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
|
|