cased-ruby 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 136251a6fad727d85e14bf64bfdb5ecf33fdba19735646c3599398c7a0e44abb
4
- data.tar.gz: 94f191ec590bc6bd68ef98b137abbaa052c8438573bb84d9cb9b63ffec4ae8e4
3
+ metadata.gz: dc3d9c43168af4bfb222f063557726b6579ee497059ee14343e422b49f16c879
4
+ data.tar.gz: bfdb95c9831fd38d4ad86a25772aac3a1740c5de33ad3441c4b7edb0a6f173e9
5
5
  SHA512:
6
- metadata.gz: 613409847cfcda2948b2b3559a754ac6822fca908cec0d1a089475be19801290bf8aee866e592d00bef882b1e3b7027ead484346bd39a404c171b8205a5631fa
7
- data.tar.gz: 3a3d8435ecce240a7cff4a83061c57412d08dd1d16e91c9995caf1f755a4706f40744e7ce11c015a4557d66ea1948b6c54caf05f893205a2f8296aedb9780e7b
6
+ metadata.gz: 1849cbc38766aa621046ba7db1d66e841714a3c8b6005cfc9beda6e606270f83c8429627f3797ce327415f67c55a3db8b3d799c738d446342a283cdb07d3098c
7
+ data.tar.gz: 3bccd4a530a8f5f4384c793570d7cd245fb6a339b5fa5c1df7874bdfcec28f63c21ad90dc3f109a2c9739968c02b69e899ab1f14bfcbf5624b2b6a7620aa2fac
@@ -28,19 +28,3 @@ jobs:
28
28
  - name: Run Tests
29
29
  run: |
30
30
  bundle exec rake test
31
-
32
- - name: Generate yard documentation
33
- run: |
34
- bundle exec yard
35
-
36
- - name: Upload test coverage report
37
- uses: actions/upload-artifact@v2
38
- with:
39
- name: coverage
40
- path: coverage/**/*
41
-
42
- - name: Upload generated yard documentation
43
- uses: actions/upload-artifact@v2
44
- with:
45
- name: yard
46
- path: doc/**/*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cased-ruby (0.4.4)
4
+ cased-ruby (0.5.0)
5
5
  activesupport (~> 6)
6
6
  dotpath (= 0.1.0)
7
7
  faraday (~> 1.0)
@@ -10,11 +10,12 @@ PATH
10
10
  jwt (~> 2)
11
11
  net-http-persistent (~> 3.0)
12
12
  subprocess (~> 1.5.0)
13
+ tty-prompt (~> 0.23.0)
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
- activesupport (6.1.3)
18
+ activesupport (6.1.3.2)
18
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
20
  i18n (>= 1.6, < 2)
20
21
  minitest (>= 5.1)
@@ -30,19 +31,23 @@ GEM
30
31
  safe_yaml (~> 1.0.0)
31
32
  docile (1.3.2)
32
33
  dotpath (0.1.0)
33
- faraday (1.3.0)
34
+ faraday (1.4.1)
35
+ faraday-excon (~> 1.1)
34
36
  faraday-net_http (~> 1.0)
37
+ faraday-net_http_persistent (~> 1.1)
35
38
  multipart-post (>= 1.2, < 3)
36
- ruby2_keywords
39
+ ruby2_keywords (>= 0.0.4)
40
+ faraday-excon (1.1.0)
37
41
  faraday-net_http (1.0.1)
42
+ faraday-net_http_persistent (1.1.0)
38
43
  faraday_middleware (1.0.0)
39
44
  faraday (~> 1.0)
40
45
  hashdiff (1.0.1)
41
- i18n (1.8.9)
46
+ i18n (1.8.10)
42
47
  concurrent-ruby (~> 1.0)
43
48
  jaro_winkler (1.5.4)
44
49
  json (2.5.1)
45
- jwt (2.2.2)
50
+ jwt (2.2.3)
46
51
  minitest (5.13.0)
47
52
  mocha (1.11.2)
48
53
  multipart-post (2.1.1)
@@ -51,6 +56,8 @@ GEM
51
56
  parallel (1.19.1)
52
57
  parser (2.7.1.3)
53
58
  ast (~> 2.4.0)
59
+ pastel (0.8.0)
60
+ tty-color (~> 0.5)
54
61
  public_suffix (4.0.5)
55
62
  rack (2.2.2)
56
63
  rack-protection (2.0.8.1)
@@ -80,6 +87,16 @@ GEM
80
87
  simplecov-html (~> 0.11)
81
88
  simplecov-html (0.12.2)
82
89
  subprocess (1.5.4)
90
+ tty-color (0.6.0)
91
+ tty-cursor (0.7.1)
92
+ tty-prompt (0.23.1)
93
+ pastel (~> 0.8)
94
+ tty-reader (~> 0.8)
95
+ tty-reader (0.9.0)
96
+ tty-cursor (~> 0.7)
97
+ tty-screen (~> 0.8)
98
+ wisper (~> 2.0)
99
+ tty-screen (0.8.1)
83
100
  tzinfo (2.0.4)
84
101
  concurrent-ruby (~> 1.0)
85
102
  unicode-display_width (1.6.1)
@@ -87,6 +104,7 @@ GEM
87
104
  addressable (>= 2.3.6)
88
105
  crack (>= 0.3.2)
89
106
  hashdiff (>= 0.4.0, < 2.0.0)
107
+ wisper (2.0.1)
90
108
  yard (0.9.24)
91
109
  zeitwerk (2.4.2)
92
110
 
data/README.md CHANGED
@@ -9,6 +9,7 @@ A Cased client for Ruby applications in your organization to control and monitor
9
9
  - [Usage](#usage)
10
10
  - [Cased CLI](#cased-cli)
11
11
  - [Starting an approval workflow](#starting-an-approval-workflow)
12
+ - [Attaching metadata to all CLI requests](#attaching-metadata-to-all-cli-requests)
12
13
  - [Audit trails](#audit-trails)
13
14
  - [Publishing events to Cased](#publishing-events-to-cased)
14
15
  - [Retrieving events from a Cased audit trail](#retrieving-events-from-a-cased-audit-trail)
@@ -85,6 +86,17 @@ Cased.configure do |config|
85
86
 
86
87
  # CASED_HTTP_READ_TIMEOUT=10
87
88
  config.http_read_timeout = 10
89
+
90
+ # Attach metadata to all CLI requests. This metadata will appear in Cased and
91
+ # any notification source such as email or Slack.
92
+ #
93
+ # You are limited to 20 properties and cannot be a nested dictionary. Metadata
94
+ # specified in the CLI request overrides any configured globally.
95
+ config.cli.metadata = {
96
+ rails_env: ENV['RAILS_ENV'],
97
+ heroku_application: ENV['HEROKU_APP_NAME'],
98
+ git_commit: ENV['GIT_COMMIT'],
99
+ }
88
100
  end
89
101
  ```
90
102
 
@@ -181,6 +193,27 @@ You no longer need to handle obtaining the user token or asking for a reason up
181
193
  front, `Cased::CLI::InteractiveSession` will prompt the user for any reason
182
194
  being required as necessary.
183
195
 
196
+ #### Attaching metadata to all CLI requests
197
+
198
+ While you can customize the metadata included for each CLI request, it may prove
199
+ useful to specify metadata globally that will be included with each CLI request.
200
+ Some useful information to include may be the current Rails environment, Heroku
201
+ application, Git commit deployed, and more.
202
+
203
+ Metadata is limited to 20 properties and cannot be a nested dictionary.
204
+
205
+ ```ruby
206
+ Cased.configure do |config|
207
+ config.cli.metadata = {
208
+ rails_env: ENV['RAILS_ENV'],
209
+ heroku_application: ENV['HEROKU_APP_NAME'],
210
+ git_commit: ENV['GIT_COMMIT'],
211
+ }
212
+ end
213
+ ```
214
+
215
+ Note: Metadata specified in the CLI request overrides any configured globally.
216
+
184
217
  ### Audit trails
185
218
 
186
219
  #### Publishing events to Cased
data/cased-ruby.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency 'jwt', '~> 2'
37
37
  spec.add_dependency 'net-http-persistent', '~> 3.0'
38
38
  spec.add_dependency 'subprocess', '~> 1.5.0'
39
+ spec.add_dependency 'tty-prompt', '~> 0.23.0'
39
40
  spec.add_development_dependency 'bundler', '2.1.4'
40
41
  spec.add_development_dependency 'byebug', '11.0.1'
41
42
  spec.add_development_dependency 'minitest', '5.13.0'
@@ -15,12 +15,17 @@ module Cased
15
15
  end
16
16
 
17
17
  def self.from_cast(cast)
18
+ return if cast.blank?
19
+
18
20
  stream = cast.split("\n").collect do |data|
19
21
  JSON.parse(data)
20
22
  end
21
23
  header = stream.shift
24
+ return unless header.is_a?(Hash)
22
25
 
23
26
  new(header, stream)
27
+ rescue JSON::ParserError
28
+ nil
24
29
  end
25
30
 
26
31
  # Required
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cased
4
+ module CLI
5
+ class Config
6
+ # @example
7
+ # Cased.configure do |config|
8
+ # config.cli.metadata = {
9
+ # rails_env: ENV['RAILS_ENV'],
10
+ # heroku_application: ENV['HEROKU_APP_NAME'],
11
+ # git_commit: ENV['GIT_COMMIT'],
12
+ # }
13
+ # end
14
+ attr_accessor :metadata
15
+
16
+ def initialize
17
+ @metadata = {}
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'cased/cli/session'
4
+ require 'tty/prompt'
4
5
 
5
6
  module Cased
6
7
  module CLI
@@ -27,6 +28,8 @@ module Cased
27
28
  command: command,
28
29
  metadata: metadata,
29
30
  )
31
+
32
+ @prompt = TTY::Prompt.new
30
33
  end
31
34
 
32
35
  def create
@@ -81,8 +84,11 @@ module Cased
81
84
  private
82
85
 
83
86
  def reason_prompt
84
- print Cased::CLI::Log.string 'Please enter a reason for access: '
85
- session.reason = STDIN.gets.chomp
87
+ reason = @prompt.multiline(Cased::CLI::Log.string('Please enter a reason for access:'), help: '(Press Ctrl+D or Ctrl+Z to submit)')
88
+ session.reason = reason.join("\n")
89
+ rescue TTY::Reader::InputInterrupt
90
+ Cased::CLI::Log.log 'Exiting and canceling request…'
91
+ exit 0
86
92
  end
87
93
 
88
94
  def wait_for_approval
@@ -112,8 +118,10 @@ module Cased
112
118
  exit 1
113
119
  when 'timed_out'
114
120
  Cased::CLI::Log.log 'CLI session has timed out'
121
+ exit 1
115
122
  when 'canceled'
116
123
  Cased::CLI::Log.log 'CLI session has been canceled'
124
+ exit 0
117
125
  end
118
126
  end
119
127
  end
@@ -124,11 +124,18 @@ module Cased
124
124
  # @return [Hash, nil]
125
125
  attr_reader :guard_application
126
126
 
127
+ # Public: Cased may filter out sensitive data in the command, we shouldn't
128
+ # execute what is returned from the server.
129
+ #
130
+ # @return [String, nil]
131
+ attr_reader :original_command
132
+
127
133
  def initialize(reason: nil, command: nil, metadata: {}, authentication: nil)
128
134
  @authentication = authentication || Cased::CLI::Authentication.new
129
135
  @reason = reason
130
- @command = command || [$PROGRAM_NAME, *ARGV].join(' ')
131
- @metadata = metadata
136
+ @original_command = command || [$PROGRAM_NAME, *ARGV].join(' ')
137
+ @command = @original_command
138
+ @metadata = Cased.config.cli.metadata.merge(metadata)
132
139
  @requester = {}
133
140
  @responder = {}
134
141
  @guard_application = {}
@@ -216,7 +223,7 @@ module Cased
216
223
 
217
224
  Cased::CLI::Log.log 'CLI session is now recording'
218
225
 
219
- recorder = Cased::CLI::Recorder.new(command.split(' '), env: {
226
+ recorder = Cased::CLI::Recorder.new(original_command.split(' '), env: {
220
227
  'GUARD_SESSION_ID' => id,
221
228
  'GUARD_APPLICATION_ID' => guard_application.fetch('id'),
222
229
  'GUARD_USER_TOKEN' => requester.fetch('id'),
data/lib/cased/config.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cased/cli/config'
4
+
3
5
  module Cased
4
6
  class Config
5
7
  # The amount of time in seconds to allow the HTTP client to open a
@@ -149,6 +151,16 @@ module Cased
149
151
  # end
150
152
  attr_writer :silence
151
153
 
154
+ # @example
155
+ # Cased.configure do |config|
156
+ # config.cli.metadata = {
157
+ # rails_env: ENV['RAILS_ENV'],
158
+ # heroku_application: ENV['HEROKU_APP_NAME'],
159
+ # git_commit: ENV['GIT_COMMIT'],
160
+ # }
161
+ # end
162
+ attr_reader :cli
163
+
152
164
  def initialize
153
165
  @http_read_timeout = ENV.fetch('CASED_HTTP_READ_TIMEOUT', 10).to_i
154
166
  @http_open_timeout = ENV.fetch('CASED_HTTP_OPEN_TIMEOUT', 5).to_i
@@ -172,6 +184,7 @@ module Cased
172
184
  hash[normalized_key] = api_key if api_key
173
185
  end
174
186
  end
187
+ @cli = Cased::CLI::Config.new
175
188
  end
176
189
 
177
190
  # Policy keys are used to query for events from audit trails.
@@ -224,7 +237,7 @@ module Cased
224
237
  private
225
238
 
226
239
  def parse_bool(val)
227
- %w[1 true t].include?(val&.downcase)
240
+ %w[1 true t].include?(val.to_s&.downcase)
228
241
  end
229
242
  end
230
243
  end
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.4'
4
+ VERSION = '0.5.0'
5
5
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
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
4
+ version: 0.5.0
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-18 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-prompt
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.23.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.23.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: bundler
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -305,6 +319,7 @@ files:
305
319
  - lib/cased/cli/asciinema/file.rb
306
320
  - lib/cased/cli/asciinema/writer.rb
307
321
  - lib/cased/cli/authentication.rb
322
+ - lib/cased/cli/config.rb
308
323
  - lib/cased/cli/identity.rb
309
324
  - lib/cased/cli/interactive_session.rb
310
325
  - lib/cased/cli/log.rb
@@ -343,7 +358,7 @@ files:
343
358
  - lib/cased/sensitive/string.rb
344
359
  - lib/cased/test_helper.rb
345
360
  - lib/cased/version.rb
346
- - vendor/cache/activesupport-6.1.3.gem
361
+ - vendor/cache/activesupport-6.1.3.2.gem
347
362
  - vendor/cache/addressable-2.7.0.gem
348
363
  - vendor/cache/ast-2.4.0.gem
349
364
  - vendor/cache/byebug-11.0.1.gem
@@ -352,20 +367,23 @@ files:
352
367
  - vendor/cache/crack-0.4.3.gem
353
368
  - vendor/cache/docile-1.3.2.gem
354
369
  - vendor/cache/dotpath-0.1.0.gem
355
- - vendor/cache/faraday-1.3.0.gem
370
+ - vendor/cache/faraday-1.4.1.gem
371
+ - vendor/cache/faraday-excon-1.1.0.gem
356
372
  - vendor/cache/faraday-net_http-1.0.1.gem
373
+ - vendor/cache/faraday-net_http_persistent-1.1.0.gem
357
374
  - vendor/cache/faraday_middleware-1.0.0.gem
358
375
  - vendor/cache/hashdiff-1.0.1.gem
359
- - vendor/cache/i18n-1.8.9.gem
376
+ - vendor/cache/i18n-1.8.10.gem
360
377
  - vendor/cache/jaro_winkler-1.5.4.gem
361
378
  - vendor/cache/json-2.5.1.gem
362
- - vendor/cache/jwt-2.2.2.gem
379
+ - vendor/cache/jwt-2.2.3.gem
363
380
  - vendor/cache/minitest-5.13.0.gem
364
381
  - vendor/cache/mocha-1.11.2.gem
365
382
  - vendor/cache/multipart-post-2.1.1.gem
366
383
  - vendor/cache/net-http-persistent-3.1.0.gem
367
384
  - vendor/cache/parallel-1.19.1.gem
368
385
  - vendor/cache/parser-2.7.1.3.gem
386
+ - vendor/cache/pastel-0.8.0.gem
369
387
  - vendor/cache/public_suffix-4.0.5.gem
370
388
  - vendor/cache/rack-2.2.2.gem
371
389
  - vendor/cache/rack-protection-2.0.8.1.gem
@@ -381,9 +399,15 @@ files:
381
399
  - vendor/cache/simplecov-0.18.5.gem
382
400
  - vendor/cache/simplecov-html-0.12.2.gem
383
401
  - vendor/cache/subprocess-1.5.4.gem
402
+ - vendor/cache/tty-color-0.6.0.gem
403
+ - vendor/cache/tty-cursor-0.7.1.gem
404
+ - vendor/cache/tty-prompt-0.23.1.gem
405
+ - vendor/cache/tty-reader-0.9.0.gem
406
+ - vendor/cache/tty-screen-0.8.1.gem
384
407
  - vendor/cache/tzinfo-2.0.4.gem
385
408
  - vendor/cache/unicode-display_width-1.6.1.gem
386
409
  - vendor/cache/webmock-3.8.3.gem
410
+ - vendor/cache/wisper-2.0.1.gem
387
411
  - vendor/cache/yard-0.9.24.gem
388
412
  - vendor/cache/zeitwerk-2.4.2.gem
389
413
  homepage: https://github.com/cased/cased-ruby
Binary file
Binary file
Binary file
Binary file