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