cased-ruby 0.4.3 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +0 -16
- data/Gemfile.lock +9 -5
- data/README.md +35 -1
- data/lib/cased/cli/asciinema/file.rb +5 -0
- data/lib/cased/cli/config.rb +21 -0
- data/lib/cased/cli/identity.rb +8 -3
- data/lib/cased/cli/interactive_session.rb +8 -2
- data/lib/cased/cli/session.rb +21 -4
- data/lib/cased/config.rb +13 -0
- data/lib/cased/version.rb +1 -1
- data/vendor/cache/activesupport-6.1.3.1.gem +0 -0
- data/vendor/cache/faraday-1.4.1.gem +0 -0
- data/vendor/cache/faraday-excon-1.1.0.gem +0 -0
- data/vendor/cache/faraday-net_http_persistent-1.1.0.gem +0 -0
- data/vendor/cache/i18n-1.8.10.gem +0 -0
- metadata +8 -5
- data/vendor/cache/activesupport-6.1.3.gem +0 -0
- data/vendor/cache/faraday-1.3.0.gem +0 -0
- data/vendor/cache/i18n-1.8.9.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d2e582beb818f03f7211310ca694248b25aaf28a1ed625c0fa82afafbb4af71
|
4
|
+
data.tar.gz: 85dfd3af819d73e055401b8461d156e990021362b7b3acfa67ea0c690a359a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d5ef3b76f2187d030928d448488560784beb0fad6a462dcd6339e5697874c822bfd1efcd2fca6c7307b95f10d2465761693a1d422baea4e789f84d77bae6a8
|
7
|
+
data.tar.gz: 9969f4cf476784ac3e4747d0053035fd61fd329a425bb5e67f04a64125792c7842f3ddb9fe966920f118825960af1477c1843d8779600c706bea5c3a6a364e2d
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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
|
+
cased-ruby (0.4.8)
|
5
5
|
activesupport (~> 6)
|
6
6
|
dotpath (= 0.1.0)
|
7
7
|
faraday (~> 1.0)
|
@@ -14,7 +14,7 @@ PATH
|
|
14
14
|
GEM
|
15
15
|
remote: https://rubygems.org/
|
16
16
|
specs:
|
17
|
-
activesupport (6.1.3)
|
17
|
+
activesupport (6.1.3.1)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (>= 1.6, < 2)
|
20
20
|
minitest (>= 5.1)
|
@@ -30,15 +30,19 @@ GEM
|
|
30
30
|
safe_yaml (~> 1.0.0)
|
31
31
|
docile (1.3.2)
|
32
32
|
dotpath (0.1.0)
|
33
|
-
faraday (1.
|
33
|
+
faraday (1.4.1)
|
34
|
+
faraday-excon (~> 1.1)
|
34
35
|
faraday-net_http (~> 1.0)
|
36
|
+
faraday-net_http_persistent (~> 1.1)
|
35
37
|
multipart-post (>= 1.2, < 3)
|
36
|
-
ruby2_keywords
|
38
|
+
ruby2_keywords (>= 0.0.4)
|
39
|
+
faraday-excon (1.1.0)
|
37
40
|
faraday-net_http (1.0.1)
|
41
|
+
faraday-net_http_persistent (1.1.0)
|
38
42
|
faraday_middleware (1.0.0)
|
39
43
|
faraday (~> 1.0)
|
40
44
|
hashdiff (1.0.1)
|
41
|
-
i18n (1.8.
|
45
|
+
i18n (1.8.10)
|
42
46
|
concurrent-ruby (~> 1.0)
|
43
47
|
jaro_winkler (1.5.4)
|
44
48
|
json (2.5.1)
|
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
|
|
@@ -135,7 +147,8 @@ end
|
|
135
147
|
|
136
148
|
authentication = Cased::CLI::Authentication.new
|
137
149
|
identity = Cased::CLI::Identity.new
|
138
|
-
|
150
|
+
token, ip_address = identity.identify
|
151
|
+
authentication.token = token
|
139
152
|
|
140
153
|
session = Cased::CLI::Session.new(
|
141
154
|
authentication: authentication,
|
@@ -180,6 +193,27 @@ You no longer need to handle obtaining the user token or asking for a reason up
|
|
180
193
|
front, `Cased::CLI::InteractiveSession` will prompt the user for any reason
|
181
194
|
being required as necessary.
|
182
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
|
+
|
183
217
|
### Audit trails
|
184
218
|
|
185
219
|
#### Publishing events to Cased
|
@@ -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
|
data/lib/cased/cli/identity.rb
CHANGED
@@ -23,15 +23,20 @@ module Cased
|
|
23
23
|
def poll(poll_url)
|
24
24
|
count = 0
|
25
25
|
user_id = nil
|
26
|
+
ip_address = nil
|
26
27
|
|
27
28
|
while user_id.nil?
|
28
29
|
count += 1
|
29
30
|
response = Cased.clients.cli.get(poll_url)
|
30
|
-
|
31
|
-
|
31
|
+
if response.success?
|
32
|
+
user_id = response.body.dig('user', 'id')
|
33
|
+
ip_address = response.body.fetch('ip_address')
|
34
|
+
else
|
35
|
+
sleep 1
|
36
|
+
end
|
32
37
|
end
|
33
38
|
|
34
|
-
user_id
|
39
|
+
[user_id, ip_address]
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
@@ -50,7 +50,9 @@ module Cased
|
|
50
50
|
Cased::CLI::Log.log "You must re-authenticate with Cased due to recent changes to this application's settings."
|
51
51
|
|
52
52
|
identity = Cased::CLI::Identity.new
|
53
|
-
|
53
|
+
token, ip_address = identity.identify
|
54
|
+
session.authentication.token = token
|
55
|
+
session.forwarded_ip_address = ip_address
|
54
56
|
|
55
57
|
create
|
56
58
|
elsif session.unauthorized?
|
@@ -61,7 +63,9 @@ module Cased
|
|
61
63
|
end
|
62
64
|
|
63
65
|
identity = Cased::CLI::Identity.new
|
64
|
-
|
66
|
+
token, ip_address = identity.identify
|
67
|
+
session.authentication.token = token
|
68
|
+
session.forwarded_ip_address = ip_address
|
65
69
|
|
66
70
|
create
|
67
71
|
elsif session.reason_required?
|
@@ -108,8 +112,10 @@ module Cased
|
|
108
112
|
exit 1
|
109
113
|
when 'timed_out'
|
110
114
|
Cased::CLI::Log.log 'CLI session has timed out'
|
115
|
+
exit 1
|
111
116
|
when 'canceled'
|
112
117
|
Cased::CLI::Log.log 'CLI session has been canceled'
|
118
|
+
exit 0
|
113
119
|
end
|
114
120
|
end
|
115
121
|
end
|
data/lib/cased/cli/session.rb
CHANGED
@@ -86,9 +86,17 @@ module Cased
|
|
86
86
|
# @return [String, nil]
|
87
87
|
attr_accessor :reason
|
88
88
|
|
89
|
+
# Public: The forwarded IP V4 or IP V6 address of the user that initiated
|
90
|
+
# the CLI session.
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# session.forwarded_ip_address #=> "1.1.1.1"
|
94
|
+
# @return [String, nil]
|
95
|
+
attr_accessor :forwarded_ip_address
|
96
|
+
|
89
97
|
# Public: The client's IP V4 or IP V6 address that initiated the CLI session.
|
90
98
|
# @example
|
91
|
-
# session.
|
99
|
+
# session.ip_address #=> "1.1.1.1"
|
92
100
|
# @return [String, nil]
|
93
101
|
attr_reader :ip_address
|
94
102
|
|
@@ -116,11 +124,18 @@ module Cased
|
|
116
124
|
# @return [Hash, nil]
|
117
125
|
attr_reader :guard_application
|
118
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
|
+
|
119
133
|
def initialize(reason: nil, command: nil, metadata: {}, authentication: nil)
|
120
134
|
@authentication = authentication || Cased::CLI::Authentication.new
|
121
135
|
@reason = reason
|
122
|
-
@
|
123
|
-
@
|
136
|
+
@original_command = command || [$PROGRAM_NAME, *ARGV].join(' ')
|
137
|
+
@command = @original_command
|
138
|
+
@metadata = Cased.config.cli.metadata.merge(metadata)
|
124
139
|
@requester = {}
|
125
140
|
@responder = {}
|
126
141
|
@guard_application = {}
|
@@ -144,6 +159,7 @@ module Cased
|
|
144
159
|
@command = session.fetch('command')
|
145
160
|
@metadata = session.fetch('metadata')
|
146
161
|
@reason = session.fetch('reason')
|
162
|
+
@forwarded_ip_address = session.fetch('forwarded_ip_address')
|
147
163
|
@ip_address = session.fetch('ip_address')
|
148
164
|
@requester = session.fetch('requester')
|
149
165
|
@responded_at = session['responded_at']
|
@@ -207,7 +223,7 @@ module Cased
|
|
207
223
|
|
208
224
|
Cased::CLI::Log.log 'CLI session is now recording'
|
209
225
|
|
210
|
-
recorder = Cased::CLI::Recorder.new(
|
226
|
+
recorder = Cased::CLI::Recorder.new(original_command.split(' '), env: {
|
211
227
|
'GUARD_SESSION_ID' => id,
|
212
228
|
'GUARD_APPLICATION_ID' => guard_application.fetch('id'),
|
213
229
|
'GUARD_USER_TOKEN' => requester.fetch('id'),
|
@@ -226,6 +242,7 @@ module Cased
|
|
226
242
|
|
227
243
|
response = Cased.clients.cli.post('cli/sessions',
|
228
244
|
user_token: authentication.token,
|
245
|
+
forwarded_ip_address: forwarded_ip_address,
|
229
246
|
reason: reason,
|
230
247
|
metadata: metadata,
|
231
248
|
command: command)
|
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.
|
data/lib/cased/version.rb
CHANGED
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
|
+
version: 0.4.8
|
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-
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -305,6 +305,7 @@ files:
|
|
305
305
|
- lib/cased/cli/asciinema/file.rb
|
306
306
|
- lib/cased/cli/asciinema/writer.rb
|
307
307
|
- lib/cased/cli/authentication.rb
|
308
|
+
- lib/cased/cli/config.rb
|
308
309
|
- lib/cased/cli/identity.rb
|
309
310
|
- lib/cased/cli/interactive_session.rb
|
310
311
|
- lib/cased/cli/log.rb
|
@@ -343,7 +344,7 @@ files:
|
|
343
344
|
- lib/cased/sensitive/string.rb
|
344
345
|
- lib/cased/test_helper.rb
|
345
346
|
- lib/cased/version.rb
|
346
|
-
- vendor/cache/activesupport-6.1.3.gem
|
347
|
+
- vendor/cache/activesupport-6.1.3.1.gem
|
347
348
|
- vendor/cache/addressable-2.7.0.gem
|
348
349
|
- vendor/cache/ast-2.4.0.gem
|
349
350
|
- vendor/cache/byebug-11.0.1.gem
|
@@ -352,11 +353,13 @@ files:
|
|
352
353
|
- vendor/cache/crack-0.4.3.gem
|
353
354
|
- vendor/cache/docile-1.3.2.gem
|
354
355
|
- vendor/cache/dotpath-0.1.0.gem
|
355
|
-
- vendor/cache/faraday-1.
|
356
|
+
- vendor/cache/faraday-1.4.1.gem
|
357
|
+
- vendor/cache/faraday-excon-1.1.0.gem
|
356
358
|
- vendor/cache/faraday-net_http-1.0.1.gem
|
359
|
+
- vendor/cache/faraday-net_http_persistent-1.1.0.gem
|
357
360
|
- vendor/cache/faraday_middleware-1.0.0.gem
|
358
361
|
- vendor/cache/hashdiff-1.0.1.gem
|
359
|
-
- vendor/cache/i18n-1.8.
|
362
|
+
- vendor/cache/i18n-1.8.10.gem
|
360
363
|
- vendor/cache/jaro_winkler-1.5.4.gem
|
361
364
|
- vendor/cache/json-2.5.1.gem
|
362
365
|
- vendor/cache/jwt-2.2.2.gem
|
Binary file
|
Binary file
|
data/vendor/cache/i18n-1.8.9.gem
DELETED
Binary file
|