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 +4 -4
- data/README.md +15 -2
- data/lib/kessel/auth.rb +6 -4
- data/lib/kessel/rbac/v2.rb +26 -2
- data/lib/kessel/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 136206dbccfc87a36252fa0b635f195d00ebc861f9d26c3a35095403257e971c
|
|
4
|
+
data.tar.gz: 6e1366c5ed2fc78316fd7804f4ff31ac59819817e919fda84e689c7c8023f980
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
208
|
-
|
|
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
|
-
@
|
|
150
|
-
@cached_token = nil if force_refresh
|
|
150
|
+
generation = @generation
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
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
|
data/lib/kessel/rbac/v2.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/kessel/version.rb
CHANGED
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.
|
|
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.
|
|
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.
|
|
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.
|