oso-cloud 1.10.0 → 1.11.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dac67a8075972556f7ae65a0536ec256633cb2262e09bc846c0d9abd5d076b7
4
- data.tar.gz: 5f99588ce46c6aa63eec48ba8c157f493a86f6341f7c3983ebaaef82712d424d
3
+ metadata.gz: f66bca1d07a3adbcedf23dd7fb2e8962788a209645c8ecf2e1147f35a00bbeab
4
+ data.tar.gz: ad34aa74fea952b3a7b1a8d5c1ac9f26f56a4e23ed14187675f854b22aa34d58
5
5
  SHA512:
6
- metadata.gz: e208dbfa5c8d680d6887369deb5acaf157ab3d06ed408b9fa375823a00c39a9c7a2bf397d1fb14d0716d71b9518bd1f7124900d7dc0ae586a2b12f964ff23315
7
- data.tar.gz: c4485eaf638f9e262c8b035c5b6606b0162fea19babe548f1ffd14cbee977e1ee0408f3679bc2f87eb984debeef86f176c4e0dcbed5c3164dea3acd7066fc515
6
+ metadata.gz: e4011b1d7408ced5b4797d44cf725f0d364a42444586d7bee9be77025dffd995b63066fdbdfc778635410b1368f92ff01e8cc6728cb7c696eff3fecf0e08d693
7
+ data.tar.gz: a2d207b0e58b5e1937e22b89c5ebea872f81539b018b6fcd9790c88468016c43ca8a21a40e71874c758783d9d1512285698b9591446b63364e79b9119e34dfcc
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .bundle
2
2
  vendor
3
+ *.gem
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in oso-cloud.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
6
+ gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,67 +1,121 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-cloud (1.10.0)
5
- faraday (~> 2.5.2)
4
+ oso-cloud (1.11.2)
5
+ faraday (>= 2.14.1, < 3.0)
6
6
  faraday-net_http_persistent (~> 2.0)
7
- faraday-retry (~> 2.0.0)
7
+ faraday-retry (~> 2.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (7.1.3)
13
- activesupport (= 7.1.3)
14
- activerecord (7.1.3)
15
- activemodel (= 7.1.3)
16
- activesupport (= 7.1.3)
12
+ activemodel (7.2.3.1)
13
+ activesupport (= 7.2.3.1)
14
+ activerecord (7.2.3.1)
15
+ activemodel (= 7.2.3.1)
16
+ activesupport (= 7.2.3.1)
17
17
  timeout (>= 0.4.0)
18
- activesupport (7.1.3)
18
+ activesupport (7.2.3.1)
19
19
  base64
20
+ benchmark (>= 0.3)
20
21
  bigdecimal
21
- concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ concurrent-ruby (~> 1.0, >= 1.3.1)
22
23
  connection_pool (>= 2.2.5)
23
24
  drb
24
25
  i18n (>= 1.6, < 2)
25
- minitest (>= 5.1)
26
- mutex_m
27
- tzinfo (~> 2.0)
28
- base64 (0.2.0)
29
- bigdecimal (3.1.6)
30
- concurrent-ruby (1.2.3)
31
- connection_pool (2.4.1)
32
- drb (2.2.0)
33
- ruby2_keywords
34
- faraday (2.5.2)
35
- faraday-net_http (>= 2.0, < 3.1)
36
- ruby2_keywords (>= 0.0.4)
37
- faraday-net_http (3.0.2)
38
- faraday-net_http_persistent (2.1.0)
26
+ logger (>= 1.4.2)
27
+ minitest (>= 5.1, < 6)
28
+ securerandom (>= 0.3)
29
+ tzinfo (~> 2.0, >= 2.0.5)
30
+ base64 (0.3.0)
31
+ benchmark (0.5.0)
32
+ bigdecimal (4.1.2)
33
+ concurrent-ruby (1.3.6)
34
+ connection_pool (3.0.2)
35
+ drb (2.2.3)
36
+ faraday (2.14.1)
37
+ faraday-net_http (>= 2.0, < 3.5)
38
+ json
39
+ logger
40
+ faraday-net_http (3.4.2)
41
+ net-http (~> 0.5)
42
+ faraday-net_http_persistent (2.3.1)
39
43
  faraday (~> 2.5)
40
- net-http-persistent (~> 4.0)
41
- faraday-retry (2.0.0)
44
+ net-http-persistent (>= 4.0.4, < 5)
45
+ faraday-retry (2.4.0)
42
46
  faraday (~> 2.0)
43
- i18n (1.14.1)
47
+ i18n (1.14.8)
44
48
  concurrent-ruby (~> 1.0)
45
- minitest (5.18.0)
46
- mutex_m (0.2.0)
47
- net-http-persistent (4.0.2)
48
- connection_pool (~> 2.2)
49
- pg (1.5.4)
50
- rake (12.3.3)
51
- ruby2_keywords (0.0.5)
52
- timeout (0.4.1)
49
+ json (2.19.5)
50
+ logger (1.7.0)
51
+ minitest (5.27.0)
52
+ net-http (0.9.1)
53
+ uri (>= 0.11.1)
54
+ net-http-persistent (4.0.8)
55
+ connection_pool (>= 2.2.4, < 4)
56
+ pg (1.6.3)
57
+ pg (1.6.3-aarch64-linux)
58
+ pg (1.6.3-aarch64-linux-musl)
59
+ pg (1.6.3-arm64-darwin)
60
+ pg (1.6.3-x86_64-darwin)
61
+ pg (1.6.3-x86_64-linux)
62
+ pg (1.6.3-x86_64-linux-musl)
63
+ rake (13.4.2)
64
+ securerandom (0.4.1)
65
+ timeout (0.6.1)
53
66
  tzinfo (2.0.6)
54
67
  concurrent-ruby (~> 1.0)
68
+ uri (1.1.1)
55
69
 
56
70
  PLATFORMS
71
+ aarch64-linux
72
+ aarch64-linux-musl
73
+ arm64-darwin
57
74
  ruby
75
+ x86_64-darwin
76
+ x86_64-linux
77
+ x86_64-linux-musl
58
78
 
59
79
  DEPENDENCIES
60
80
  activerecord (~> 7.0)
61
81
  minitest (~> 5.15)
62
82
  oso-cloud!
63
83
  pg (~> 1.0)
64
- rake (~> 12.0)
84
+ rake (~> 13.0)
85
+
86
+ CHECKSUMS
87
+ activemodel (7.2.3.1) sha256=39e1869b85e7a0b64a8ccddf19f3fb0c44261b329785384bb88f878eab51c0d0
88
+ activerecord (7.2.3.1) sha256=b89513e275da5b34183c5f2a497c154b02dcc7c811d399ab557e67e36170a05d
89
+ activesupport (7.2.3.1) sha256=11ebed516a43a0bb47346227a35ebae4d9427465a7c9eb197a03d5c8d283cb34
90
+ base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
91
+ benchmark (0.5.0) sha256=465df122341aedcb81a2a24b4d3bd19b6c67c1530713fd533f3ff034e419236c
92
+ bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd
93
+ concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
94
+ connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
95
+ drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
96
+ faraday (2.14.1) sha256=a43cceedc1e39d188f4d2cdd360a8aaa6a11da0c407052e426ba8d3fb42ef61c
97
+ faraday-net_http (3.4.2) sha256=f147758260d3526939bf57ecf911682f94926a3666502e24c69992765875906c
98
+ faraday-net_http_persistent (2.3.1) sha256=23ffba37d6a27807a10f033d01918ec958aa73fa6ff0fccfbcd5ce2d2e68fca3
99
+ faraday-retry (2.4.0) sha256=7b79c48fb7e56526faf247b12d94a680071ff40c9fda7cf1ec1549439ad11ebe
100
+ i18n (1.14.8) sha256=285778639134865c5e0f6269e0b818256017e8cde89993fdfcbfb64d088824a5
101
+ json (2.19.5) sha256=218a18553e4801d579ca7e0f5bc72bafd776d7397238a1fb4e74db5b0a812c59
102
+ logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
103
+ minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
104
+ net-http (0.9.1) sha256=25ba0b67c63e89df626ed8fac771d0ad24ad151a858af2cc8e6a716ca4336996
105
+ net-http-persistent (4.0.8) sha256=ef3de8319d691537b329053fae3a33195f8b070bbbfae8bf1a58c796081960e6
106
+ oso-cloud (1.11.2)
107
+ pg (1.6.3) sha256=1388d0563e13d2758c1089e35e973a3249e955c659592d10e5b77c468f628a99
108
+ pg (1.6.3-aarch64-linux) sha256=0698ad563e02383c27510b76bf7d4cd2de19cd1d16a5013f375dd473e4be72ea
109
+ pg (1.6.3-aarch64-linux-musl) sha256=06a75f4ea04b05140146f2a10550b8e0d9f006a79cdaf8b5b130cde40e3ecc2c
110
+ pg (1.6.3-arm64-darwin) sha256=7240330b572e6355d7c75a7de535edb5dfcbd6295d9c7777df4d9dddfb8c0e5f
111
+ pg (1.6.3-x86_64-darwin) sha256=ee2e04a17c0627225054ffeb43e31a95be9d7e93abda2737ea3ce4a62f2729d6
112
+ pg (1.6.3-x86_64-linux) sha256=5d9e188c8f7a0295d162b7b88a768d8452a899977d44f3274d1946d67920ae8d
113
+ pg (1.6.3-x86_64-linux-musl) sha256=9c9c90d98c72f78eb04c0f55e9618fe55d1512128e411035fe229ff427864009
114
+ rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
115
+ securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
116
+ timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb
117
+ tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
118
+ uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
65
119
 
66
120
  BUNDLED WITH
67
- 2.5.6
121
+ 4.0.3
data/lib/oso/api.rb CHANGED
@@ -22,7 +22,10 @@ module OsoCloud
22
22
 
23
23
  # @!visibility private
24
24
  class ApiError < StandardError
25
- def initialize(message:)
25
+ attr_reader :status_code, :retry_after
26
+ def initialize(message:, status_code: nil, retry_after: nil)
27
+ @status_code = status_code
28
+ @retry_after = retry_after
26
29
  super(message)
27
30
  end
28
31
  end
@@ -164,23 +167,26 @@ module OsoCloud
164
167
 
165
168
  # @!visibility private
166
169
  class ListResult
167
- attr_reader :results
170
+ attr_reader :results, :next_page_token
168
171
 
169
- def initialize(results:)
172
+ def initialize(results:, next_page_token: nil)
170
173
  @results = results
174
+ @next_page_token = next_page_token
171
175
  end
172
176
  end
173
177
 
174
178
  # @!visibility private
175
179
  class ListQuery
176
- attr_reader :actor_type, :actor_id, :action, :resource_type, :context_facts
180
+ attr_reader :actor_type, :actor_id, :action, :resource_type, :context_facts, :page_size, :page_token
177
181
 
178
- def initialize(actor_type:, actor_id:, action:, resource_type:, context_facts:)
182
+ def initialize(actor_type:, actor_id:, action:, resource_type:, context_facts:, page_size: nil, page_token: nil)
179
183
  @actor_type = actor_type
180
184
  @actor_id = actor_id
181
185
  @action = action
182
186
  @resource_type = resource_type
183
187
  @context_facts = context_facts.map { |v| (v.is_a? Fact) ? v : Fact.new(**v) }
188
+ @page_size = page_size
189
+ @page_token = page_token
184
190
  end
185
191
  end
186
192
 
@@ -229,17 +235,6 @@ module OsoCloud
229
235
  end
230
236
  end
231
237
 
232
- # @!visibility private
233
- class StatsResult
234
- attr_reader :num_roles, :num_relations, :num_facts
235
-
236
- def initialize(num_roles:, num_relations:, num_facts:)
237
- @num_roles = num_roles
238
- @num_relations = num_relations
239
- @num_facts = num_facts
240
- end
241
- end
242
-
243
238
  # @!visibility private
244
239
  class LocalAuthQuery
245
240
  attr_reader :query, :data_bindings
@@ -298,6 +293,9 @@ module OsoCloud
298
293
  interval_randomness: 0.005,
299
294
  max_interval: 1,
300
295
  backoff_factor: 2,
296
+ # 409 (Conflict) is intentionally not retried here. The server uses 409
297
+ # with Retry-After for paginated results not yet ready, which needs
298
+ # longer delays than HTTP-level backoff. Handled by per-page retry in list().
301
299
  retry_statuses: [429, 500, 502, 503, 504],
302
300
  # This is the default set of methods plus POST.
303
301
  # ref: https://github.com/lostisland/faraday-retry#specify-which-methods-will-be-retried
@@ -439,12 +437,6 @@ module OsoCloud
439
437
  QueryResult.new(**result)
440
438
  end
441
439
 
442
- def get_stats
443
- url = '/stats'
444
- result = GET(url, {})
445
- StatsResult.new(**result)
446
- end
447
-
448
440
  def post_authorize_query(query, parity_handle = nil)
449
441
  url = '/authorize_query'
450
442
  data = LocalAuthQuery.new(query: query, data_bindings: @data_bindings)
@@ -598,10 +590,13 @@ module OsoCloud
598
590
 
599
591
  def handle_faraday_error(error)
600
592
  resp = error.response
601
- create_api_error(resp, error.message)
593
+ status_code = resp && resp[:status]
594
+ retry_after = resp && resp[:headers] && resp[:headers]['Retry-After']
595
+ retry_after = retry_after.to_f if retry_after
596
+ create_api_error(resp, error.message, status_code: status_code, retry_after: retry_after)
602
597
  end
603
598
 
604
- def create_api_error(resp, message)
599
+ def create_api_error(resp, message, status_code: nil, retry_after: nil)
605
600
  formatted_request_id = if resp.nil? || resp[:headers].nil? || resp[:headers]['X-Request-ID'].nil?
606
601
  ''
607
602
  else
@@ -613,7 +608,11 @@ module OsoCloud
613
608
  else
614
609
  resp[:body][:message]
615
610
  end
616
- raise ApiError.new(message: err + formatted_request_id)
611
+
612
+ sc = status_code || (resp && resp[:status])
613
+ ra = retry_after || (resp && resp[:headers] && resp[:headers]['Retry-After'] ? resp[:headers]['Retry-After'].to_f : nil)
614
+
615
+ raise ApiError.new(message: err + formatted_request_id, status_code: sc, retry_after: ra)
617
616
  end
618
617
 
619
618
  def post_expected_result(expected_result)
data/lib/oso/oso.rb CHANGED
@@ -228,15 +228,50 @@ module OsoCloud
228
228
  # @return [Array<String>]
229
229
  # @see Oso for more information about facts
230
230
  def list(actor, action, resource_type, context_facts = [])
231
+ all_results = []
232
+ page_token = nil
233
+ loop do
234
+ page = list_paginated(actor, action, resource_type, 10000, page_token: page_token, context_facts: context_facts)
235
+ all_results.concat(page.results)
236
+ break if page.next_page_token.nil?
237
+ page_token = page.next_page_token
238
+ end
239
+ all_results
240
+ end
241
+
242
+ ##
243
+ # List authorized resources with pagination
244
+ #
245
+ # Fetches a page of resource ids on which an actor can perform a
246
+ # particular action. Returns a ListResult with `results` and `next_page_token`.
247
+ # Pass `next_page_token` to fetch subsequent pages.
248
+ #
249
+ # @param actor [OsoCloud::Value]
250
+ # @param action [String]
251
+ # @param resource_type [String]
252
+ # @param page_size [Integer]
253
+ # @param page_token [String, nil]
254
+ # @param context_facts [Array<fact>]
255
+ # @return [OsoCloud::Core::ListResult]
256
+ def list_paginated(actor, action, resource_type, page_size, page_token: nil, context_facts: [])
231
257
  actor_typed_id = actor.to_api_value
232
- result = @api.post_list(OsoCloud::Core::ListQuery.new(
233
- actor_type: actor_typed_id.type,
234
- actor_id: actor_typed_id.id,
235
- action: action,
236
- resource_type: resource_type,
237
- context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
238
- ))
239
- result.results
258
+ 10.times do |attempt|
259
+ begin
260
+ return @api.post_list(OsoCloud::Core::ListQuery.new(
261
+ actor_type: actor_typed_id.type,
262
+ actor_id: actor_typed_id.id,
263
+ action: action,
264
+ resource_type: resource_type,
265
+ context_facts: OsoCloud::Helpers.params_to_facts(context_facts),
266
+ page_size: page_size,
267
+ page_token: page_token
268
+ ))
269
+ rescue OsoCloud::Core::ApiError => e
270
+ raise unless e.status_code == 409 && e.retry_after && attempt < 9
271
+ sleep(e.retry_after)
272
+ end
273
+ end
274
+ raise OsoCloud::Core::ApiError.new(message: 'Page not available after retries', status_code: 409)
240
275
  end
241
276
 
242
277
  ##
data/lib/oso/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  # !! IMPORTANT: Update the ruby docs to reflect the latest version !!
4
4
  module OsoCloud
5
- VERSION = '1.10.0'
5
+ VERSION = '1.11.2'
6
6
  end
data/oso-cloud.gemspec CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'faraday', '~> 2.5.2'
24
- spec.add_dependency 'faraday-retry', '~> 2.0.0'
23
+ spec.add_dependency 'faraday', '>= 2.14.1', '< 3.0'
24
+ spec.add_dependency 'faraday-retry', '~> 2.0'
25
25
  spec.add_dependency 'faraday-net_http_persistent', '~> 2.0'
26
26
  spec.add_development_dependency 'minitest', '~> 5.15'
27
27
  spec.add_development_dependency 'pg', '~> 1.0'
metadata CHANGED
@@ -1,43 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oso Security, Inc.
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-06-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.14.1
19
+ - - "<"
18
20
  - !ruby/object:Gem::Version
19
- version: 2.5.2
21
+ version: '3.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: 2.5.2
28
+ version: 2.14.1
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: faraday-retry
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - "~>"
32
37
  - !ruby/object:Gem::Version
33
- version: 2.0.0
38
+ version: '2.0'
34
39
  type: :runtime
35
40
  prerelease: false
36
41
  version_requirements: !ruby/object:Gem::Requirement
37
42
  requirements:
38
43
  - - "~>"
39
44
  - !ruby/object:Gem::Version
40
- version: 2.0.0
45
+ version: '2.0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: faraday-net_http_persistent
43
48
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +99,6 @@ dependencies:
94
99
  - - "~>"
95
100
  - !ruby/object:Gem::Version
96
101
  version: '7.0'
97
- description:
98
102
  email:
99
103
  - support@osohq.com
100
104
  executables: []
@@ -120,7 +124,6 @@ homepage: https://www.osohq.com/
120
124
  licenses:
121
125
  - Apache-2.0
122
126
  metadata: {}
123
- post_install_message:
124
127
  rdoc_options: []
125
128
  require_paths:
126
129
  - lib
@@ -135,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
138
  - !ruby/object:Gem::Version
136
139
  version: '0'
137
140
  requirements: []
138
- rubygems_version: 3.2.33
139
- signing_key:
141
+ rubygems_version: 3.6.9
140
142
  specification_version: 4
141
143
  summary: Oso Cloud Ruby client
142
144
  test_files: []