envirobly 1.6.2 → 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/access_token.rb +76 -64
- 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 +2 -2
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
|
@@ -3,86 +3,98 @@
|
|
3
3
|
require "fileutils"
|
4
4
|
require "pathname"
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Envirobly
|
7
|
+
class AccessToken
|
8
|
+
include Colorize
|
8
9
|
|
9
|
-
|
10
|
+
APP_NAME = "envirobly"
|
10
11
|
|
11
|
-
|
12
|
-
def destroy
|
13
|
-
if File.exist?(path)
|
14
|
-
FileUtils.rm path
|
15
|
-
end
|
16
|
-
end
|
12
|
+
attr_reader :shell
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
class << self
|
15
|
+
def destroy
|
16
|
+
if File.exist?(path)
|
17
|
+
FileUtils.rm path
|
18
|
+
end
|
23
19
|
end
|
24
|
-
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
def storage_base_dir
|
22
|
+
if dir = ENV["ENVIROBLY_CLI_DATA_HOME"].presence
|
23
|
+
return dir
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
26
|
+
if Gem.win_platform?
|
27
|
+
ENV["APPDATA"] || File.join(Dir.home, "AppData", "Roaming")
|
28
|
+
else
|
29
|
+
ENV["XDG_DATA_HOME"] || File.join(Dir.home, ".local", "share")
|
30
|
+
end
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@token = token
|
38
|
-
end
|
39
|
-
end
|
33
|
+
def storage_dir
|
34
|
+
File.join(storage_base_dir, APP_NAME)
|
35
|
+
end
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
37
|
+
def path
|
38
|
+
Pathname.new(storage_dir).join "access_token"
|
39
|
+
end
|
40
|
+
end
|
46
41
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
42
|
+
def initialize(token = ENV["ENVIROBLY_ACCESS_TOKEN"].presence, shell: nil)
|
43
|
+
@shell = shell
|
50
44
|
|
51
|
-
|
52
|
-
|
45
|
+
if token.blank? && File.exist?(self.class.path)
|
46
|
+
@token = File.read(self.class.path)
|
47
|
+
else
|
48
|
+
@token = token
|
49
|
+
end
|
50
|
+
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
def save
|
53
|
+
FileUtils.mkdir_p self.class.storage_dir
|
54
|
+
File.write self.class.path, @token
|
55
|
+
File.chmod 0600, self.class.path
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
58
|
+
def as_http_bearer
|
59
|
+
"Bearer #{@token}"
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
def require!
|
63
|
+
return if @token.present?
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
shell.say
|
70
|
-
shell.say_error "Cancelled"
|
71
|
-
exit
|
72
|
-
end
|
65
|
+
shell.say "This action requires you to be signed in."
|
66
|
+
shell.say "Please visit https://on.envirobly.com/profile/access_tokens"
|
67
|
+
shell.say "to generate an access token and then paste it in here."
|
68
|
+
shell.say
|
73
69
|
|
74
|
-
|
70
|
+
set
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
def set
|
74
|
+
@token = nil
|
75
|
+
|
76
|
+
while @token.blank?
|
77
|
+
begin
|
78
|
+
@token = shell.ask("Access Token:", echo: false)
|
79
|
+
rescue Interrupt
|
80
|
+
shell.say
|
81
|
+
shell.say_error "Cancelled"
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
api = Api.new(access_token: self, exit_on_error: false)
|
86
|
+
|
87
|
+
# TODO: Eventually replace with custom `whoami` API that returns name, email...
|
88
|
+
if api.list_accounts.success?
|
89
|
+
save
|
90
|
+
shell.say
|
91
|
+
shell.say "Successfully signed in "
|
92
|
+
shell.say green_check
|
93
|
+
else
|
94
|
+
shell.say
|
95
|
+
shell.say_error "This token is invalid. Please try again"
|
96
|
+
@token = nil
|
97
|
+
end
|
86
98
|
end
|
87
99
|
end
|
88
100
|
end
|
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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envirobly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
|
-
rubygems_version: 3.7.
|
217
|
+
rubygems_version: 3.7.2
|
218
218
|
specification_version: 4
|
219
219
|
summary: Envirobly command line interface
|
220
220
|
test_files: []
|