envirobly 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/envirobly/api.rb +50 -13
- data/lib/envirobly/cli/main.rb +4 -10
- data/lib/envirobly/colorize.rb +0 -13
- data/lib/envirobly/deployment.rb +2 -6
- data/lib/envirobly/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e6005245f891cfc1cee6078dfd201ba7662f1beff0d462452e09b5b406eb7f8
|
4
|
+
data.tar.gz: e1ebac83b39461529d6eb06d8b92f4d275bb8225b4868bd97e41104a085dcd67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 696c939aff4ab4047f2eea626d23f381ea364992220a96533a9282946aa3c1ef30915a218ee64776137c7cf4897f723d86476448ef26c8fe9392f6e491ec593e
|
7
|
+
data.tar.gz: 81fcd2a06ce9a82a28a98eebf07f5ed40caa37415cbbaf94103d8fc65e6724950f7a06ed0c27e5a691d1b43777d64fb71170b043fefb0135641573f6039c0422
|
data/lib/envirobly/api.rb
CHANGED
@@ -6,6 +6,8 @@ require "socket"
|
|
6
6
|
require "uri"
|
7
7
|
|
8
8
|
class Envirobly::Api
|
9
|
+
include Envirobly::Colorize
|
10
|
+
|
9
11
|
HOST = ENV["ENVIROBLY_API_HOST"].presence || "on.envirobly.com"
|
10
12
|
USER_AGENT = "Envirobly CLI v#{Envirobly::VERSION}"
|
11
13
|
CONTENT_TYPE = "application/json"
|
@@ -16,12 +18,7 @@ class Envirobly::Api
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def validate_shape(params)
|
19
|
-
post_as_json(api_v1_shape_validations_url, params:, headers: authorization_headers)
|
20
|
-
unless response.success?
|
21
|
-
$stderr.puts "Validation request responded with #{response.code}. Aborting."
|
22
|
-
exit 1
|
23
|
-
end
|
24
|
-
end
|
21
|
+
post_as_json(api_v1_shape_validations_url, params:, headers: authorization_headers)
|
25
22
|
end
|
26
23
|
|
27
24
|
def create_deployment(params)
|
@@ -49,7 +46,7 @@ class Envirobly::Api
|
|
49
46
|
LONG_RETRY_INTERVAL = 6.seconds
|
50
47
|
def get_deployment_with_delay_and_retry(url, tries = 1)
|
51
48
|
sleep SHORT_RETRY_INTERVAL * tries
|
52
|
-
response = get_as_json URI(url)
|
49
|
+
response = get_as_json URI(url), retriable: true
|
53
50
|
|
54
51
|
if response.success?
|
55
52
|
response
|
@@ -67,8 +64,8 @@ class Envirobly::Api
|
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
70
|
-
def get_as_json(url, headers: {})
|
71
|
-
request(url, type: Net::HTTP::Get, headers:)
|
67
|
+
def get_as_json(url, headers: {}, retriable: false)
|
68
|
+
request(url, type: Net::HTTP::Get, headers:, retriable:)
|
72
69
|
end
|
73
70
|
|
74
71
|
def post_as_json(url, params: {}, headers: {})
|
@@ -112,7 +109,11 @@ class Envirobly::Api
|
|
112
109
|
URI::HTTPS.build(host: HOST, path: "/api/#{path}", query:)
|
113
110
|
end
|
114
111
|
|
115
|
-
def request(url, type:, headers: {})
|
112
|
+
def request(url, type:, headers: {}, retriable: false)
|
113
|
+
if ENV["ENVIROBLY_CLI_LOG_LEVEL"] == "debug"
|
114
|
+
puts "[Envirobly::Api] request #{url} #{type} #{headers}"
|
115
|
+
end
|
116
|
+
|
116
117
|
uri = URI(url)
|
117
118
|
http = Net::HTTP.new uri.host, uri.port
|
118
119
|
http.use_ssl = true
|
@@ -126,18 +127,41 @@ class Envirobly::Api
|
|
126
127
|
yield request if block_given?
|
127
128
|
|
128
129
|
http.request(request).tap do |response|
|
130
|
+
if ENV["ENVIROBLY_CLI_LOG_LEVEL"] == "debug"
|
131
|
+
puts "[Envirobly::Api] response #{response.code} => #{response.body}"
|
132
|
+
end
|
133
|
+
|
129
134
|
def response.object
|
130
135
|
@json_parsed_body ||= JSON.parse(body)
|
131
136
|
rescue
|
132
|
-
@json_parsed_body = { error_message
|
137
|
+
@json_parsed_body = { "error_message" => body }
|
133
138
|
end
|
134
139
|
|
135
140
|
def response.success?
|
136
141
|
(200..299).include?(code.to_i)
|
137
142
|
end
|
138
143
|
|
139
|
-
if @exit_on_error && !response.success?
|
140
|
-
|
144
|
+
if !retriable && @exit_on_error && !response.success?
|
145
|
+
informed = false
|
146
|
+
|
147
|
+
if response.object.try(:key?, "error_message")
|
148
|
+
puts response.object["error_message"]
|
149
|
+
informed = true
|
150
|
+
end
|
151
|
+
|
152
|
+
if response.object.try(:key?, "config_errors")
|
153
|
+
display_config_errors response.object["config_errors"]
|
154
|
+
informed = true
|
155
|
+
end
|
156
|
+
|
157
|
+
unless informed
|
158
|
+
puts red("Error response (#{response.code}) from the API")
|
159
|
+
end
|
160
|
+
|
161
|
+
if response.code.to_i == 401
|
162
|
+
puts "Run `envirobly signin` to ensure you're signed in with a valid access token"
|
163
|
+
end
|
164
|
+
|
141
165
|
exit 1
|
142
166
|
end
|
143
167
|
end
|
@@ -150,4 +174,17 @@ class Envirobly::Api
|
|
150
174
|
def authorization_headers
|
151
175
|
{ "Authorization" => @access_token.as_http_bearer }
|
152
176
|
end
|
177
|
+
|
178
|
+
def display_config_errors(errors)
|
179
|
+
puts "#{red(cross)} Config contains the following issues:"
|
180
|
+
|
181
|
+
errors.each do |error|
|
182
|
+
puts
|
183
|
+
puts " #{error["message"]}"
|
184
|
+
|
185
|
+
if error["path"]
|
186
|
+
puts faint(" #{downwards_arrow_to_right} #{error["path"]}")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
153
190
|
end
|
data/lib/envirobly/cli/main.rb
CHANGED
@@ -22,9 +22,8 @@ class Envirobly::Cli::Main < Envirobly::Base
|
|
22
22
|
desc "signout", "Sign out"
|
23
23
|
def signout
|
24
24
|
Envirobly::AccessToken.destroy
|
25
|
-
say "You've signed out
|
26
|
-
say "
|
27
|
-
say "You can sign in again with `envirobly signin`."
|
25
|
+
say "You've signed out"
|
26
|
+
say "You can sign in again with `envirobly signin`"
|
28
27
|
end
|
29
28
|
|
30
29
|
desc "set_default_account", "Choose default account to deploy the current project to"
|
@@ -45,14 +44,9 @@ class Envirobly::Cli::Main < Envirobly::Base
|
|
45
44
|
api = Envirobly::Api.new
|
46
45
|
|
47
46
|
params = { validation: configs.to_params }
|
48
|
-
|
47
|
+
api.validate_shape params
|
49
48
|
|
50
|
-
|
51
|
-
puts "Config is valid #{green_check}"
|
52
|
-
else
|
53
|
-
display_config_errors response.object.fetch("errors")
|
54
|
-
exit 1
|
55
|
-
end
|
49
|
+
say "Config is valid #{green_check}"
|
56
50
|
end
|
57
51
|
|
58
52
|
desc "instance_types [REGION]", "List instance types in the given region, including price and performance characteristics."
|
data/lib/envirobly/colorize.rb
CHANGED
@@ -40,17 +40,4 @@ module Envirobly::Colorize
|
|
40
40
|
def cross
|
41
41
|
"✖"
|
42
42
|
end
|
43
|
-
|
44
|
-
def display_config_errors(errors)
|
45
|
-
puts "#{red(cross)} Config contains the following issues:"
|
46
|
-
|
47
|
-
errors.each do |error|
|
48
|
-
puts
|
49
|
-
puts " #{error["message"]}"
|
50
|
-
|
51
|
-
if error["path"]
|
52
|
-
puts faint(" #{downwards_arrow_to_right} #{error["path"]}")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
43
|
end
|
data/lib/envirobly/deployment.rb
CHANGED
@@ -9,12 +9,12 @@ module Envirobly
|
|
9
9
|
attr_reader :params
|
10
10
|
|
11
11
|
def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:)
|
12
|
-
@environ_name = environ_name
|
13
12
|
@commit = commit
|
14
13
|
@config = Config.new
|
15
14
|
@default_account = Defaults::Account.new(shell:)
|
16
15
|
@default_project = Defaults::Project.new(shell:)
|
17
16
|
@default_region = Defaults::Region.new(shell:)
|
17
|
+
@shell = shell
|
18
18
|
|
19
19
|
target = Target.new(
|
20
20
|
default_account_id: @default_account.value,
|
@@ -41,6 +41,7 @@ module Envirobly
|
|
41
41
|
shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it"
|
42
42
|
end
|
43
43
|
|
44
|
+
@environ_name = target.environ_name
|
44
45
|
@params = {
|
45
46
|
account_id: target.account_id,
|
46
47
|
project_id: target.project_id,
|
@@ -74,11 +75,6 @@ module Envirobly
|
|
74
75
|
Duration.measure do
|
75
76
|
response = api.create_deployment @params
|
76
77
|
|
77
|
-
unless response.success?
|
78
|
-
display_config_errors response.object.fetch("errors")
|
79
|
-
exit 1
|
80
|
-
end
|
81
|
-
|
82
78
|
print "Preparing project..."
|
83
79
|
|
84
80
|
@default_account.save_if_none response.object.fetch("account_id")
|
data/lib/envirobly/version.rb
CHANGED