kessel-sdk 1.3.0 → 1.4.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: 03c1e365bed3b3630e895a51b7dc31ce2ea261df747b13792b27fee2425b1d92
4
- data.tar.gz: 206abbac137b487acdb9d33e30cd0fd597d6bc2a04a7115c718e84a606f17875
3
+ metadata.gz: 2e2b24045b21b41dc888f7ce2c81efefbb882e7c81b9e747e1587d11bed3882e
4
+ data.tar.gz: 906ce22a27644bacd76e79a30257d463dd73ae0d46ccf784133adc545979bb4a
5
5
  SHA512:
6
- metadata.gz: 4ff107f891cfa1b12b71908ca3783b9db9064b0695c29de7790462550148ef2c58c2e5e81e90f5a62d2791da7e446335c898b0fa0f155a39b8e6fe875099db04
7
- data.tar.gz: 4e5c268ae1cdcf9db41910b9ccf5ffc812f0e73ce6a8fc5f67e605e4bb54d0edc27f10dc8c3e6f4463f7071f277c077a3b7765d7302b3863888b84ad6349526f
6
+ metadata.gz: 3a072b07ce4021d603045744b35d68680a53ef492e2bc7839706ca5402ffe024105399a8e5a1b835f22d93e4c3be1029a0331aa05b3a3695e7a457481b1094f8
7
+ data.tar.gz: 884484eb24a3ce17829bcc370712201bd593770f4a673e914671f47d70582c13dc60e79b9ab80c96804277b3cc8372fa791e5bca4c2aa499a716ee056f835636
@@ -3,11 +3,17 @@
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
  require 'json'
6
+ require_relative 'v2_helpers'
7
+ require_relative 'v2_http'
8
+ require_relative '../inventory/v1beta2'
6
9
 
7
10
  module Kessel
8
11
  module RBAC
9
12
  module V2
13
+ include Kessel::Inventory::V1beta2
14
+
10
15
  WORKSPACE_ENDPOINT = '/api/rbac/v2/workspaces/'
16
+ DEFAULT_PAGE_LIMIT = 1000
11
17
  Workspace = Struct.new(:id, :name, :type, :description)
12
18
 
13
19
  def fetch_default_workspace(rbac_base_endpoint, org_id, auth: nil, http_client: nil)
@@ -18,17 +24,35 @@ module Kessel
18
24
  fetch_workspace(rbac_base_endpoint, org_id, 'root', auth: auth, http_client: http_client)
19
25
  end
20
26
 
21
- private
22
-
23
- def run_request(uri, org_id, auth, http_client)
24
- request = Net::HTTP::Get.new uri
25
- request['x-rh-rbac-org-id'] = org_id
26
-
27
- auth&.configure_request(request)
28
-
29
- http_client.request(request)
27
+ def list_workspaces(inventory, subject, relation, continuation_token = nil)
28
+ Enumerator.new do |yielder|
29
+ loop do
30
+ request = StreamedListObjectsRequest.new(
31
+ object_type: workspace_type,
32
+ relation: relation,
33
+ subject: subject,
34
+ pagination: RequestPagination.new(
35
+ limit: DEFAULT_PAGE_LIMIT,
36
+ continuation_token: continuation_token
37
+ )
38
+ )
39
+
40
+ has_responses = false
41
+ streamed_response = inventory.streamed_list_objects(request)
42
+ streamed_response.each do |response|
43
+ has_responses = true
44
+ yielder << response
45
+
46
+ continuation_token = response&.pagination&.continuation_token
47
+ end
48
+
49
+ break if !has_responses || !continuation_token
50
+ end
51
+ end
30
52
  end
31
53
 
54
+ private
55
+
32
56
  def process_response(response, workspace_type)
33
57
  unless response.is_a?(Net::HTTPSuccess)
34
58
  raise "Error while fetching the workspace of type #{workspace_type}. " \
@@ -70,12 +94,6 @@ module Kessel
70
94
  response = run_request(uri, org_id, auth, http_client)
71
95
  process_response(response, workspace_type)
72
96
  end
73
-
74
- def check_http_client(http_client, uri)
75
- return if uri.host == http_client.address && uri.port == http_client.port
76
-
77
- raise 'http client host and port do not match rbac_base_endpoint'
78
- end
79
97
  end
80
98
  end
81
99
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kessel
4
+ module RBAC
5
+ module V2
6
+ def workspace_type
7
+ RepresentationType.new(
8
+ resource_type: 'workspace',
9
+ reporter_type: 'rbac'
10
+ )
11
+ end
12
+
13
+ def role_type
14
+ RepresentationType.new(
15
+ resource_type: 'role',
16
+ reporter_type: 'rbac'
17
+ )
18
+ end
19
+
20
+ def principal_resource(id, domain)
21
+ ResourceReference.new(
22
+ resource_type: 'principal',
23
+ resource_id: "#{domain}/#{id}",
24
+ reporter: ReporterReference.new(
25
+ type: 'rbac'
26
+ )
27
+ )
28
+ end
29
+
30
+ def role_resource(resource_id)
31
+ ResourceReference.new(
32
+ resource_type: 'role',
33
+ resource_id: resource_id,
34
+ reporter: ReporterReference.new(
35
+ type: 'rbac'
36
+ )
37
+ )
38
+ end
39
+
40
+ def workspace_resource(resource_id)
41
+ ResourceReference.new(
42
+ resource_type: 'workspace',
43
+ resource_id: resource_id,
44
+ reporter: ReporterReference.new(
45
+ type: 'rbac'
46
+ )
47
+ )
48
+ end
49
+
50
+ def principal_subject(id, domain)
51
+ SubjectReference.new(
52
+ resource: principal_resource(id, domain)
53
+ )
54
+ end
55
+
56
+ def subject(resource_ref, relation = nil)
57
+ SubjectReference.new(
58
+ resource: resource_ref,
59
+ relation: relation
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kessel
4
+ module RBAC
5
+ module V2
6
+ private
7
+
8
+ def run_request(uri, org_id, auth, http_client)
9
+ request = Net::HTTP::Get.new uri
10
+ request['x-rh-rbac-org-id'] = org_id
11
+
12
+ auth&.configure_request(request)
13
+
14
+ http_client.request(request)
15
+ end
16
+
17
+ def check_http_client(http_client, uri)
18
+ return if uri.host == http_client.address && uri.port == http_client.port
19
+
20
+ raise 'http client host and port do not match rbac_base_endpoint'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kessel
4
4
  module Inventory
5
- VERSION = '1.3.0'
5
+ VERSION = '1.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kessel-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Project Kessel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-01 00:00:00.000000000 Z
11
+ date: 2025-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -261,6 +261,8 @@ files:
261
261
  - lib/kessel/inventory/v1beta2/subject_reference_pb.rb
262
262
  - lib/kessel/inventory/v1beta2/write_visibility_pb.rb
263
263
  - lib/kessel/rbac/v2.rb
264
+ - lib/kessel/rbac/v2_helpers.rb
265
+ - lib/kessel/rbac/v2_http.rb
264
266
  - lib/kessel/version.rb
265
267
  homepage: https://github.com/project-kessel/kessel-sdk-ruby
266
268
  licenses: