cased-ruby 0.3.3 → 0.4.0

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +20 -15
  3. data/README.md +14 -41
  4. data/bin/cli +14 -0
  5. data/cased-ruby.gemspec +2 -0
  6. data/lib/cased.rb +1 -0
  7. data/lib/cased/cli.rb +13 -0
  8. data/lib/cased/cli/asciinema/file.rb +108 -0
  9. data/lib/cased/cli/asciinema/writer.rb +67 -0
  10. data/lib/cased/cli/authentication.rb +31 -0
  11. data/lib/cased/cli/identity.rb +38 -0
  12. data/lib/cased/cli/interactive_session.rb +84 -0
  13. data/lib/cased/cli/log.rb +25 -0
  14. data/lib/cased/cli/recorder.rb +57 -0
  15. data/lib/cased/cli/session.rb +278 -0
  16. data/lib/cased/clients.rb +7 -3
  17. data/lib/cased/config.rb +40 -0
  18. data/lib/cased/http/client.rb +13 -6
  19. data/lib/cased/http/error.rb +5 -2
  20. data/lib/cased/query.rb +6 -3
  21. data/lib/cased/version.rb +1 -1
  22. data/vendor/cache/activesupport-6.1.3.gem +0 -0
  23. data/vendor/cache/concurrent-ruby-1.1.8.gem +0 -0
  24. data/vendor/cache/faraday-1.3.0.gem +0 -0
  25. data/vendor/cache/faraday-net_http-1.0.1.gem +0 -0
  26. data/vendor/cache/i18n-1.8.9.gem +0 -0
  27. data/vendor/cache/json-2.5.1.gem +0 -0
  28. data/vendor/cache/jwt-2.2.2.gem +0 -0
  29. data/vendor/cache/ruby2_keywords-0.0.4.gem +0 -0
  30. data/vendor/cache/subprocess-1.5.4.gem +0 -0
  31. data/vendor/cache/tzinfo-2.0.4.gem +0 -0
  32. data/vendor/cache/zeitwerk-2.4.2.gem +0 -0
  33. metadata +51 -11
  34. data/vendor/cache/activesupport-6.0.3.4.gem +0 -0
  35. data/vendor/cache/concurrent-ruby-1.1.7.gem +0 -0
  36. data/vendor/cache/faraday-1.1.0.gem +0 -0
  37. data/vendor/cache/i18n-1.8.5.gem +0 -0
  38. data/vendor/cache/json-2.3.1.gem +0 -0
  39. data/vendor/cache/ruby2_keywords-0.0.2.gem +0 -0
  40. data/vendor/cache/thread_safe-0.3.6.gem +0 -0
  41. data/vendor/cache/tzinfo-1.2.7.gem +0 -0
  42. 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
@@ -37,6 +37,33 @@ module Cased
37
37
  # end
38
38
  attr_accessor :api_url
39
39
 
40
+ # @example
41
+ # GUARD_APPLICATION_KEY="guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH" rails server
42
+ #
43
+ # @example
44
+ # Cased.configure do |config|
45
+ # config.guard_application_key = "guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH"
46
+ # end
47
+ attr_accessor :guard_application_key
48
+
49
+ # @example
50
+ # GUARD_USER_TOKEN="user_1oFqlROLNRGVLOXJSsHkJiVmylr" rails server
51
+ #
52
+ # @example
53
+ # Cased.configure do |config|
54
+ # config.guard_user_token = "user_1oFqlROLNRGVLOXJSsHkJiVmylr"
55
+ # end
56
+ attr_accessor :guard_user_token
57
+
58
+ # @example
59
+ # DENY_IF_UNREACHABLE="1" rails server
60
+ #
61
+ # @example
62
+ # Cased.configure do |config|
63
+ # config.guard_deny_if_unreachable = true
64
+ # end
65
+ attr_accessor :guard_deny_if_unreachable
66
+
40
67
  # The URL to publish audit events to. Defaults to https://publish.cased.com
41
68
  #
42
69
  # @example
@@ -115,6 +142,9 @@ module Cased
115
142
  @raise_on_errors = !ENV['CASED_RAISE_ON_ERRORS'].nil?
116
143
  @api_url = ENV.fetch('CASED_API_URL', 'https://api.cased.com')
117
144
  @publish_url = ENV.fetch('CASED_PUBLISH_URL', 'https://publish.cased.com')
145
+ @guard_application_key = ENV['GUARD_APPLICATION_KEY']
146
+ @guard_user_token = ENV['GUARD_USER_TOKEN']
147
+ @guard_deny_if_unreachable = parse_bool(ENV['DENY_IF_UNREACHABLE'])
118
148
  @publish_key = ENV['CASED_PUBLISH_KEY']
119
149
  @silence = !ENV['CASED_SILENCE'].nil?
120
150
  @policy_keys = Hash.new do |hash, key|
@@ -168,5 +198,15 @@ module Cased
168
198
  def silence?
169
199
  @silence || !ENV['CASED_SILENCE'].nil?
170
200
  end
201
+
202
+ def guard_deny_if_unreachable?
203
+ @guard_deny_if_unreachable
204
+ end
205
+
206
+ private
207
+
208
+ def parse_bool(val)
209
+ %w[1 true t].include?(val&.downcase)
210
+ end
171
211
  end
172
212
  end
@@ -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
- @client = Faraday.new(url: url) do |conn|
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'
@@ -72,11 +73,17 @@ module Cased
72
73
 
73
74
  def request(method, url = nil, params_or_body = nil, headers = nil, &block)
74
75
  response = @client.send(method, url, params_or_body, headers, &block)
75
- return response if response.success?
76
76
 
77
- # TODO: Look to return a Cased::Response here with error wrapped.
78
- klass = Cased::HTTP::Error.class_from_response(response)
79
- raise klass.from_response(response)
77
+ if !response.success? && raise_on_errors?
78
+ klass = Cased::HTTP::Error.class_from_response(response)
79
+ raise klass.from_response(response)
80
+ else
81
+ response
82
+ end
83
+ end
84
+
85
+ def raise_on_errors?
86
+ @raise_on_errors
80
87
  end
81
88
  end
82
89
  end
@@ -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(message = '', code = nil)
11
- super(message)
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
- delegate :results, \
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cased
4
- VERSION = '0.3.3'
4
+ VERSION = '0.4.0'
5
5
  end
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.3.3
4
+ version: 0.4.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: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2021-03-02 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.0.3.4.gem
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.7.gem
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.1.0.gem
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.5.gem
359
+ - vendor/cache/i18n-1.8.9.gem
321
360
  - vendor/cache/jaro_winkler-1.5.4.gem
322
- - vendor/cache/json-2.3.1.gem
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.2.gem
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/thread_safe-0.3.6.gem
344
- - vendor/cache/tzinfo-1.2.7.gem
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.0.gem
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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file