cased-ruby 0.3.3 → 0.4.4
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 +4 -4
- data/Gemfile.lock +20 -15
- data/README.md +135 -54
- data/bin/cli +14 -0
- data/cased-ruby.gemspec +2 -0
- data/lib/cased.rb +1 -0
- data/lib/cased/cli.rb +13 -0
- data/lib/cased/cli/asciinema/file.rb +108 -0
- data/lib/cased/cli/asciinema/writer.rb +69 -0
- data/lib/cased/cli/authentication.rb +31 -0
- data/lib/cased/cli/identity.rb +43 -0
- data/lib/cased/cli/interactive_session.rb +121 -0
- data/lib/cased/cli/log.rb +27 -0
- data/lib/cased/cli/recorder.rb +58 -0
- data/lib/cased/cli/session.rb +292 -0
- data/lib/cased/clients.rb +7 -3
- data/lib/cased/config.rb +58 -0
- data/lib/cased/http/client.rb +13 -8
- data/lib/cased/http/error.rb +5 -2
- data/lib/cased/query.rb +6 -3
- data/lib/cased/version.rb +1 -1
- data/vendor/cache/activesupport-6.1.3.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.1.8.gem +0 -0
- data/vendor/cache/faraday-1.3.0.gem +0 -0
- data/vendor/cache/faraday-net_http-1.0.1.gem +0 -0
- data/vendor/cache/i18n-1.8.9.gem +0 -0
- data/vendor/cache/json-2.5.1.gem +0 -0
- data/vendor/cache/jwt-2.2.2.gem +0 -0
- data/vendor/cache/ruby2_keywords-0.0.4.gem +0 -0
- data/vendor/cache/subprocess-1.5.4.gem +0 -0
- data/vendor/cache/tzinfo-2.0.4.gem +0 -0
- data/vendor/cache/zeitwerk-2.4.2.gem +0 -0
- metadata +51 -11
- data/vendor/cache/activesupport-6.0.3.4.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.1.7.gem +0 -0
- data/vendor/cache/faraday-1.1.0.gem +0 -0
- data/vendor/cache/i18n-1.8.5.gem +0 -0
- data/vendor/cache/json-2.3.1.gem +0 -0
- data/vendor/cache/ruby2_keywords-0.0.2.gem +0 -0
- data/vendor/cache/thread_safe-0.3.6.gem +0 -0
- data/vendor/cache/tzinfo-1.2.7.gem +0 -0
- data/vendor/cache/zeitwerk-2.4.0.gem +0 -0
data/lib/cased/clients.rb
CHANGED
@@ -4,10 +4,10 @@ require 'cased/http/client'
|
|
4
4
|
|
5
5
|
module Cased
|
6
6
|
class Clients
|
7
|
-
def self.create(api_key:, url: nil)
|
7
|
+
def self.create(api_key:, url: nil, raise_on_errors: false)
|
8
8
|
url ||= Cased.config.api_url
|
9
9
|
|
10
|
-
Cased::HTTP::Client.new(url: url, api_key: api_key)
|
10
|
+
Cased::HTTP::Client.new(url: url, api_key: api_key, raise_on_errors: raise_on_errors)
|
11
11
|
end
|
12
12
|
|
13
13
|
def organization
|
@@ -15,7 +15,11 @@ module Cased
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def publish
|
18
|
-
@publish ||= self.class.create(url: Cased.config.publish_url, api_key: Cased.config.publish_key)
|
18
|
+
@publish ||= self.class.create(url: Cased.config.publish_url, api_key: Cased.config.publish_key, raise_on_errors: true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def cli
|
22
|
+
@cli ||= self.class.create(api_key: Cased.config.guard_application_key)
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
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
|
@@ -37,6 +50,33 @@ module Cased
|
|
37
50
|
# end
|
38
51
|
attr_accessor :api_url
|
39
52
|
|
53
|
+
# @example
|
54
|
+
# GUARD_APPLICATION_KEY="guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH" rails server
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# Cased.configure do |config|
|
58
|
+
# config.guard_application_key = "guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH"
|
59
|
+
# end
|
60
|
+
attr_accessor :guard_application_key
|
61
|
+
|
62
|
+
# @example
|
63
|
+
# GUARD_USER_TOKEN="user_1oFqlROLNRGVLOXJSsHkJiVmylr" rails server
|
64
|
+
#
|
65
|
+
# @example
|
66
|
+
# Cased.configure do |config|
|
67
|
+
# config.guard_user_token = "user_1oFqlROLNRGVLOXJSsHkJiVmylr"
|
68
|
+
# end
|
69
|
+
attr_accessor :guard_user_token
|
70
|
+
|
71
|
+
# @example
|
72
|
+
# DENY_IF_UNREACHABLE="1" rails server
|
73
|
+
#
|
74
|
+
# @example
|
75
|
+
# Cased.configure do |config|
|
76
|
+
# config.guard_deny_if_unreachable = true
|
77
|
+
# end
|
78
|
+
attr_reader :guard_deny_if_unreachable
|
79
|
+
|
40
80
|
# The URL to publish audit events to. Defaults to https://publish.cased.com
|
41
81
|
#
|
42
82
|
# @example
|
@@ -113,8 +153,12 @@ module Cased
|
|
113
153
|
@http_read_timeout = ENV.fetch('CASED_HTTP_READ_TIMEOUT', 10).to_i
|
114
154
|
@http_open_timeout = ENV.fetch('CASED_HTTP_OPEN_TIMEOUT', 5).to_i
|
115
155
|
@raise_on_errors = !ENV['CASED_RAISE_ON_ERRORS'].nil?
|
156
|
+
@url = ENV.fetch('CASED_URL', 'https://app.cased.com')
|
116
157
|
@api_url = ENV.fetch('CASED_API_URL', 'https://api.cased.com')
|
117
158
|
@publish_url = ENV.fetch('CASED_PUBLISH_URL', 'https://publish.cased.com')
|
159
|
+
@guard_application_key = ENV['GUARD_APPLICATION_KEY']
|
160
|
+
@guard_user_token = ENV['GUARD_USER_TOKEN']
|
161
|
+
self.guard_deny_if_unreachable = ENV['DENY_IF_UNREACHABLE']
|
118
162
|
@publish_key = ENV['CASED_PUBLISH_KEY']
|
119
163
|
@silence = !ENV['CASED_SILENCE'].nil?
|
120
164
|
@policy_keys = Hash.new do |hash, key|
|
@@ -168,5 +212,19 @@ module Cased
|
|
168
212
|
def silence?
|
169
213
|
@silence || !ENV['CASED_SILENCE'].nil?
|
170
214
|
end
|
215
|
+
|
216
|
+
def guard_deny_if_unreachable=(value)
|
217
|
+
@guard_deny_if_unreachable = parse_bool(value)
|
218
|
+
end
|
219
|
+
|
220
|
+
def guard_deny_if_unreachable?
|
221
|
+
@guard_deny_if_unreachable
|
222
|
+
end
|
223
|
+
|
224
|
+
private
|
225
|
+
|
226
|
+
def parse_bool(val)
|
227
|
+
%w[1 true t].include?(val&.downcase)
|
228
|
+
end
|
171
229
|
end
|
172
230
|
end
|
data/lib/cased/http/client.rb
CHANGED
@@ -7,8 +7,9 @@ require 'faraday_middleware'
|
|
7
7
|
module Cased
|
8
8
|
module HTTP
|
9
9
|
class Client
|
10
|
-
def initialize(url:, api_key:)
|
11
|
-
@
|
10
|
+
def initialize(url:, api_key:, raise_on_errors: false)
|
11
|
+
@raise_on_errors = raise_on_errors
|
12
|
+
@client = ::Faraday.new(url: url) do |conn|
|
12
13
|
conn.headers[:user_agent] = "cased-ruby/v#{Cased::VERSION}"
|
13
14
|
conn.headers[:content_type] = 'application/json'
|
14
15
|
conn.headers[:accept] = 'application/json'
|
@@ -19,8 +20,6 @@ module Cased
|
|
19
20
|
|
20
21
|
conn.options.timeout = Cased.config.http_read_timeout
|
21
22
|
conn.options.open_timeout = Cased.config.http_open_timeout
|
22
|
-
|
23
|
-
conn.adapter :net_http_persistent
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -72,11 +71,17 @@ module Cased
|
|
72
71
|
|
73
72
|
def request(method, url = nil, params_or_body = nil, headers = nil, &block)
|
74
73
|
response = @client.send(method, url, params_or_body, headers, &block)
|
75
|
-
return response if response.success?
|
76
74
|
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
if !response.success? && raise_on_errors?
|
76
|
+
klass = Cased::HTTP::Error.class_from_response(response)
|
77
|
+
raise klass.from_response(response)
|
78
|
+
else
|
79
|
+
response
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def raise_on_errors?
|
84
|
+
@raise_on_errors
|
80
85
|
end
|
81
86
|
end
|
82
87
|
end
|
data/lib/cased/http/error.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'cased/error'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
module Cased
|
6
7
|
module HTTP
|
7
8
|
class Error < Cased::Error
|
8
9
|
attr_reader :code
|
10
|
+
attr_reader :json
|
9
11
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
+
def initialize(json = {}, code = nil)
|
13
|
+
@json = json
|
12
14
|
@code = code
|
15
|
+
super(JSON.dump(@json))
|
13
16
|
end
|
14
17
|
|
15
18
|
def self.from_response(response)
|
data/lib/cased/query.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'cased/collection_response'
|
4
|
+
require 'forwardable'
|
4
5
|
|
5
6
|
module Cased
|
6
7
|
class Query
|
8
|
+
extend Forwardable
|
9
|
+
|
7
10
|
# @param client [Cased::HTTP::Client] the HTTP client authorized to query an
|
8
11
|
# audit trail policy
|
9
12
|
# @param phrase [String, nil] the phrase to search for audit trail events
|
@@ -43,7 +46,8 @@ module Cased
|
|
43
46
|
end
|
44
47
|
|
45
48
|
# If any of these methods are called we need the request to fulfil the response.
|
46
|
-
|
49
|
+
def_delegators :response, \
|
50
|
+
:results, \
|
47
51
|
:total_count, \
|
48
52
|
:total_pages, \
|
49
53
|
:next_page_url?, \
|
@@ -64,8 +68,7 @@ module Cased
|
|
64
68
|
:last_page?, \
|
65
69
|
:error, \
|
66
70
|
:error?, \
|
67
|
-
:success
|
68
|
-
to: :response
|
71
|
+
:success?
|
69
72
|
|
70
73
|
def response
|
71
74
|
return @response if defined?(@response)
|
data/lib/cased/version.rb
CHANGED
Binary file
|
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
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garrett Bjerkhoel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jwt
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: net-http-persistent
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: subprocess
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.5.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.5.0
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: bundler
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,11 +295,21 @@ files:
|
|
267
295
|
- LICENSE
|
268
296
|
- README.md
|
269
297
|
- Rakefile
|
298
|
+
- bin/cli
|
270
299
|
- bin/console
|
271
300
|
- bin/rubocop
|
272
301
|
- cased-ruby.gemspec
|
273
302
|
- lib/cased-ruby.rb
|
274
303
|
- lib/cased.rb
|
304
|
+
- lib/cased/cli.rb
|
305
|
+
- lib/cased/cli/asciinema/file.rb
|
306
|
+
- lib/cased/cli/asciinema/writer.rb
|
307
|
+
- lib/cased/cli/authentication.rb
|
308
|
+
- lib/cased/cli/identity.rb
|
309
|
+
- lib/cased/cli/interactive_session.rb
|
310
|
+
- lib/cased/cli/log.rb
|
311
|
+
- lib/cased/cli/recorder.rb
|
312
|
+
- lib/cased/cli/session.rb
|
275
313
|
- lib/cased/clients.rb
|
276
314
|
- lib/cased/collection_response.rb
|
277
315
|
- lib/cased/config.rb
|
@@ -305,21 +343,23 @@ files:
|
|
305
343
|
- lib/cased/sensitive/string.rb
|
306
344
|
- lib/cased/test_helper.rb
|
307
345
|
- lib/cased/version.rb
|
308
|
-
- vendor/cache/activesupport-6.
|
346
|
+
- vendor/cache/activesupport-6.1.3.gem
|
309
347
|
- vendor/cache/addressable-2.7.0.gem
|
310
348
|
- vendor/cache/ast-2.4.0.gem
|
311
349
|
- vendor/cache/byebug-11.0.1.gem
|
312
|
-
- vendor/cache/concurrent-ruby-1.1.
|
350
|
+
- vendor/cache/concurrent-ruby-1.1.8.gem
|
313
351
|
- vendor/cache/connection_pool-2.2.2.gem
|
314
352
|
- vendor/cache/crack-0.4.3.gem
|
315
353
|
- vendor/cache/docile-1.3.2.gem
|
316
354
|
- vendor/cache/dotpath-0.1.0.gem
|
317
|
-
- vendor/cache/faraday-1.
|
355
|
+
- vendor/cache/faraday-1.3.0.gem
|
356
|
+
- vendor/cache/faraday-net_http-1.0.1.gem
|
318
357
|
- vendor/cache/faraday_middleware-1.0.0.gem
|
319
358
|
- vendor/cache/hashdiff-1.0.1.gem
|
320
|
-
- vendor/cache/i18n-1.8.
|
359
|
+
- vendor/cache/i18n-1.8.9.gem
|
321
360
|
- vendor/cache/jaro_winkler-1.5.4.gem
|
322
|
-
- vendor/cache/json-2.
|
361
|
+
- vendor/cache/json-2.5.1.gem
|
362
|
+
- vendor/cache/jwt-2.2.2.gem
|
323
363
|
- vendor/cache/minitest-5.13.0.gem
|
324
364
|
- vendor/cache/mocha-1.11.2.gem
|
325
365
|
- vendor/cache/multipart-post-2.1.1.gem
|
@@ -335,17 +375,17 @@ files:
|
|
335
375
|
- vendor/cache/rubocop-0.78.0.gem
|
336
376
|
- vendor/cache/rubocop-performance-1.5.2.gem
|
337
377
|
- vendor/cache/ruby-progressbar-1.10.1.gem
|
338
|
-
- vendor/cache/ruby2_keywords-0.0.
|
378
|
+
- vendor/cache/ruby2_keywords-0.0.4.gem
|
339
379
|
- vendor/cache/safe_yaml-1.0.5.gem
|
340
380
|
- vendor/cache/sidekiq-6.0.7.gem
|
341
381
|
- vendor/cache/simplecov-0.18.5.gem
|
342
382
|
- vendor/cache/simplecov-html-0.12.2.gem
|
343
|
-
- vendor/cache/
|
344
|
-
- vendor/cache/tzinfo-
|
383
|
+
- vendor/cache/subprocess-1.5.4.gem
|
384
|
+
- vendor/cache/tzinfo-2.0.4.gem
|
345
385
|
- vendor/cache/unicode-display_width-1.6.1.gem
|
346
386
|
- vendor/cache/webmock-3.8.3.gem
|
347
387
|
- vendor/cache/yard-0.9.24.gem
|
348
|
-
- vendor/cache/zeitwerk-2.4.
|
388
|
+
- vendor/cache/zeitwerk-2.4.2.gem
|
349
389
|
homepage: https://github.com/cased/cased-ruby
|
350
390
|
licenses:
|
351
391
|
- MIT
|
Binary file
|
Binary file
|
Binary file
|
data/vendor/cache/i18n-1.8.5.gem
DELETED
Binary file
|
data/vendor/cache/json-2.3.1.gem
DELETED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|