oso-cloud 1.0.0 → 1.0.1
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 +53 -11
- 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: 339079e696596a482f6f1fe6bc875d9f88dc5415b0eaca4b4e7a04304280cc7a
|
4
|
+
data.tar.gz: '099c6b0532405a7fc0cf5933b09ea03991fe43f3e2da6b726d5e33e932706b55'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 441e11c7fdb4b201cf22d84195d7f0cc5454a64186c0078086ae085138a31a8ee10f667f5723b94b467aa74ee89780e1ccd853c435d044f84616b46f78a44527
|
7
|
+
data.tar.gz: 56c4cb7d88820805bbd9238624f8220253c48aa19fdffe71298af26ff9369e3bf5692d49be70f439a582e4f76ff9d4b7458f45a303fa32c02296c5c2324f9f08
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
oso-cloud (1.0.
|
4
|
+
oso-cloud (1.0.1)
|
5
5
|
faraday (~> 2.5.2)
|
6
6
|
faraday-retry (~> 2.0.0)
|
7
7
|
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
faraday (2.5.2)
|
12
12
|
faraday-net_http (>= 2.0, < 3.1)
|
13
13
|
ruby2_keywords (>= 0.0.4)
|
14
|
-
faraday-net_http (3.0.
|
14
|
+
faraday-net_http (3.0.2)
|
15
15
|
faraday-retry (2.0.0)
|
16
16
|
faraday (~> 2.0)
|
17
17
|
minitest (5.15.0)
|
data/lib/oso/api.rb
CHANGED
@@ -18,11 +18,9 @@ module OsoCloud
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# @!visibility private
|
21
|
-
class ApiError
|
22
|
-
attr_reader :message
|
23
|
-
|
21
|
+
class ApiError < StandardError
|
24
22
|
def initialize(message:)
|
25
|
-
|
23
|
+
super(message)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
@@ -229,20 +227,51 @@ module OsoCloud
|
|
229
227
|
|
230
228
|
# @!visibility private
|
231
229
|
class Api
|
232
|
-
def initialize(url: 'https://cloud.osohq.com', api_key: nil)
|
230
|
+
def initialize(url: 'https://cloud.osohq.com', api_key: nil, options: nil)
|
233
231
|
@url = url
|
234
232
|
@connection = Faraday.new(url: url) do |faraday|
|
233
|
+
faraday.request :json
|
234
|
+
|
235
|
+
# responses are processed in reverse order; this stack implies the
|
236
|
+
# retries are attempted before an error is raised, and the json
|
237
|
+
# parser is only applied if there are no errors
|
238
|
+
faraday.response :json, preserve_raw: true
|
239
|
+
faraday.response :raise_error
|
235
240
|
faraday.request :retry, {
|
236
|
-
max:
|
237
|
-
interval: 0.
|
238
|
-
interval_randomness: 0.
|
241
|
+
max: (options && options[:max_retries]) || 10,
|
242
|
+
interval: 0.01,
|
243
|
+
interval_randomness: 0.005,
|
244
|
+
max_interval: 1,
|
239
245
|
backoff_factor: 2,
|
240
246
|
retry_statuses: [429, 500, 502, 503, 504],
|
247
|
+
# ensure authorize and related check functions are retried because
|
248
|
+
# they are POST requests, which are not retried automatically
|
249
|
+
retry_if: ->(env, _exc) {
|
250
|
+
%w[
|
251
|
+
/api/authorize
|
252
|
+
/api/authorize_resources
|
253
|
+
/api/list
|
254
|
+
/api/actions
|
255
|
+
/api/query
|
256
|
+
].include? env.url.path
|
257
|
+
},
|
241
258
|
}
|
242
259
|
|
243
|
-
|
244
|
-
|
245
|
-
|
260
|
+
if (options && options[:test_adapter])
|
261
|
+
faraday.adapter :test do |stub|
|
262
|
+
stub.post(options[:test_adapter][:path]) do |env|
|
263
|
+
options[:test_adapter][:func].call
|
264
|
+
end
|
265
|
+
stub.get(options[:test_adapter][:path]) do |env|
|
266
|
+
options[:test_adapter][:func].call
|
267
|
+
end
|
268
|
+
stub.delete(options[:test_adapter][:path]) do |env|
|
269
|
+
options[:test_adapter][:func].call
|
270
|
+
end
|
271
|
+
end
|
272
|
+
else
|
273
|
+
faraday.adapter :net_http
|
274
|
+
end
|
246
275
|
end
|
247
276
|
@api_key = api_key
|
248
277
|
end
|
@@ -390,6 +419,8 @@ module OsoCloud
|
|
390
419
|
def GET(path, params, body)
|
391
420
|
response = @connection.get("api#{path}", params, headers )
|
392
421
|
handle_faraday_response response
|
422
|
+
rescue Faraday::Error => error
|
423
|
+
handle_faraday_error error
|
393
424
|
end
|
394
425
|
|
395
426
|
def POST(path, params, body)
|
@@ -397,6 +428,8 @@ module OsoCloud
|
|
397
428
|
req.params = params
|
398
429
|
end
|
399
430
|
handle_faraday_response response
|
431
|
+
rescue Faraday::Error => error
|
432
|
+
handle_faraday_error error
|
400
433
|
end
|
401
434
|
|
402
435
|
def DELETE(path, params, body)
|
@@ -404,12 +437,21 @@ module OsoCloud
|
|
404
437
|
req.body = body
|
405
438
|
end
|
406
439
|
handle_faraday_response response
|
440
|
+
rescue Faraday::Error => error
|
441
|
+
handle_faraday_error error
|
407
442
|
end
|
408
443
|
|
409
444
|
def handle_faraday_response(response)
|
410
445
|
# TODO:(@patrickod) refactor duplicative JSON parsing
|
411
446
|
JSON.parse(response.env[:raw_body], symbolize_names: true)
|
412
447
|
end
|
448
|
+
|
449
|
+
def handle_faraday_error(error)
|
450
|
+
err = JSON.parse(error.response[:body], symbolize_names: true)
|
451
|
+
raise ApiError.new(**err)
|
452
|
+
rescue JSON::ParserError => e
|
453
|
+
raise ApiError.new(message: e.message)
|
454
|
+
end
|
413
455
|
end
|
414
456
|
|
415
457
|
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.0.
|
4
|
+
version: 1.0.1
|
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:
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|