Class: KeycloakAdmin::RoleClient
- Inherits:
-
Client
- Object
- Client
- KeycloakAdmin::RoleClient
show all
- Defined in:
- lib/keycloak-admin/client/role_client.rb
Instance Method Summary
collapse
Methods inherited from Client
#create_payload, #created_id, #current_token, #execute_http, #headers, #server_url
Constructor Details
#initialize(configuration, realm_client) ⇒ RoleClient
Returns a new instance of RoleClient.
4
5
6
7
8
|
# File 'lib/keycloak-admin/client/role_client.rb', line 4
def initialize(configuration, realm_client)
super(configuration)
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
@realm_client = realm_client
end
|
Instance Method Details
#get(name) ⇒ Object
Returns the role representation for the specified role name
18
19
20
21
22
23
|
# File 'lib/keycloak-admin/client/role_client.rb', line 18
def get(name)
response = execute_http do
resource(role_name_url(name)).get()
end
RoleRepresentation.from_hash JSON.parse(response)
end
|
#list ⇒ Object
10
11
12
13
14
15
|
# File 'lib/keycloak-admin/client/role_client.rb', line 10
def list
response = execute_http do
resource(roles_url).get()
end
JSON.parse(response).map { |role_as_hash| RoleRepresentation.from_hash(role_as_hash) }
end
|
#list_groups(name) ⇒ Object
Lists all groups that have the specified role name assigned
26
27
28
29
30
31
|
# File 'lib/keycloak-admin/client/role_client.rb', line 26
def list_groups(name)
response = execute_http do
resource("#{role_name_url(name)}/groups").get()
end
JSON.parse(response).map { |role_as_hash| GroupRepresentation.from_hash(role_as_hash) }
end
|
#role_id_url(id) ⇒ Object
48
49
50
|
# File 'lib/keycloak-admin/client/role_client.rb', line 48
def role_id_url(id)
"#{@realm_client.realm_admin_url}/roles-by-id/#{encode_segment(id)}"
end
|
#role_name_url(name) ⇒ Object
52
53
54
|
# File 'lib/keycloak-admin/client/role_client.rb', line 52
def role_name_url(name)
"#{@realm_client.realm_admin_url}/roles/#{encode_segment(name)}"
end
|
#roles_url ⇒ Object
44
45
46
|
# File 'lib/keycloak-admin/client/role_client.rb', line 44
def roles_url
"#{@realm_client.realm_admin_url}/roles"
end
|
#save(role_representation) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/keycloak-admin/client/role_client.rb', line 33
def save(role_representation)
execute_http do
payload = create_payload(role_representation)
if role_representation.id
resource(role_id_url(role_representation.id)).put(payload, )
else
resource(roles_url).post(payload, )
end
end
end
|