cased-ruby 0.4.0 → 0.4.1

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: e22f14bbfac74d8d6ed2565ab7d4dd2607b03178a8534e15681ebad08aadd047
4
- data.tar.gz: aeec32fc2d39829a6e4c24b4b8024b416dad08d84528d13eaa2d310c4a3c2c59
3
+ metadata.gz: f91759262adc1b192cc5305bb9f84448b888bcb258c7c297f9494b0bba71b55c
4
+ data.tar.gz: ce78dd8209246e35dd4ed0fb76f15870b074352b29cf73f01eba426352176572
5
5
  SHA512:
6
- metadata.gz: ba38566776a824c05f9750a72ca0e0b878279a07e5134fac83d54e9f10d462a8a940bf01f5d0968c1654adfb9a196f3d7ad6398614c987e41168bdf81d40cd93
7
- data.tar.gz: f5bde94bab92b5cfc4dce4a146ca5a1d02d7946f14e5003386b3b82c920c656b92665b801b5ae5ef116316b0d33e7c3d727a730bda46426e30d08380b7bac798
6
+ metadata.gz: f13376f04cc1d8dc3c8d93ffcc0403e073d9819ec71f1344f9cb0801b596ab21e31646c89ba02c3a5577dc1afd65ee6a2f24e779eb1e45c9d59ef49b9754fcf3
7
+ data.tar.gz: 8a13f691413981290dfda15d90d6576fdf04723dbc4ede2872d7e9cd476488182bda4a8fdf05eec6f2680490c342fddb1d9aaf0a1f0c32be7739e284c231a01e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cased-ruby (0.4.0)
4
+ cased-ruby (0.4.1)
5
5
  activesupport (~> 6)
6
6
  dotpath (= 0.1.0)
7
7
  faraday (~> 1.0)
data/README.md CHANGED
@@ -7,14 +7,17 @@ A Cased client for Ruby applications in your organization to control and monitor
7
7
  - [Installation](#installation)
8
8
  - [Configuration](#configuration)
9
9
  - [Usage](#usage)
10
- - [Publishing events to Cased](#publishing-events-to-cased)
11
- - [Retrieving events from a Cased audit trail](#retrieving-events-from-a-cased-audit-trail)
12
- - [Retrieving events from multiple Cased audit trails](#retrieving-events-from-multiple-cased-audit-trails)
13
- - [Exporting events](#exporting-events)
14
- - [Masking & filtering sensitive information](#masking--filtering-sensitive-information)
15
- - [Disable publishing events](#disable-publishing-events)
16
- - [Context](#context)
17
- - [Testing](#testing)
10
+ - [Cased CLI](#cased-cli)
11
+ - [Starting an approval workflow](#starting-an-approval-workflow)
12
+ - [Audit trails](#audit-trails)
13
+ - [Publishing events to Cased](#publishing-events-to-cased)
14
+ - [Retrieving events from a Cased audit trail](#retrieving-events-from-a-cased-audit-trail)
15
+ - [Retrieving events from multiple Cased audit trails](#retrieving-events-from-multiple-cased-audit-trails)
16
+ - [Exporting events](#exporting-events)
17
+ - [Masking & filtering sensitive information](#masking--filtering-sensitive-information)
18
+ - [Disable publishing events](#disable-publishing-events)
19
+ - [Context](#context)
20
+ - [Testing](#testing)
18
21
  - [Customizing cased-ruby](#customizing-cased-ruby)
19
22
  - [Contributing](#contributing)
20
23
 
@@ -56,9 +59,21 @@ Cased.configure do |config|
56
59
  # CASED_PUBLISH_URL=https://publish.cased.com
57
60
  config.publish_url = 'https://publish.cased.com'
58
61
 
62
+ # CASED_URL=https://app.cased.com
63
+ config.url = 'https://app.cased.com'
64
+
59
65
  # CASED_API_URL=https://api.cased.com
60
66
  config.api_url = 'https://api.cased.com'
61
67
 
68
+ # GUARD_APPLICATION_KEY=guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH
69
+ config.guard_application_key = 'guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH'
70
+
71
+ # GUARD_USER_TOKEN=user_1oFqlROLNRGVLOXJSsHkJiVmylr
72
+ config.guard_user_token = 'user_1oFqlROLNRGVLOXJSsHkJiVmylr'
73
+
74
+ # DENY_IF_UNREACHABLE=1
75
+ config.guard_deny_if_unreachable = true
76
+
62
77
  # CASED_RAISE_ON_ERRORS=1
63
78
  config.raise_on_errors = false
64
79
 
@@ -75,7 +90,99 @@ end
75
90
 
76
91
  ## Usage
77
92
 
78
- ### Publishing events to Cased
93
+ ### Cased CLI
94
+
95
+ Keep any command line tool available as your team grows — monitor usage, require peer approvals for sensitive operations, and receive intelligent alerts to suspicious activity.
96
+
97
+ #### Starting an approval workflow
98
+
99
+ To start an approval workflow you must first obtain your application key and the
100
+ user token for who is requesting access.
101
+
102
+ ```ruby
103
+ Cased.configure do |config|
104
+ config.guard_application_key = 'guard_application_1pG43HF3aRHjNTTm10zzu0tngBO'
105
+ end
106
+
107
+ authentication = Cased::CLI::Authentication.new(token: 'user_1pG43D1AzTjLR8XWJHj8B3aNZ4Y')
108
+ session = Cased::CLI::Session.new(
109
+ authentication: authentication,
110
+ reason: 'I need export our GitHub issues.',
111
+ metadata: {
112
+ organization: 'GitHub',
113
+ },
114
+ )
115
+
116
+ if session.create && session.approved?
117
+ github.issues.each do |issue|
118
+ puts issue.title
119
+ end
120
+ else
121
+ puts 'Unauthorized to export GitHub issues.'
122
+ end
123
+ ```
124
+
125
+ If you do not have the user token you can always request it interactively.
126
+ [Cased::CLI::Identity#identify](https://github.com/cased/cased-ruby/blob/3b0c8ebd37ba7deb83236be7dba4d52c74d7e4e5/lib/cased/cli/identity.rb#L10-L21)
127
+ is a blocking operation prompting the user to visit Cased to identify
128
+ themselves, returning their user token upon identifying themselves which can be
129
+ used to start your session.
130
+
131
+ ```ruby
132
+ Cased.configure do |config|
133
+ config.guard_application_key = 'guard_application_1pG43HF3aRHjNTTm10zzu0tngBO'
134
+ end
135
+
136
+ authentication = Cased::CLI::Authentication.new
137
+ identity = Cased::CLI::Identity.new
138
+ authentication.token = identity.identify
139
+
140
+ session = Cased::CLI::Session.new(
141
+ authentication: authentication,
142
+ reason: 'I need export our GitHub issues.',
143
+ metadata: {
144
+ organization: 'GitHub',
145
+ },
146
+ )
147
+
148
+ if session.create && session.approved?
149
+ github.issues.each do |issue|
150
+ puts issue.title
151
+ end
152
+ else
153
+ puts 'Unauthorized to export GitHub issues.'
154
+ end
155
+ ```
156
+
157
+ #### Starting an interactive approval workflow
158
+
159
+ If you do not want to manually create sessions and handle each state manually,
160
+ you can use the interactive approval workflow using
161
+ [Cased::CLI::InteractiveSession](https://github.com/cased/cased-ruby/blob/3b0c8ebd37ba7deb83236be7dba4d52c74d7e4e5/lib/cased/cli/interactive_session.rb).
162
+
163
+ ```ruby
164
+ Cased.configure do |config|
165
+ config.guard_application_key = 'guard_application_1pG43HF3aRHjNTTm10zzu0tngBO'
166
+ end
167
+
168
+ session = Cased::CLI::InteractiveSession.start
169
+
170
+ if session.approved?
171
+ github.issues.each do |issue|
172
+ puts issue.title
173
+ end
174
+ else
175
+ puts 'Unauthorized to export GitHub issues.'
176
+ end
177
+ ```
178
+
179
+ You no longer need to handle obtaining the user token or asking for a reason up
180
+ front, `Cased::CLI::InteractiveSession` will prompt the user for any reason
181
+ being required as necessary.
182
+
183
+ ### Audit trails
184
+
185
+ #### Publishing events to Cased
79
186
 
80
187
  There are two ways to publish your first Cased event.
81
188
 
@@ -170,7 +277,7 @@ Both examples above are equivelent in that they publish the following `credit_ca
170
277
  }
171
278
  ```
172
279
 
173
- ### Retrieving events from a Cased audit trail
280
+ #### Retrieving events from a Cased audit trail
174
281
 
175
282
  If you plan on retrieving audit events from your Cased audit trail you must use a Cased API key.
176
283
 
@@ -193,7 +300,7 @@ query.success? # => true
193
300
  query.error? # => false
194
301
  ```
195
302
 
196
- ### Retrieving events from multiple Cased audit trails
303
+ #### Retrieving events from multiple Cased audit trails
197
304
 
198
305
  To retrieve audit events from one or more Cased audit trails you can configure multiple Cased Policy API keys and retrieve events for each one.
199
306
 
@@ -222,7 +329,7 @@ results.each do |event|
222
329
  end
223
330
  ```
224
331
 
225
- ### Exporting events
332
+ #### Exporting events
226
333
 
227
334
  Exporting events from Cased allows you to provide users with exports of their own data or to respond to data requests.
228
335
 
@@ -240,7 +347,7 @@ export = Cased.policy.exports.create(
240
347
  export.download_url # => https://api.cased.com/exports/export_1dSHQSNtAH90KA8zGTooMnmMdiD/download?token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlcl8xZFFwWThiQmdFd2RwbWRwVnJydER6TVg0ZkgiLCJ
241
348
  ```
242
349
 
243
- ### Masking & filtering sensitive information
350
+ #### Masking & filtering sensitive information
244
351
 
245
352
  If you are handling sensitive information on behalf of your users you should consider masking or filtering any sensitive information.
246
353
 
@@ -257,7 +364,7 @@ Cased.publish(
257
364
  )
258
365
  ```
259
366
 
260
- ### Console Usage
367
+ #### Console Usage
261
368
 
262
369
  Most Cased events will be created by users from actions on the website from custom defined events or lifecycle callbacks. The exception is any console session where models may generate Cased events as you start to modify records.
263
370
 
@@ -268,7 +375,7 @@ By default any console session will include the hostname of where the console se
268
375
  Cased.context.push(actor: @actor)
269
376
  ```
270
377
 
271
- ### Disable publishing events
378
+ #### Disable publishing events
272
379
 
273
380
  Although rare, there may be times where you wish to disable publishing events to Cased. To do so wrap your transaction inside of a `Cased.disable` block:
274
381
 
@@ -284,7 +391,7 @@ Or you can configure the entire process to disable publishing events.
284
391
  CASED_DISABLE_PUBLISHING=1 bundle exec ruby crawl.rb
285
392
  ```
286
393
 
287
- ### Context
394
+ #### Context
288
395
 
289
396
  One of the most easiest ways to publish detailed events to Cased is to push contextual information on to the Cased context.
290
397
 
@@ -339,7 +446,7 @@ To clear/reset the context:
339
446
  Cased.context.clear
340
447
  ```
341
448
 
342
- ### Testing
449
+ #### Testing
343
450
 
344
451
  cased-ruby provides a test helper class that you can use to test events are being published to Cased.
345
452
 
@@ -390,7 +497,7 @@ class CreditCardTest < Test::Unit::TestCase
390
497
  end
391
498
  ```
392
499
 
393
- ## Customizing cased-ruby
500
+ ### Customizing cased-ruby
394
501
 
395
502
  Out of the box cased-ruby takes care of serializing objects for you to the best of its ability, but you can customize cased-ruby should you like to fit your products needs.
396
503
 
@@ -11,6 +11,7 @@ module Cased
11
11
 
12
12
  attr_accessor :width
13
13
  attr_accessor :height
14
+ attr_reader :command
14
15
  attr_reader :stream
15
16
  attr_reader :started_at
16
17
  attr_reader :finished_at
@@ -51,6 +52,7 @@ module Cased
51
52
  },
52
53
  'width' => width,
53
54
  'height' => height,
55
+ 'command' => command.join(' '),
54
56
  }.tap do |h|
55
57
  if started_at
56
58
  h['timestamp'] = started_at.to_i
@@ -9,8 +9,8 @@ module Cased
9
9
  attr_reader :credentials_path
10
10
  attr_writer :token
11
11
 
12
- def initialize
13
- @token = Cased.config.guard_user_token
12
+ def initialize(token: nil)
13
+ @token = token || Cased.config.guard_user_token
14
14
  @directory = Pathname.new(File.expand_path('~/.cguard'))
15
15
  @credentials_path = @directory.join('credentials')
16
16
  end
@@ -6,6 +6,7 @@ module Cased
6
6
  module CLI
7
7
  class Recorder
8
8
  KEY = 'CASED_CLI_RECORDING'
9
+ TRUE = '1'
9
10
 
10
11
  attr_reader :command
11
12
  attr_reader :events
@@ -17,7 +18,7 @@ module Cased
17
18
 
18
19
  # @return [Boolean] if CLI session is being recorded.
19
20
  def self.recording?
20
- ENV[KEY] == '1'
21
+ ENV[KEY] == TRUE
21
22
  end
22
23
 
23
24
  def initialize(command, env: {})
@@ -27,10 +28,10 @@ module Cased
27
28
  @height = Subprocess.check_output(%w[tput lines]).strip.to_i
28
29
 
29
30
  subprocess_env = ENV.to_h.dup
30
- subprocess_env[KEY] = '1'
31
+ subprocess_env[KEY] = TRUE
31
32
  subprocess_env.merge!(env)
32
33
  @writer = Cased::CLI::Asciinema::Writer.new(
33
- command: command.join(' '),
34
+ command: command,
34
35
  width: width,
35
36
  height: height,
36
37
  )
@@ -22,9 +22,7 @@ module Cased
22
22
  # If we're inside of a recorded session we can lookup the session
23
23
  # we're in.
24
24
  def self.current
25
- return @current if defined?(@current)
26
-
27
- @current = if ENV['GUARD_SESSION_ID']
25
+ @current ||= if ENV['GUARD_SESSION_ID']
28
26
  Cased::CLI::Session.find(ENV['GUARD_SESSION_ID'])
29
27
  end
30
28
  end
@@ -121,7 +119,7 @@ module Cased
121
119
  def initialize(reason: nil, command: nil, metadata: {}, authentication: nil)
122
120
  @authentication = authentication || Cased::CLI::Authentication.new
123
121
  @reason = reason
124
- @command = command
122
+ @command = command || [$PROGRAM_NAME, *ARGV].join(' ')
125
123
  @metadata = metadata
126
124
  @requester = {}
127
125
  @responder = {}
@@ -201,7 +199,7 @@ module Cased
201
199
  end
202
200
 
203
201
  def record
204
- return unless recordable? && record_output?
202
+ return false unless recordable? && record_output?
205
203
 
206
204
  Cased::CLI::Log.log 'CLI session is now recording'
207
205
 
data/lib/cased/config.rb CHANGED
@@ -26,6 +26,19 @@ module Cased
26
26
  # end
27
27
  attr_reader :http_read_timeout
28
28
 
29
+ # The Cased HTTP URL. Defaults to https://app.cased.com
30
+ #
31
+ # @example
32
+ # CASED_URL="https://app.cased.com" rails server
33
+ #
34
+ # @example
35
+ # Cased.configure do |config|
36
+ # config.url = "https://app.cased.com"
37
+ # end
38
+ #
39
+ # @return [String]
40
+ attr_accessor :url
41
+
29
42
  # The Cased HTTP API URL. Defaults to https://api.cased.com
30
43
  #
31
44
  # @example
@@ -62,7 +75,7 @@ module Cased
62
75
  # Cased.configure do |config|
63
76
  # config.guard_deny_if_unreachable = true
64
77
  # end
65
- attr_accessor :guard_deny_if_unreachable
78
+ attr_reader :guard_deny_if_unreachable
66
79
 
67
80
  # The URL to publish audit events to. Defaults to https://publish.cased.com
68
81
  #
@@ -140,11 +153,12 @@ module Cased
140
153
  @http_read_timeout = ENV.fetch('CASED_HTTP_READ_TIMEOUT', 10).to_i
141
154
  @http_open_timeout = ENV.fetch('CASED_HTTP_OPEN_TIMEOUT', 5).to_i
142
155
  @raise_on_errors = !ENV['CASED_RAISE_ON_ERRORS'].nil?
156
+ @url = ENV.fetch('CASED_URL', 'https://app.cased.com')
143
157
  @api_url = ENV.fetch('CASED_API_URL', 'https://api.cased.com')
144
158
  @publish_url = ENV.fetch('CASED_PUBLISH_URL', 'https://publish.cased.com')
145
159
  @guard_application_key = ENV['GUARD_APPLICATION_KEY']
146
160
  @guard_user_token = ENV['GUARD_USER_TOKEN']
147
- @guard_deny_if_unreachable = parse_bool(ENV['DENY_IF_UNREACHABLE'])
161
+ self.guard_deny_if_unreachable = ENV['DENY_IF_UNREACHABLE']
148
162
  @publish_key = ENV['CASED_PUBLISH_KEY']
149
163
  @silence = !ENV['CASED_SILENCE'].nil?
150
164
  @policy_keys = Hash.new do |hash, key|
@@ -199,6 +213,10 @@ module Cased
199
213
  @silence || !ENV['CASED_SILENCE'].nil?
200
214
  end
201
215
 
216
+ def guard_deny_if_unreachable=(value)
217
+ @guard_deny_if_unreachable = parse_bool(value)
218
+ end
219
+
202
220
  def guard_deny_if_unreachable?
203
221
  @guard_deny_if_unreachable
204
222
  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.0'
4
+ VERSION = '0.4.1'
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.0
4
+ version: 0.4.1
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-02 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport