cased-ruby 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f866d60b9da3d895469686a8510dc93a0bf2ec80b45c8b0d0c2af912233b5849
4
- data.tar.gz: bca2f7aff437b0b739a5784b0d598171c5e61c6491ee4bf408fc3718f4a649a1
3
+ metadata.gz: 5356c39c08774c8e104858515fbb9111264c526e72984dd9da83874f87107903
4
+ data.tar.gz: 4ca2cf761ef6d0abc7110988f38038d952bec2be593d4ae2e01a291b46c5cb69
5
5
  SHA512:
6
- metadata.gz: 6fad8ffa2d18d75001a72cd6a861658e5b8e02c11d6ede6f7df320ec420424db372bbbd06f8e3b57425a96f0d684513144a863b6f5a65d7c0301a3fcc15159fc
7
- data.tar.gz: d51546813623b1a5196dbf7bc393581e75ad347522909a45c09bd9ae3e3e620341f905670c71e206f2b12ba405cdb8e589b2c35e2ec7b0cae34b6cb192183a35
6
+ metadata.gz: 04b3651c4658c938257d333f167ab7846f9d7d9efe9a162e3986457af8acf86431ee4bc2b12ed393aed92073474da7f78c0283e584a82deb207041002c9d7bd0
7
+ data.tar.gz: de40f52b7145f88ea18c6f9cfeaa5508a025e3f0d4498db9bd8821f45ba6b412804745f01ffb5ea13cbdc1ba942ac6496f622305af4ba705e6a2d94ccddb5390
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cased-ruby (0.4.2)
4
+ cased-ruby (0.4.3)
5
5
  activesupport (~> 6)
6
6
  dotpath (= 0.1.0)
7
7
  faraday (~> 1.0)
@@ -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
@@ -13,6 +13,8 @@ module Cased
13
13
 
14
14
  def self.log(text)
15
15
  puts string(text)
16
+ ensure
17
+ STDOUT.flush
16
18
  end
17
19
 
18
20
  def self.color(text, color, bold = false)
@@ -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 if response.success?
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 if response.success?
253
+ self.session = response.body
248
254
 
249
255
  canceled?
250
256
  end
@@ -20,8 +20,6 @@ module Cased
20
20
 
21
21
  conn.options.timeout = Cased.config.http_read_timeout
22
22
  conn.options.open_timeout = Cased.config.http_open_timeout
23
-
24
- conn.adapter :net_http_persistent
25
23
  end
26
24
  end
27
25
 
data/lib/cased/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cased
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
5
5
  end
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport