keycloak-admin 1.0.19 → 1.0.20
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/CHANGELOG.md +8 -2
- data/Gemfile.lock +3 -3
- data/README.md +11 -1
- data/lib/keycloak-admin/client/group_client.rb +10 -0
- data/lib/keycloak-admin/representation/group_representation.rb +7 -5
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +2 -0
- data/lib/keycloak-admin/version.rb +1 -1
- data/spec/client/group_client_spec.rb +19 -8
- data/spec/representation/group_representation_spec.rb +15 -0
- data/spec/spec_helper.rb +9 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e12b29d601e1a543c15d2d23820a1834088d4ab03fdde20ab81905ee0236309
|
4
|
+
data.tar.gz: 1d42e0333e35bf0c6faca2a1439533f2a35d5e85a0494b2fa0901d98b37ae99e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74e45f56d4ec1adca533d8c41fc9ae519a359a63c3632560c17fb927425b5e0f1e22519b6d8c99894b034acdd8c3b7a1229430a95a00e42fa024376b72bd8298
|
7
|
+
data.tar.gz: 662228969795e4fa165be24480714e662ac4e178c5ad1e3eaae14be90ffd245796db80bd0bedb02761e8d228a7b023dd426b52884029de449ebf2f8a02e7a8d9
|
data/CHANGELOG.md
CHANGED
@@ -5,10 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [1.0.20] - 2022-12-26
|
9
|
+
|
10
|
+
* Create subgroups (thanks to @neckhair)
|
11
|
+
* Add subgroups to `GroupRepresentation` (thanks to @neckhair)
|
12
|
+
* Expose `BaseRoleContainingResource.resource_id` (thanks to @neckhair)
|
13
|
+
|
8
14
|
## [1.0.19] - 2022-12-03
|
9
15
|
|
10
|
-
* Remove specific realm roles from user (thanks to @
|
11
|
-
* Get role by name (thanks to @
|
16
|
+
* Remove specific realm roles from user (thanks to @tlloydthwaites)
|
17
|
+
* Get role by name (thanks to @tlloydthwaites)
|
12
18
|
|
13
19
|
## [1.0.18] - 2022-11-24
|
14
20
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
keycloak-admin (1.0.
|
4
|
+
keycloak-admin (1.0.20)
|
5
5
|
http-cookie (~> 1.0, >= 1.0.3)
|
6
6
|
rest-client (~> 2.1)
|
7
7
|
|
@@ -30,10 +30,10 @@ GEM
|
|
30
30
|
rspec-mocks (~> 3.12.0)
|
31
31
|
rspec-core (3.12.0)
|
32
32
|
rspec-support (~> 3.12.0)
|
33
|
-
rspec-expectations (3.12.
|
33
|
+
rspec-expectations (3.12.1)
|
34
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
35
|
rspec-support (~> 3.12.0)
|
36
|
-
rspec-mocks (3.12.
|
36
|
+
rspec-mocks (3.12.1)
|
37
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
38
|
rspec-support (~> 3.12.0)
|
39
39
|
rspec-support (3.12.0)
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ This gem *does not* require Rails.
|
|
12
12
|
For example, using `bundle`, add this line to your Gemfile.
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem "keycloak-admin", "1.0.
|
15
|
+
gem "keycloak-admin", "1.0.20"
|
16
16
|
```
|
17
17
|
|
18
18
|
## Login
|
@@ -310,6 +310,16 @@ group_path = "/top"
|
|
310
310
|
group_id = KeycloakAdmin.realm("a_realm").groups.create!(group_name, group_path)
|
311
311
|
```
|
312
312
|
|
313
|
+
### Create a new subgroup of an existing group
|
314
|
+
|
315
|
+
Create a new group as the child of an existing group.
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
parent_id = "7686af34-204c-4515-8122-78d19febbf6e"
|
319
|
+
group_name = "test"
|
320
|
+
sub_group_id = KeycloakAdmin.realm("a_realm").groups.create_subgroup!(parent_id, group_name)
|
321
|
+
```
|
322
|
+
|
313
323
|
### Get list of roles in a realm
|
314
324
|
|
315
325
|
Returns an array of `KeycloakAdmin::RoleRepresentation`.
|
@@ -26,6 +26,16 @@ module KeycloakAdmin
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def create_subgroup!(parent_id, name)
|
30
|
+
url = "#{groups_url(parent_id)}/children"
|
31
|
+
response = execute_http do
|
32
|
+
RestClient::Resource.new(url, @configuration.rest_client_options).post(
|
33
|
+
create_payload(build(name, nil)), headers
|
34
|
+
)
|
35
|
+
end
|
36
|
+
created_id(response)
|
37
|
+
end
|
38
|
+
|
29
39
|
def groups_url(id=nil)
|
30
40
|
if id
|
31
41
|
"#{@realm_client.realm_admin_url}/groups/#{id}"
|
@@ -2,13 +2,15 @@ module KeycloakAdmin
|
|
2
2
|
class GroupRepresentation < Representation
|
3
3
|
attr_accessor :id,
|
4
4
|
:name,
|
5
|
-
:path
|
5
|
+
:path,
|
6
|
+
:sub_groups
|
6
7
|
|
7
8
|
def self.from_hash(hash)
|
8
|
-
group
|
9
|
-
group.id
|
10
|
-
group.name
|
11
|
-
group.path
|
9
|
+
group = new
|
10
|
+
group.id = hash["id"]
|
11
|
+
group.name = hash["name"]
|
12
|
+
group.path = hash["path"]
|
13
|
+
group.sub_groups = hash.fetch("subGroups", []).map { |sub_group_hash| self.from_hash(sub_group_hash) }
|
12
14
|
group
|
13
15
|
end
|
14
16
|
end
|
@@ -111,15 +111,26 @@ RSpec.describe KeycloakAdmin::GroupClient do
|
|
111
111
|
'Create method returned status OK (Code: 200); expected status: Created (201)'
|
112
112
|
)
|
113
113
|
end
|
114
|
+
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
describe "#create_subgroup!" do
|
117
|
+
let(:realm_name) { "valid-realm" }
|
118
|
+
|
119
|
+
before(:each) do
|
120
|
+
@group_client = KeycloakAdmin.realm(realm_name).groups
|
121
|
+
|
122
|
+
stub_token_client
|
123
|
+
@response = double headers: {
|
124
|
+
location: 'http://auth.service.io/auth/admin/realms/valid-realm/groups/7686af34-204c-4515-8122-78d19febbf6e'
|
125
|
+
}
|
126
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return @response
|
127
|
+
end
|
128
|
+
|
129
|
+
it "creates a subgroup" do
|
130
|
+
stub_net_http_res(Net::HTTPCreated, 201, 'Created')
|
131
|
+
|
132
|
+
group_id = @group_client.create_subgroup!('be061c48-6edd-4783-a726-1a57d4bfa22b', 'subgroup-name')
|
133
|
+
expect(group_id).to eq '7686af34-204c-4515-8122-78d19febbf6e'
|
123
134
|
end
|
124
135
|
end
|
125
136
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
RSpec.describe KeycloakAdmin::GroupRepresentation do
|
3
|
+
describe ".from_hash" do
|
4
|
+
it "parses the sub groups into group representations" do
|
5
|
+
group = described_class.from_hash({
|
6
|
+
"name" => "group a",
|
7
|
+
"subGroups" => [{
|
8
|
+
"name" => "subgroup b"
|
9
|
+
}]
|
10
|
+
})
|
11
|
+
expect(group.sub_groups.length).to eq 1
|
12
|
+
expect(group.sub_groups.first).to be_a described_class
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ def configure
|
|
10
10
|
config.client_secret = "aaaaaaaa"
|
11
11
|
config.client_realm_name = "master2"
|
12
12
|
config.use_service_account = true
|
13
|
-
end
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
RSpec.configure do |config|
|
@@ -27,3 +27,11 @@ def stub_token_client
|
|
27
27
|
'refresh_expires_in', 'id_token', 'not_before_policy', 'session_state'
|
28
28
|
)
|
29
29
|
end
|
30
|
+
|
31
|
+
def stub_net_http_res(res_class, code, message)
|
32
|
+
net_http_res = double(message: message, code: code)
|
33
|
+
allow(net_http_res).to receive(:is_a?) do |target_class|
|
34
|
+
target_class == res_class
|
35
|
+
end
|
36
|
+
allow(@response).to receive(:net_http_res).and_return(net_http_res)
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorent Lempereur
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-cookie
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- spec/client/user_client_spec.rb
|
135
135
|
- spec/configuration_spec.rb
|
136
136
|
- spec/representation/client_representation_spec.rb
|
137
|
+
- spec/representation/group_representation_spec.rb
|
137
138
|
- spec/representation/identity_provider_mapper_representation_spec.rb
|
138
139
|
- spec/representation/identity_provider_representation_spec.rb
|
139
140
|
- spec/representation/impersonation_representation_spec.rb
|
@@ -147,7 +148,7 @@ homepage: https://github.com/looorent/keycloak-admin-ruby
|
|
147
148
|
licenses:
|
148
149
|
- MIT
|
149
150
|
metadata: {}
|
150
|
-
post_install_message:
|
151
|
+
post_install_message:
|
151
152
|
rdoc_options: []
|
152
153
|
require_paths:
|
153
154
|
- lib
|
@@ -162,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
163
|
- !ruby/object:Gem::Version
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
166
|
-
signing_key:
|
166
|
+
rubygems_version: 3.0.3.1
|
167
|
+
signing_key:
|
167
168
|
specification_version: 4
|
168
169
|
summary: Keycloak Admin REST API client written in Ruby
|
169
170
|
test_files: []
|