envirobly 1.6.1 → 1.7.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/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: 89cfd488c2765b1d8bc3205d34cf6d4e49230f4eb3a371cdb05b6785d690c955
|
4
|
+
data.tar.gz: f52f5be5eaf21eb35273f3d5d9da22af91ca2d6078faedcd1e875ebbcdab13e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f8e1e766e47c1a7765cf96c0b893ab8cec55a16feb1916423f944396bdf9c1c17c215b4ed7f415217ccc8bb4c559331b687e3c91e71b698ea9ed34d81ec2c48
|
7
|
+
data.tar.gz: 2c0d7c929da365fa21c4a946049da551c6ab5eb6c6492babf138b64a01d0f7f43f5c99693989c65bb260ac7ebbc1a0ed47d7bccea633df6ecbedcd2afe4ad0ed
|
@@ -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/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.7.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: []
|