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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6847ac8a3a697faa9a95a4b13a303361bbb19dc0
4
- data.tar.gz: 4aca28022cf88bf9f9eaf3ca9c55ebcaaf5d32e8
3
+ metadata.gz: c0ffc09522c3a73e576b93cb4a91d4bfd364899a
4
+ data.tar.gz: b6c63c346221fa1a4c1c3583668a64e93e445904
5
5
  SHA512:
6
- metadata.gz: b6d390d92c8275c2945d6c1da9b8a83504ee9f0be43ed95e4b3f633d2c3bed5222ea00eab741ecc8e5c7c05fb40b3894cc377ec359f3b925bd1e8143c058fd90
7
- data.tar.gz: fa448aeb49775be821774cf820b2751be52162695fc9719262345bf4c533708aec6786f741f730acc341ccb9e5a58b1d26f4000a715399925a53075fd9e88fe3
6
+ metadata.gz: 57748a8d6093727413c17a28002615a7375141e1ad69e14710b952dd51ce8b035029d8670cfb6847b928e71c87d9b7e9af5e36ab5de49173d51dc37bad9d63d2
7
+ data.tar.gz: 8646c4aa28104f61ecaf501576a827c17530c82c83102497a151abf8f3c30400e3401f1aace5ea8eed93433332415b7f8881566f156a7275960d844f3270dd75
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "idlc/sdk/deploy"
4
+ require "idlc-sdk-deploy"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Idlc
2
2
  module Deploy
3
- VERSION = '1.0.0.rc14'.freeze
3
+ VERSION = '1.0.0.rc15'.freeze
4
4
  end
5
5
  end
@@ -17,5 +17,6 @@ require 'idlc-sdk-core'
17
17
  require 'idlc-sdk-deploy/config'
18
18
  require 'idlc-sdk-deploy/power'
19
19
  require 'idlc-sdk-deploy/keypair'
20
+ require 'idlc-sdk-deploy/restclient'
20
21
 
21
22
  Idlc::Deploy::Config.load_tasks
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.rc14
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: