oso-cloud 1.3.0.dev.5 → 1.3.0.dev.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51dc4187ef8812ede5669c392262eceb0cf09ed962831f0263c0eb931703ba21
4
- data.tar.gz: 37f0a58b35e23da57458685ad36a9171e20c933fa90a80685226ef0d3a9b9cf6
3
+ metadata.gz: 844583229037d7124d91b588abfbef062026c934d5cd1dcd0e4892a6d539b969
4
+ data.tar.gz: 889f910639d097b5c5e29fa64e36959a7c7aebbe7ffe48dfa080f8bbef119015
5
5
  SHA512:
6
- metadata.gz: 732ec34bb79ad29287de13c6e6d696e374b21478dd4943059d0b7e4adb41ff96d31908b339e69f346bc7ee64704bdaeca1973ffdb49ae088dd73991615da43b8
7
- data.tar.gz: a397403259a48af1d934cefe3563c0a5816810b00a213e30f99aabaa41affacfa95e276c234da9201f36474ddca0305d83969816ca2ea5021eb862e2b717b579
6
+ metadata.gz: 77883cfc4f1584d65a31f1d620d239bcb98b70de099320c91590de55b4a39ee8b4aa7d5c80bbe7b94b8f6f16a02aeab6d54efb5aeecb1a289e7f93ac9048e1a8
7
+ data.tar.gz: ecd8b9f6377a4465b9cc39622d35da59a548229ab6df9edc212859e0f282041a812644c02f4cc9e25065e047e805d1fd594b69f5adeb9b40e4e0a4ddab5711a2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-cloud (1.3.0.dev.5)
4
+ oso-cloud (1.3.0.dev.6)
5
5
  faraday (~> 2.5.2)
6
6
  faraday-net_http_persistent (~> 2.0)
7
7
  faraday-retry (~> 2.0.0)
data/lib/oso/api.rb CHANGED
@@ -203,6 +203,17 @@ module OsoCloud
203
203
  end
204
204
  end
205
205
 
206
+ class OsoAdapter < Faraday::Adapter::Typhoeus
207
+ @@max_concurrency = 20
208
+
209
+ def self.setup_parallel_manager(options = {})
210
+ options[:max_concurrency] = @@max_concurrency
211
+ ::Typhoeus::Hydra.new(options)
212
+ end
213
+ end
214
+
215
+ Faraday::Adapter.register_middleware(oso_http: OsoAdapter)
216
+
206
217
  # @!visibility private
207
218
  class Api
208
219
  def get_connection(options: nil)
@@ -214,6 +225,7 @@ module OsoCloud
214
225
  # parser is only applied if there are no errors
215
226
  faraday.response :json, parser_options: { symbolize_names: true }
216
227
  faraday.response :raise_error
228
+ # faraday.response :logger
217
229
  faraday.request :retry, {
218
230
  max: (options && options[:max_retries]) || 10,
219
231
  interval: 0.01,
@@ -247,17 +259,20 @@ module OsoCloud
247
259
  end
248
260
  end
249
261
  elsif options && options[:parallel_adapter]
250
- faraday.adapter :typhoeus, forbid_reuse: false, maxredirs: 1, connecttimeout: 30
262
+ if options[:max_concurrency]
263
+ OsoAdapter.class_variable_set(:@@max_concurrency, options[:max_concurrency])
264
+ end
265
+ faraday.adapter :oso_http, forbid_reuse: false, maxredirs: 1, connecttimeout: 30
251
266
  else
252
267
  faraday.adapter :net_http_persistent, pool_size: 10, idle_timeout: 30
253
268
  end
254
269
  end
255
270
  end
256
271
 
257
- def initialize(url: 'https://api.osohq.com', api_key: nil, options: nil)
272
+ def initialize(url: 'https://api.osohq.com', api_key: nil, options: {})
258
273
  @url = url
259
274
  @connection = get_connection(options: options)
260
- @parallel_connection = get_connection(options: { parallel_adapter: true })
275
+ @parallel_connection = get_connection(options: { parallel_adapter: true, max_concurrency: options[:max_concurrency] })
261
276
  @api_key = api_key
262
277
  @user_agent = "Oso Cloud (ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}; rv:#{VERSION})"
263
278
  @last_offset = nil
data/lib/oso/oso.rb CHANGED
@@ -28,8 +28,8 @@ 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)
32
- @api = OsoCloud::Core::Api.new(url: url, api_key: api_key)
31
+ def initialize(url: 'https://cloud.osohq.com', api_key: nil, options: nil)
32
+ @api = OsoCloud::Core::Api.new(url: url, api_key: api_key, options: options || {})
33
33
  end
34
34
 
35
35
  # Update the active policy
@@ -270,21 +270,37 @@ module OsoCloud
270
270
  OsoCloud::Helpers.facts_to_params(result.results)
271
271
  end
272
272
 
273
- def actions_batch(actor, resources, context_facts = [])
274
- actor_typed_id = actor.to_api_value
275
- data = resources.map do |r|
276
- resource_typed_id = r.to_api_value
277
- OsoCloud::Core::ActionsQuery.new(
278
- actor_type: actor_typed_id.type,
279
- actor_id: actor_typed_id.id,
280
- resource_type: resource_typed_id.type,
281
- resource_id: resource_typed_id.id,
282
- context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
283
- )
273
+ ##
274
+ # List authorized actions for a batch of queries
275
+ #
276
+ # Fetches a list of actions which an actor can perform on a particular resource.
277
+ #
278
+ # @param actor [OsoCloud::Value]
279
+ # @param queries [Array<OsoCloud::Value>] | Array<[OsoCloud::Value, Array<fact>]>
280
+ # @return [Array<Array<String>>]
281
+ # @see Oso for more information about facts
282
+ def actions_batch(actor, queries:)
283
+ actor_typed_id = actor.to_api_value
284
+ data = queries.map do |q|
285
+ context_facts = []
286
+ resource = nil
287
+ if (q.is_a?(Array))
288
+ resource = q[0]
289
+ context_facts = q[1]
290
+ else
291
+ resource = q
292
+ end
293
+ resource_typed_id = resource.to_api_value
294
+ OsoCloud::Core::ActionsQuery.new(
295
+ actor_type: actor_typed_id.type,
296
+ actor_id: actor_typed_id.id,
297
+ resource_type: resource_typed_id.type,
298
+ resource_id: resource_typed_id.id,
299
+ context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
300
+ )
284
301
  end
285
302
  @api.post_actions_batch(data).map { |result| result.results}
286
303
  end
287
304
  end
288
305
 
289
306
  end
290
-
data/lib/oso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OsoCloud
2
- VERSION = '1.3.0.dev.5'.freeze
2
+ VERSION = '1.3.0.dev.7'.freeze
3
3
  end
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.3.0.dev.5
4
+ version: 1.3.0.dev.7
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-09-27 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday