oso-cloud 1.3.0.dev.7 → 1.4.0.dev.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 844583229037d7124d91b588abfbef062026c934d5cd1dcd0e4892a6d539b969
4
- data.tar.gz: 889f910639d097b5c5e29fa64e36959a7c7aebbe7ffe48dfa080f8bbef119015
3
+ metadata.gz: bccf4bc9bf1950fba9c250563971c55f3f2be4299677adf9fb1eeadedc5b6e90
4
+ data.tar.gz: 56572baaeafefc78940e4c3c688e2d7d8dc71cf81ad91246ab89f237a9925f50
5
5
  SHA512:
6
- metadata.gz: 77883cfc4f1584d65a31f1d620d239bcb98b70de099320c91590de55b4a39ee8b4aa7d5c80bbe7b94b8f6f16a02aeab6d54efb5aeecb1a289e7f93ac9048e1a8
7
- data.tar.gz: ecd8b9f6377a4465b9cc39622d35da59a548229ab6df9edc212859e0f282041a812644c02f4cc9e25065e047e805d1fd594b69f5adeb9b40e4e0a4ddab5711a2
6
+ metadata.gz: 6c3d2b3bcfaff463c156bb2b50341a2350e81d39264d2bcac50fd917f849208f8ba5eb8a5b7335f18bad3604d6d57bb9b12305d10ca4126fa07ecf94e6741a7f
7
+ data.tar.gz: d0025b3196aadf1dc3d04ca8a7a8cbce61d31fd6ba18b2dd8ec9ab3b185542c668c985e7ab8545697a86ec9d32c22afacdad97c65dcfcc8b7c738f4b959ab3ea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-cloud (1.3.0.dev.6)
4
+ oso-cloud (1.4.0.dev.0)
5
5
  faraday (~> 2.5.2)
6
6
  faraday-net_http_persistent (~> 2.0)
7
7
  faraday-retry (~> 2.0.0)
@@ -29,7 +29,7 @@ GEM
29
29
  faraday-typhoeus (1.0.0)
30
30
  faraday (~> 2.0)
31
31
  typhoeus (~> 1.4)
32
- ffi (1.16.2)
32
+ ffi (1.16.3)
33
33
  interception (0.5)
34
34
  method_source (1.0.0)
35
35
  minitest (5.18.0)
data/lib/oso/api.rb CHANGED
@@ -273,11 +273,28 @@ module OsoCloud
273
273
  @url = url
274
274
  @connection = get_connection(options: options)
275
275
  @parallel_connection = get_connection(options: { parallel_adapter: true, max_concurrency: options[:max_concurrency] })
276
+
277
+ if options && options[:fallback_url]
278
+ @fallback_connection = Faraday.new(url: options[:fallback_url]) do |faraday|
279
+ faraday.request :json
280
+ faraday.response :json, parser_options: { symbolize_names: true }
281
+ faraday.response :raise_error
282
+ faraday.adapter :net_http
283
+ end
284
+ end
276
285
  @api_key = api_key
277
286
  @user_agent = "Oso Cloud (ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}; rv:#{VERSION})"
278
287
  @last_offset = nil
279
288
  end
280
289
 
290
+ def fallback_eligible(path)
291
+ !@fallback_connection.nil? && ['/authorize',
292
+ '/authorize_resources',
293
+ '/list',
294
+ '/actions',
295
+ '/query'].include?(path)
296
+ end
297
+
281
298
  def get_policy
282
299
  url = '/policy'
283
300
  result = GET(url, nil)
@@ -400,11 +417,21 @@ module OsoCloud
400
417
  end
401
418
 
402
419
  def GET(path, params)
403
- response = @connection.get("api#{path}") do |req|
404
- req.params = params unless params.nil?
405
- req.headers = headers
420
+ begin
421
+ response = @connection.get("api#{path}") do |req|
422
+ req.params = params unless params.nil?
423
+ req.headers = headers
424
+ end
425
+ response.body
426
+ rescue Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError => e
427
+ raise e unless fallback_eligible(path)
428
+
429
+ response = @fallback_connection.get("api#{path}") do |req|
430
+ req.params = params unless params.nil?
431
+ req.headers = headers
432
+ end
433
+ response.body
406
434
  end
407
- response.body
408
435
  rescue Faraday::Error => e
409
436
  handle_faraday_error e
410
437
  end
@@ -440,16 +467,28 @@ module OsoCloud
440
467
  end
441
468
 
442
469
  def POST(path, params, body, isMutation)
443
- response = @connection.post("api#{path}") do |req|
444
- req.params = params unless params.nil?
445
- req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
446
- req.headers = headers
447
- end
470
+ begin
471
+ response = @connection.post("api#{path}") do |req|
472
+ req.params = params unless params.nil?
473
+ req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
474
+ req.headers = headers
475
+ end
448
476
 
449
- if isMutation
450
- @last_offset = response.headers[:OsoOffset]
477
+ if isMutation
478
+ @last_offset = response.headers[:OsoOffset]
479
+ end
480
+ response.body
481
+ # only attempt fallback on 5xx, and connection failure conditions
482
+ rescue Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError => e
483
+ raise e unless fallback_eligible(path)
484
+
485
+ response = @fallback_connection.post("api#{path}") do |req|
486
+ req.params = params unless params.nil?
487
+ req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
488
+ req.headers = headers
489
+ end
490
+ response.body
451
491
  end
452
- response.body
453
492
  rescue Faraday::Error => e
454
493
  handle_faraday_error e
455
494
  end
data/lib/oso/oso.rb CHANGED
@@ -28,8 +28,10 @@ module OsoCloud
28
28
  # Any other elements in the array, which together represent the fact's arguments,
29
29
  # can be "OsoCloud::Value" objects or strings.
30
30
  class Oso
31
- def initialize(url: 'https://cloud.osohq.com', api_key: nil, options: nil)
32
- @api = OsoCloud::Core::Api.new(url: url, api_key: api_key, options: options || {})
31
+ def initialize(url: 'https://cloud.osohq.com', api_key: nil, options: nil, fallback_url: nil)
32
+ options ||= {}
33
+ options[:fallback_url] = fallback_url unless fallback_url.nil?
34
+ @api = OsoCloud::Core::Api.new(url: url, api_key: api_key, options: options)
33
35
  end
34
36
 
35
37
  # Update the active policy
data/lib/oso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OsoCloud
2
- VERSION = '1.3.0.dev.7'.freeze
2
+ VERSION = '1.4.0.dev.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.dev.7
4
+ version: 1.4.0.dev.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oso Security, Inc.