oso-cloud 1.3.0.dev.7 → 1.4.0.dev.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/oso/api.rb +51 -12
- data/lib/oso/oso.rb +4 -2
- data/lib/oso/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bccf4bc9bf1950fba9c250563971c55f3f2be4299677adf9fb1eeadedc5b6e90
|
4
|
+
data.tar.gz: 56572baaeafefc78940e4c3c688e2d7d8dc71cf81ad91246ab89f237a9925f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
-
|
404
|
-
|
405
|
-
|
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
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
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
|
-
|
450
|
-
|
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
|
-
|
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