kessel-sdk 1.9.0 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9408aacf7604105abff5b811ad6548270be6d0c63f6193602fecd703ea79d522
4
- data.tar.gz: 0237cd7effe27b00ff1ac07b1e8a2121f0275a2cbd48e215ae0a24ad511e8fb3
3
+ metadata.gz: 136206dbccfc87a36252fa0b635f195d00ebc861f9d26c3a35095403257e971c
4
+ data.tar.gz: 6e1366c5ed2fc78316fd7804f4ff31ac59819817e919fda84e689c7c8023f980
5
5
  SHA512:
6
- metadata.gz: 6a6ee646283375fcb8f535f14475639e1d9b687212de54c06795eab2de4b07abc310a74c0ba9ed5d660efbcf8a039929f3cf6379ebaae18f8859434324fdd565
7
- data.tar.gz: 6a92e7bb7b73d215fade25f2e818ecfad57638d5f84858c742fd4914294ac90132205cd9e252cb8906729927508fe73ba662e0fe93ee9e6528629be421137448
6
+ metadata.gz: 2c015adbcbf6838b582f598b31d7860d31541c4adeb622c60877399b67ae797a516f603185640890f6c711311e0ff9f09ef0968153219b9dddcc070bb75acfeb
7
+ data.tar.gz: 4967035e1789c864e4197e5e6ffcbf7bfe6e2d47dc24b2c1a4823b83e198171f043f0ceb0f9bee4cbbc5ae5f495882c2654b6d6e08989a4cc15fae5de3513a96
data/README.md CHANGED
@@ -196,6 +196,10 @@ end
196
196
 
197
197
  ### List Workspaces (Streaming with Auto-Pagination)
198
198
 
199
+ The `list_workspaces` helper automatically paginates through all workspaces
200
+ a subject can access. Continuation tokens are handled internally, meaning you never
201
+ need to manage them yourself.
202
+
199
203
  ```ruby
200
204
  include Kessel::Inventory::V1beta2
201
205
  include Kessel::RBAC::V2
@@ -204,11 +208,20 @@ client = KesselInventoryService::ClientBuilder.new('localhost:9000')
204
208
  .insecure
205
209
  .build
206
210
 
207
- list_workspaces(client, principal_subject('alice', 'redhat'), 'view_document').each do |response|
208
- puts response
211
+ subject = principal_subject("alice", "redhat")
212
+ consistency = Kessel::Inventory::V1beta2::Consistency.new(minimize_latency: true)
213
+
214
+ # Lazy iteration (constant memory)
215
+ list_workspaces(client, subject, "viewer", consistency: consistency).each do |response|
216
+ puts response.object.resource_id
209
217
  end
218
+
219
+ # Materialise into an Array
220
+ all_workspaces = list_workspaces(client, subject, "viewer", consistency: consistency).to_a
210
221
  ```
211
222
 
223
+ See [`examples/list_workspaces.rb`](./examples/list_workspaces.rb) for a complete working example.
224
+
212
225
  ### Available Services (V1beta2)
213
226
 
214
227
  The primary service is **`KesselInventoryService`** with these RPCs:
data/lib/kessel/auth.rb CHANGED
@@ -130,6 +130,7 @@ module Kessel
130
130
  @client_secret = client_secret
131
131
  @token_endpoint = token_endpoint
132
132
  @token_mutex = Mutex.new
133
+ @generation = 0
133
134
  end
134
135
 
135
136
  # Gets the current access token with automatic caching and refresh.
@@ -146,13 +147,14 @@ module Kessel
146
147
  def get_token(force_refresh: false)
147
148
  return @cached_token if !force_refresh && token_valid?
148
149
 
149
- @token_mutex.synchronize do
150
- @cached_token = nil if force_refresh
150
+ generation = @generation
151
151
 
152
- # Double-check: another thread might have refreshed the token
153
- return @cached_token if token_valid?
152
+ @token_mutex.synchronize do
153
+ # Another thread already refreshed while we waited on the lock
154
+ return @cached_token if @generation != generation && token_valid?
154
155
 
155
156
  @cached_token = refresh
157
+ @generation += 1
156
158
 
157
159
  return @cached_token
158
160
  rescue StandardError => e
@@ -22,7 +22,30 @@ module Kessel
22
22
  fetch_workspace(rbac_base_endpoint, org_id, 'root', auth: auth, http_client: http_client)
23
23
  end
24
24
 
25
- def list_workspaces(inventory, subject, relation, continuation_token = nil)
25
+ # Lists all workspaces that a subject has a specific relation to.
26
+ #
27
+ # Pagination is handled automatically -- continuation tokens are managed
28
+ # internally. The returned +Enumerator+ is lazy; each page is fetched
29
+ # only when the next element is requested.
30
+ #
31
+ # @param inventory [Object] the inventory service client stub
32
+ # @param subject [SubjectReference] the subject to check permissions for
33
+ # @param relation [String] the relationship type (e.g. "member", "admin", "viewer")
34
+ # @param continuation_token [String, nil] optional token to resume listing
35
+ # @param consistency [Consistency, nil] optional consistency requirements for each request
36
+ # @return [Enumerator] a lazy enumerator of +StreamedListObjectsResponse+ objects
37
+ #
38
+ # @example Lazy iteration (constant memory)
39
+ # consistency = Kessel::Inventory::V1beta2::Consistency.new(minimize_latency: true)
40
+ # list_workspaces(inventory, subject, "viewer", consistency: consistency).each do |response|
41
+ # puts response.object.resource_id
42
+ # end
43
+ #
44
+ # @example Materialise into an Array (eager, all results in memory)
45
+ # consistency = Kessel::Inventory::V1beta2::Consistency.new(minimize_latency: true)
46
+ # all_workspaces = list_workspaces(inventory, subject, "viewer", consistency: consistency).to_a
47
+ #
48
+ def list_workspaces(inventory, subject, relation, continuation_token = nil, consistency: nil)
26
49
  Enumerator.new do |yielder|
27
50
  loop do
28
51
  request = StreamedListObjectsRequest.new(
@@ -32,7 +55,8 @@ module Kessel
32
55
  pagination: RequestPagination.new(
33
56
  limit: DEFAULT_PAGE_LIMIT,
34
57
  continuation_token: continuation_token
35
- )
58
+ ),
59
+ consistency: consistency
36
60
  )
37
61
 
38
62
  has_responses = false
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kessel
4
4
  module Inventory
5
- VERSION = '1.9.0'
5
+ VERSION = '1.10.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kessel-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Project Kessel
@@ -183,14 +183,14 @@ dependencies:
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 0.31.0
186
+ version: 0.32.0
187
187
  type: :development
188
188
  prerelease: false
189
189
  version_requirements: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - "~>"
192
192
  - !ruby/object:Gem::Version
193
- version: 0.31.0
193
+ version: 0.32.0
194
194
  description: This is the official Ruby SDK for [Project Kessel](https://github.com/project-kessel),
195
195
  a system for unifying APIs and experiences with fine-grained authorization, common
196
196
  inventory, and CloudEvents.