cased-ruby 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cased/cli/interactive_session.rb +33 -0
- data/lib/cased/cli/log.rb +2 -0
- data/lib/cased/cli/session.rb +8 -2
- data/lib/cased/http/client.rb +0 -2
- data/lib/cased/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: 5356c39c08774c8e104858515fbb9111264c526e72984dd9da83874f87107903
|
4
|
+
data.tar.gz: 4ca2cf761ef6d0abc7110988f38038d952bec2be593d4ae2e01a291b46c5cb69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04b3651c4658c938257d333f167ab7846f9d7d9efe9a162e3986457af8acf86431ee4bc2b12ed393aed92073474da7f78c0283e584a82deb207041002c9d7bd0
|
7
|
+
data.tar.gz: de40f52b7145f88ea18c6f9cfeaa5508a025e3f0d4498db9bd8821f45ba6b412804745f01ffb5ea13cbdc1ba942ac6496f622305af4ba705e6a2d94ccddb5390
|
data/Gemfile.lock
CHANGED
@@ -30,8 +30,29 @@ module Cased
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def create
|
33
|
+
signal_handler = Signal.trap('SIGINT') do
|
34
|
+
if session.requested?
|
35
|
+
Cased::CLI::Log.log 'Exiting and canceling request…'
|
36
|
+
session.cancel
|
37
|
+
exit 0
|
38
|
+
elsif signal_handler.respond_to?(:call)
|
39
|
+
# We need to call the original handler if we exit this interactive
|
40
|
+
# session successfully
|
41
|
+
signal_handler.call
|
42
|
+
else
|
43
|
+
raise Interrupt
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
33
47
|
if session.create
|
34
48
|
handle_state(session.state)
|
49
|
+
elsif session.reauthenticate?
|
50
|
+
Cased::CLI::Log.log "You must re-authenticate with Cased due to recent changes to this application's settings."
|
51
|
+
|
52
|
+
identity = Cased::CLI::Identity.new
|
53
|
+
session.authentication.token = identity.identify
|
54
|
+
|
55
|
+
create
|
35
56
|
elsif session.unauthorized?
|
36
57
|
if session.authentication.exists?
|
37
58
|
Cased::CLI::Log.log "Existing credentials at #{session.authentication.credentials_path} are not valid."
|
@@ -61,18 +82,30 @@ module Cased
|
|
61
82
|
end
|
62
83
|
|
63
84
|
def wait_for_approval
|
85
|
+
sleep 1
|
64
86
|
session.refresh && handle_state(session.state)
|
65
87
|
end
|
66
88
|
|
89
|
+
def waiting_for_approval_message
|
90
|
+
return if defined?(@waiting_for_approval_message_displayed)
|
91
|
+
|
92
|
+
motd = session.guard_application.dig('settings', 'message_of_the_day')
|
93
|
+
waiting_message = motd.blank? ? 'Approval request sent…' : motd
|
94
|
+
Cased::CLI::Log.log "#{waiting_message} (id: #{session.id})"
|
95
|
+
@waiting_for_approval_message_displayed = true
|
96
|
+
end
|
97
|
+
|
67
98
|
def handle_state(state)
|
68
99
|
case state
|
69
100
|
when 'approved'
|
70
101
|
Cased::CLI::Log.log 'CLI session has been approved'
|
71
102
|
session.record
|
72
103
|
when 'requested'
|
104
|
+
waiting_for_approval_message
|
73
105
|
wait_for_approval
|
74
106
|
when 'denied'
|
75
107
|
Cased::CLI::Log.log 'CLI session has been denied'
|
108
|
+
exit 1
|
76
109
|
when 'timed_out'
|
77
110
|
Cased::CLI::Log.log 'CLI session has timed out'
|
78
111
|
when 'canceled'
|
data/lib/cased/cli/log.rb
CHANGED
data/lib/cased/cli/session.rb
CHANGED
@@ -175,7 +175,7 @@ module Cased
|
|
175
175
|
return false unless api_url
|
176
176
|
|
177
177
|
response = Cased.clients.cli.get(api_url, user_token: authentication.token)
|
178
|
-
self.session = response.body
|
178
|
+
self.session = response.body
|
179
179
|
end
|
180
180
|
|
181
181
|
def error?
|
@@ -194,6 +194,10 @@ module Cased
|
|
194
194
|
error == :unauthorized
|
195
195
|
end
|
196
196
|
|
197
|
+
def reauthenticate?
|
198
|
+
error == :reauthenticate
|
199
|
+
end
|
200
|
+
|
197
201
|
def record_output?
|
198
202
|
guard_application.dig('settings', 'record_output') || false
|
199
203
|
end
|
@@ -233,6 +237,8 @@ module Cased
|
|
233
237
|
@error = :reason_required
|
234
238
|
when 'unauthorized'
|
235
239
|
@error = :unauthorized
|
240
|
+
when 'reauthenticate'
|
241
|
+
@error = :reauthenticate
|
236
242
|
else
|
237
243
|
@error = true
|
238
244
|
return false
|
@@ -244,7 +250,7 @@ module Cased
|
|
244
250
|
|
245
251
|
def cancel
|
246
252
|
response = Cased.clients.cli.post("#{api_url}/cancel", user_token: authentication.token)
|
247
|
-
self.session = response.body
|
253
|
+
self.session = response.body
|
248
254
|
|
249
255
|
canceled?
|
250
256
|
end
|
data/lib/cased/http/client.rb
CHANGED
data/lib/cased/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cased-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garrett Bjerkhoel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|