idlc-sdk-deploy 1.0.0.rc14 → 1.0.0.rc15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +1 -1
- data/lib/idlc-sdk-deploy/config.rb +12 -0
- data/lib/idlc-sdk-deploy/restclient.rb +114 -0
- data/lib/idlc-sdk-deploy/version.rb +1 -1
- data/lib/idlc-sdk-deploy.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ffc09522c3a73e576b93cb4a91d4bfd364899a
|
4
|
+
data.tar.gz: b6c63c346221fa1a4c1c3583668a64e93e445904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57748a8d6093727413c17a28002615a7375141e1ad69e14710b952dd51ce8b035029d8670cfb6847b928e71c87d9b7e9af5e36ab5de49173d51dc37bad9d63d2
|
7
|
+
data.tar.gz: 8646c4aa28104f61ecaf501576a827c17530c82c83102497a151abf8f3c30400e3401f1aace5ea8eed93433332415b7f8881566f156a7275960d844f3270dd75
|
data/bin/console
CHANGED
@@ -21,6 +21,18 @@ module Idlc
|
|
21
21
|
def get_deployment_output(key)
|
22
22
|
`#{Terraform::Binary::Command.binary} output #{key}`.strip!
|
23
23
|
end
|
24
|
+
|
25
|
+
def get_env_metadata(env_key)
|
26
|
+
client = Idlc::Deploy::AWSRestClient.new()
|
27
|
+
|
28
|
+
request = {
|
29
|
+
service: 'deploy',
|
30
|
+
method: 'GET',
|
31
|
+
path: "/metadata/#{env_key}",
|
32
|
+
}
|
33
|
+
|
34
|
+
client.fetch(request.to_json)['deployments'].first
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
38
|
def initialize(region)
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'aws-sigv4'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
# Service Definitions
|
6
|
+
$config = {
|
7
|
+
'config_svc_endpoint' => 'https://un0t03st4m.execute-api.us-east-1.amazonaws.com/dev',
|
8
|
+
'deploy_svc_endpoint' => 'https://dwervfhpxe.execute-api.us-east-1.amazonaws.com/dev'
|
9
|
+
}
|
10
|
+
|
11
|
+
module Idlc
|
12
|
+
module Deploy
|
13
|
+
class AWSRestClient
|
14
|
+
def initialize(credentials= {
|
15
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
16
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
17
|
+
},
|
18
|
+
region=ENV['AWS_REGION']
|
19
|
+
)
|
20
|
+
@service_name = 'execute-api'
|
21
|
+
@credentials = credentials
|
22
|
+
@region = region
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch(request)
|
26
|
+
request = JSON.parse(request)
|
27
|
+
|
28
|
+
endpoint = $config["#{request['service']}_svc_endpoint"]
|
29
|
+
|
30
|
+
body = ''
|
31
|
+
body = request['body'].to_json if request['body']
|
32
|
+
|
33
|
+
resp = send_signed_request(
|
34
|
+
request['method'],
|
35
|
+
"#{endpoint.strip}#{request['path']}",
|
36
|
+
body
|
37
|
+
)
|
38
|
+
|
39
|
+
# if request has 'outfile' param, write response to file
|
40
|
+
to_file(resp, request['outfile']) if request['outfile']
|
41
|
+
|
42
|
+
# return response obj
|
43
|
+
resp
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_file(obj, filename)
|
47
|
+
File.open(filename, 'w') do |f|
|
48
|
+
f.write(obj.to_json)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def send_signed_request(method, url, payload)
|
55
|
+
uri = URI.parse(url)
|
56
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
57
|
+
https.use_ssl = true
|
58
|
+
signature = sigv4_signature(method, url, payload)
|
59
|
+
request = http_request(method, uri.path, signature, payload)
|
60
|
+
|
61
|
+
response = https.request(request)
|
62
|
+
JSON.parse(response.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_headers(request, signature)
|
66
|
+
request.add_field 'host', signature.headers['host']
|
67
|
+
request.add_field 'content-type', 'application/json'
|
68
|
+
request.add_field 'x-amz-content-sha256', signature.headers['x-amz-content-sha256']
|
69
|
+
request.add_field 'x-amz-date', signature.headers['x-amz-date']
|
70
|
+
request.add_field 'authorization', signature.headers['authorization']
|
71
|
+
end
|
72
|
+
|
73
|
+
def http_request(method, path, signature, payload)
|
74
|
+
case method.downcase
|
75
|
+
when 'put'
|
76
|
+
request = Net::HTTP::Put.new(path)
|
77
|
+
when 'post'
|
78
|
+
request = Net::HTTP::Post.new(path)
|
79
|
+
when 'get'
|
80
|
+
request = Net::HTTP::Get.new(path)
|
81
|
+
when 'delete'
|
82
|
+
request = Net::HTTP::Delete.new(path)
|
83
|
+
else
|
84
|
+
request = Net::HTTP::Put.new(path)
|
85
|
+
end
|
86
|
+
|
87
|
+
set_headers(request, signature)
|
88
|
+
request.body = payload
|
89
|
+
|
90
|
+
request
|
91
|
+
end
|
92
|
+
|
93
|
+
def signer
|
94
|
+
Aws::Sigv4::Signer.new(
|
95
|
+
service: @service_name,
|
96
|
+
region: @region,
|
97
|
+
access_key_id: @credentials[:access_key_id],
|
98
|
+
secret_access_key: @credentials[:secret_access_key]
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def sigv4_signature(method, url, payload)
|
103
|
+
signer.sign_request(
|
104
|
+
http_method: method,
|
105
|
+
url: url,
|
106
|
+
headers: {
|
107
|
+
'content-type' => 'application/json'
|
108
|
+
},
|
109
|
+
body: payload
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/idlc-sdk-deploy.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlc-sdk-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Cazell
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/idlc-sdk-deploy/config.rb
|
216
216
|
- lib/idlc-sdk-deploy/keypair.rb
|
217
217
|
- lib/idlc-sdk-deploy/power.rb
|
218
|
+
- lib/idlc-sdk-deploy/restclient.rb
|
218
219
|
- lib/idlc-sdk-deploy/version.rb
|
219
220
|
homepage: https://github.com/nathantcz/idlc-sdk
|
220
221
|
licenses:
|