oso-cloud 1.7.1 → 1.8.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 +1 -1
- data/lib/oso/api.rb +55 -28
- data/lib/oso/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3ca5a542cd09609eab342416030091943a7e777e6fdccd8b6caf1b1b6a5a99
|
4
|
+
data.tar.gz: 34c40e85594b08ef91ead85505c1488d42fc1291bcf1f3583dacce49abb47446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e950c324bbb312688fe5b2e119d761fb5e7189ac087386ef232d632b1179d7ad2db0a3f7c63ea468088fd3a4d1b4953d4837f8462b6582bb3f09f4c0ed93eb9e
|
7
|
+
data.tar.gz: 24bed9cfb7b77c0fa77867166188e55e2811e63c5ed0fedb111d013338b8a8fdd59c0edf084169ad58d11c1988f4fb53a0e14d882aa8d827a195afc12f1129e7
|
data/Gemfile.lock
CHANGED
data/lib/oso/api.rb
CHANGED
@@ -80,10 +80,10 @@ module OsoCloud
|
|
80
80
|
|
81
81
|
def initialize(metadata:)
|
82
82
|
@metadata = if metadata.is_a? PolicyMetadata
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
metadata
|
84
|
+
else
|
85
|
+
PolicyMetadata.new(**metadata)
|
86
|
+
end
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -293,7 +293,7 @@ module OsoCloud
|
|
293
293
|
faraday.response :raise_error
|
294
294
|
faraday.response :json, parser_options: { symbolize_names: true }
|
295
295
|
faraday.request :retry, {
|
296
|
-
max: (options && options[:max_retries]) ||
|
296
|
+
max: (options && options[:max_retries]) || 3,
|
297
297
|
interval: 0.01,
|
298
298
|
interval_randomness: 0.005,
|
299
299
|
max_interval: 1,
|
@@ -301,7 +301,7 @@ module OsoCloud
|
|
301
301
|
retry_statuses: [429, 500, 502, 503, 504],
|
302
302
|
# This is the default set of methods plus POST.
|
303
303
|
# ref: https://github.com/lostisland/faraday-retry#specify-which-methods-will-be-retried
|
304
|
-
methods: %i[delete get head options post put]
|
304
|
+
methods: %i[delete get head options post put]
|
305
305
|
}
|
306
306
|
|
307
307
|
if options && options[:test_adapter]
|
@@ -336,12 +336,23 @@ module OsoCloud
|
|
336
336
|
@client_id = SecureRandom.uuid
|
337
337
|
end
|
338
338
|
|
339
|
-
def fallback_eligible(path)
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
339
|
+
def fallback_eligible(path, method:)
|
340
|
+
path_eligible = if method == 'get'
|
341
|
+
['/facts', '/policy_metadata'].include?(path)
|
342
|
+
elsif method == 'post'
|
343
|
+
['/authorize',
|
344
|
+
'/authorize_resources',
|
345
|
+
'/list',
|
346
|
+
'/actions',
|
347
|
+
'/query',
|
348
|
+
'/authorize_query',
|
349
|
+
'/list_query',
|
350
|
+
'/actions_query'].include?(path)
|
351
|
+
else
|
352
|
+
false
|
353
|
+
end
|
354
|
+
|
355
|
+
!@fallback_connection.nil? && path_eligible
|
345
356
|
end
|
346
357
|
|
347
358
|
def get_policy
|
@@ -496,13 +507,14 @@ module OsoCloud
|
|
496
507
|
|
497
508
|
def GET(path, params)
|
498
509
|
begin
|
499
|
-
response = @connection.get("api#{path}")
|
510
|
+
response = @connection.get("api#{path}") do |req|
|
500
511
|
req.params = params unless params.nil?
|
501
512
|
req.headers = headers
|
502
513
|
end
|
503
514
|
response.body
|
504
|
-
rescue Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError,
|
505
|
-
|
515
|
+
rescue Faraday::BadRequestError, Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError,
|
516
|
+
Faraday::SSLError => e
|
517
|
+
raise e unless fallback_eligible(path, method: 'get')
|
506
518
|
|
507
519
|
response = @fallback_connection.get("api#{path}") do |req|
|
508
520
|
req.params = params unless params.nil?
|
@@ -515,6 +527,14 @@ module OsoCloud
|
|
515
527
|
end
|
516
528
|
|
517
529
|
def POST(path, params, body, isMutation)
|
530
|
+
max_body_size = 10 * 1024 * 1024
|
531
|
+
hash = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
532
|
+
json_str = JSON.generate(hash)
|
533
|
+
body_size_bytes = json_str&.bytesize || 0
|
534
|
+
if body_size_bytes > max_body_size
|
535
|
+
raise ApiError.new(message: "Request payload too large (body_size_bytes: #{body_size_bytes}, max_body_size #{max_body_size})")
|
536
|
+
end
|
537
|
+
|
518
538
|
begin
|
519
539
|
response = @connection.post("api#{path}") do |req|
|
520
540
|
req.params = params unless params.nil?
|
@@ -522,13 +542,12 @@ module OsoCloud
|
|
522
542
|
req.headers = headers
|
523
543
|
end
|
524
544
|
|
525
|
-
if isMutation
|
526
|
-
@last_offset = response.headers[:OsoOffset]
|
527
|
-
end
|
545
|
+
@last_offset = response.headers[:OsoOffset] if isMutation
|
528
546
|
response.body
|
529
547
|
# only attempt fallback on 5xx, and connection failure conditions
|
530
|
-
rescue Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError,
|
531
|
-
|
548
|
+
rescue Faraday::BadRequestError, Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError,
|
549
|
+
Faraday::SSLError => e
|
550
|
+
raise e unless fallback_eligible(path, method: 'post')
|
532
551
|
|
533
552
|
response = @fallback_connection.post("api#{path}") do |req|
|
534
553
|
req.params = params unless params.nil?
|
@@ -542,6 +561,14 @@ module OsoCloud
|
|
542
561
|
end
|
543
562
|
|
544
563
|
def DELETE(path, body)
|
564
|
+
max_body_size = 10 * 1024 * 1024
|
565
|
+
hash = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
566
|
+
json_str = JSON.generate(hash)
|
567
|
+
body_size_bytes = json_str&.bytesize || 0
|
568
|
+
if body_size_bytes > max_body_size
|
569
|
+
raise ApiError.new(message: "Request payload too large (body_size_bytes: #{body_size_bytes}, max_body_size #{max_body_size})")
|
570
|
+
end
|
571
|
+
|
545
572
|
response = @connection.delete("api#{path}") do |req|
|
546
573
|
req.headers = headers
|
547
574
|
req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
@@ -554,16 +581,16 @@ module OsoCloud
|
|
554
581
|
def handle_faraday_error(error)
|
555
582
|
resp = error.response
|
556
583
|
formatted_request_id = if resp.nil? || resp[:headers].nil? || resp[:headers]['X-Request-ID'].nil?
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
584
|
+
''
|
585
|
+
else
|
586
|
+
' (Request ID: ' + resp[:headers]['X-Request-ID'] + ')'
|
587
|
+
end
|
561
588
|
|
562
589
|
err = if resp.nil? || resp[:body].nil? || resp[:body][:message].nil?
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
590
|
+
error.message
|
591
|
+
else
|
592
|
+
resp[:body][:message]
|
593
|
+
end
|
567
594
|
raise ApiError.new(message: err + formatted_request_id)
|
568
595
|
end
|
569
596
|
end
|
data/lib/oso/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oso-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oso Security, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|