oso-cloud 1.1.0 → 1.2.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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/oso/api.rb +54 -69
- 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: 3991004d30f9fb3930a74494eb15f9658d469bf198440888ef4247b04e0e90fe
|
4
|
+
data.tar.gz: 19a847a4fa5ef0940606838879aa99cb5e1cb9f0b0b591fac9d30ee1b03adf90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69a9097271580148040e9790d49b297d2ca4c90fb5c032d088f51b619e0e995b5348312e46e3748fc2d2d95a4c16cf9a98bba017d5e09292b64a65202b47b25
|
7
|
+
data.tar.gz: 3dfcf182d1283311f79c5ad806ff53e8e8a40c2f36b12cc54b459cfa3d23c215b92e5b59d24b9553df8e2c3a2b874a70e67f87e7ab2f9a647e492188dc4960fc
|
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.2.0)
|
5
5
|
faraday (~> 2.5.2)
|
6
6
|
faraday-retry (~> 2.0.0)
|
7
7
|
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
faraday-net_http (3.0.2)
|
15
15
|
faraday-retry (2.0.0)
|
16
16
|
faraday (~> 2.0)
|
17
|
-
minitest (5.
|
17
|
+
minitest (5.18.0)
|
18
18
|
rake (12.3.3)
|
19
19
|
ruby2_keywords (0.0.5)
|
20
20
|
|
data/lib/oso/api.rb
CHANGED
@@ -4,6 +4,7 @@ require 'faraday'
|
|
4
4
|
require 'faraday/retry'
|
5
5
|
|
6
6
|
require 'oso/helpers'
|
7
|
+
require 'oso/version'
|
7
8
|
|
8
9
|
module OsoCloud
|
9
10
|
# @!visibility private
|
@@ -202,7 +203,7 @@ module OsoCloud
|
|
202
203
|
|
203
204
|
# @!visibility private
|
204
205
|
class Api
|
205
|
-
def initialize(url: 'https://
|
206
|
+
def initialize(url: 'https://api.osohq.com', api_key: nil, options: nil)
|
206
207
|
@url = url
|
207
208
|
@connection = Faraday.new(url: url) do |faraday|
|
208
209
|
faraday.request :json
|
@@ -210,7 +211,7 @@ module OsoCloud
|
|
210
211
|
# responses are processed in reverse order; this stack implies the
|
211
212
|
# retries are attempted before an error is raised, and the json
|
212
213
|
# parser is only applied if there are no errors
|
213
|
-
faraday.response :json,
|
214
|
+
faraday.response :json, parser_options: { symbolize_names: true }
|
214
215
|
faraday.response :raise_error
|
215
216
|
faraday.request :retry, {
|
216
217
|
max: (options && options[:max_retries]) || 10,
|
@@ -249,117 +250,91 @@ module OsoCloud
|
|
249
250
|
end
|
250
251
|
end
|
251
252
|
@api_key = api_key
|
253
|
+
@user_agent = "Oso Cloud (ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}; rv:#{VERSION})"
|
254
|
+
@last_offset = nil
|
252
255
|
end
|
253
256
|
|
254
257
|
def get_policy
|
255
|
-
params = {}
|
256
|
-
data = nil
|
257
258
|
url = '/policy'
|
258
|
-
result = GET(url,
|
259
|
+
result = GET(url, nil)
|
259
260
|
GetPolicyResult.new(**result)
|
260
261
|
end
|
261
262
|
|
262
263
|
def post_policy(data)
|
263
|
-
params = {}
|
264
|
-
data = OsoCloud::Helpers.to_hash(data)
|
265
264
|
url = '/policy'
|
266
|
-
result = POST(url,
|
265
|
+
result = POST(url, nil, data, true)
|
267
266
|
ApiResult.new(**result)
|
268
267
|
end
|
269
268
|
|
270
269
|
def post_facts(data)
|
271
|
-
params = {}
|
272
|
-
data = OsoCloud::Helpers.to_hash(data)
|
273
270
|
url = '/facts'
|
274
|
-
result = POST(url,
|
271
|
+
result = POST(url, nil, data, true)
|
275
272
|
Fact.new(**result)
|
276
273
|
end
|
277
274
|
|
278
275
|
def delete_facts(data)
|
279
|
-
params = {}
|
280
|
-
data = OsoCloud::Helpers.to_hash(data)
|
281
276
|
url = '/facts'
|
282
|
-
result = DELETE(url,
|
277
|
+
result = DELETE(url, data)
|
283
278
|
ApiResult.new(**result)
|
284
279
|
end
|
285
280
|
|
286
281
|
def post_bulk_load(data)
|
287
|
-
params = {}
|
288
|
-
data = OsoCloud::Helpers.to_hash(data)
|
289
282
|
url = '/bulk_load'
|
290
|
-
result = POST(url,
|
283
|
+
result = POST(url, nil, data, true)
|
291
284
|
ApiResult.new(**result)
|
292
285
|
end
|
293
286
|
|
294
287
|
def post_bulk_delete(data)
|
295
|
-
params = {}
|
296
|
-
data = OsoCloud::Helpers.to_hash(data)
|
297
288
|
url = '/bulk_delete'
|
298
|
-
result = POST(url,
|
289
|
+
result = POST(url, nil, data, true)
|
299
290
|
ApiResult.new(**result)
|
300
291
|
end
|
301
292
|
|
302
293
|
def post_bulk(data)
|
303
|
-
params = {}
|
304
|
-
data = OsoCloud::Helpers.to_hash(data)
|
305
294
|
url = '/bulk'
|
306
|
-
result = POST(url,
|
295
|
+
result = POST(url, nil, data, true)
|
307
296
|
ApiResult.new(**result)
|
308
297
|
end
|
309
298
|
|
310
299
|
def post_authorize(data)
|
311
|
-
params = {}
|
312
|
-
data = OsoCloud::Helpers.to_hash(data)
|
313
300
|
url = '/authorize'
|
314
|
-
result = POST(url,
|
301
|
+
result = POST(url, nil, data, false)
|
315
302
|
AuthorizeResult.new(**result)
|
316
303
|
end
|
317
304
|
|
318
305
|
def post_authorize_resources(data)
|
319
|
-
params = {}
|
320
|
-
data = OsoCloud::Helpers.to_hash(data)
|
321
306
|
url = '/authorize_resources'
|
322
|
-
result = POST(url,
|
307
|
+
result = POST(url, nil, data, false)
|
323
308
|
AuthorizeResourcesResult.new(**result)
|
324
309
|
end
|
325
310
|
|
326
311
|
def post_list(data)
|
327
|
-
params = {}
|
328
|
-
data = OsoCloud::Helpers.to_hash(data)
|
329
312
|
url = '/list'
|
330
|
-
result = POST(url,
|
313
|
+
result = POST(url, nil, data, false)
|
331
314
|
ListResult.new(**result)
|
332
315
|
end
|
333
316
|
|
334
317
|
def post_actions(data)
|
335
|
-
params = {}
|
336
|
-
data = OsoCloud::Helpers.to_hash(data)
|
337
318
|
url = '/actions'
|
338
|
-
result = POST(url,
|
319
|
+
result = POST(url, nil, data, false)
|
339
320
|
ActionsResult.new(**result)
|
340
321
|
end
|
341
322
|
|
342
323
|
def post_query(data)
|
343
|
-
params = {}
|
344
|
-
data = OsoCloud::Helpers.to_hash(data)
|
345
324
|
url = '/query'
|
346
|
-
result = POST(url,
|
325
|
+
result = POST(url, nil, data, false)
|
347
326
|
QueryResult.new(**result)
|
348
327
|
end
|
349
328
|
|
350
329
|
def get_stats
|
351
|
-
params = {}
|
352
|
-
data = nil
|
353
330
|
url = '/stats'
|
354
|
-
result = GET(url,
|
331
|
+
result = GET(url, {})
|
355
332
|
StatsResult.new(**result)
|
356
333
|
end
|
357
334
|
|
358
335
|
def clear_data
|
359
|
-
params = {}
|
360
|
-
data = nil
|
361
336
|
url = '/clear_data'
|
362
|
-
result = POST(url,
|
337
|
+
result = POST(url, nil, nil, true)
|
363
338
|
ApiResult.new(**result)
|
364
339
|
end
|
365
340
|
|
@@ -376,57 +351,67 @@ module OsoCloud
|
|
376
351
|
params["args.#{i}.id"] = arg_query.id
|
377
352
|
end
|
378
353
|
end
|
379
|
-
data = nil
|
380
354
|
url = '/facts'
|
381
|
-
result = GET(url, params
|
355
|
+
result = GET(url, params)
|
382
356
|
result.map { |v| Fact.new(**v) }
|
383
357
|
end
|
384
358
|
|
385
359
|
def headers
|
386
|
-
{
|
360
|
+
default_headers = {
|
387
361
|
'Authorization' => format('Bearer %s', @api_key),
|
388
|
-
'User-Agent' =>
|
362
|
+
'User-Agent' => @user_agent,
|
389
363
|
Accept: 'application/json',
|
390
364
|
'Content-Type': 'application/json',
|
391
|
-
'X-OsoApiVersion': '0'
|
365
|
+
'X-OsoApiVersion': '0',
|
392
366
|
}
|
367
|
+
# set OsoOffset is last_offset is not nil
|
368
|
+
default_headers[:OsoOffset] = @last_offset unless @last_offset.nil?
|
369
|
+
default_headers
|
393
370
|
end
|
394
371
|
|
395
|
-
def GET(path, params
|
396
|
-
response = @connection.get("api#{path}"
|
397
|
-
|
372
|
+
def GET(path, params)
|
373
|
+
response = @connection.get("api#{path}") do |req|
|
374
|
+
req.params = params unless params.nil?
|
375
|
+
req.headers = headers
|
376
|
+
end
|
377
|
+
response.body
|
398
378
|
rescue Faraday::Error => e
|
399
379
|
handle_faraday_error e
|
400
380
|
end
|
401
381
|
|
402
|
-
def POST(path, params, body)
|
403
|
-
response = @connection.post("api#{path}"
|
404
|
-
req.params = params
|
382
|
+
def POST(path, params, body, isMutation)
|
383
|
+
response = @connection.post("api#{path}") do |req|
|
384
|
+
req.params = params unless params.nil?
|
385
|
+
req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
386
|
+
req.headers = headers
|
405
387
|
end
|
406
|
-
|
388
|
+
|
389
|
+
if isMutation
|
390
|
+
@last_offset = response.headers[:OsoOffset]
|
391
|
+
end
|
392
|
+
response.body
|
407
393
|
rescue Faraday::Error => e
|
408
394
|
handle_faraday_error e
|
409
395
|
end
|
410
396
|
|
411
|
-
def DELETE(path,
|
412
|
-
response = @connection.delete("api#{path}"
|
413
|
-
req.
|
397
|
+
def DELETE(path, body)
|
398
|
+
response = @connection.delete("api#{path}") do |req|
|
399
|
+
req.headers = headers
|
400
|
+
req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
414
401
|
end
|
415
|
-
|
402
|
+
response.body
|
416
403
|
rescue Faraday::Error => e
|
417
404
|
handle_faraday_error e
|
418
405
|
end
|
419
406
|
|
420
|
-
def handle_faraday_response(response)
|
421
|
-
# TODO: (@patrickod) refactor duplicative JSON parsing
|
422
|
-
JSON.parse(response.env[:raw_body], symbolize_names: true)
|
423
|
-
end
|
424
|
-
|
425
407
|
def handle_faraday_error(error)
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
408
|
+
resp = error.response
|
409
|
+
err = if resp.respond_to? :body
|
410
|
+
resp.body[:message]
|
411
|
+
else
|
412
|
+
error.message
|
413
|
+
end
|
414
|
+
raise ApiError.new(message: err)
|
430
415
|
end
|
431
416
|
end
|
432
417
|
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.2.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: 2023-
|
11
|
+
date: 2023-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|