Class: KeycloakAdmin::ClientClient

Inherits:
Client
  • Object
show all
Defined in:
lib/keycloak-admin/client/client_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) ⇒ ClientClient

Returns a new instance of ClientClient.

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/keycloak-admin/client/client_client.rb', line 3

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

#clients_url(id = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/keycloak-admin/client/client_client.rb', line 59

def clients_url(id=nil)
  if id
    "#{@realm_client.realm_admin_url}/clients/#{id}"
  else
    "#{@realm_client.realm_admin_url}/clients"
  end
end

#delete(id) ⇒ Object



35
36
37
38
39
40
# File 'lib/keycloak-admin/client/client_client.rb', line 35

def delete(id)
  execute_http do
    RestClient::Resource.new(clients_url(id), @configuration.rest_client_options).delete(headers)
  end
  true
end

#find_by_client_id(client_id) ⇒ Object



31
32
33
# File 'lib/keycloak-admin/client/client_client.rb', line 31

def find_by_client_id(client_id)
  list.find { |client| client.client_id == client_id }
end

#get(id) ⇒ Object



9
10
11
12
13
14
# File 'lib/keycloak-admin/client/client_client.rb', line 9

def get(id)
  response = execute_http do
    RestClient::Resource.new(clients_url(id), @configuration.rest_client_options).get(headers)
  end
  ClientRepresentation.from_hash(JSON.parse(response))
end

#get_service_account_user(client_id) ⇒ Object



52
53
54
55
56
57
# File 'lib/keycloak-admin/client/client_client.rb', line 52

def (client_id)
  response = execute_http do
    RestClient::Resource.new((client_id), @configuration.rest_client_options).get(headers)
  end
  UserRepresentation.from_hash(JSON.parse(response))
end

#listObject



24
25
26
27
28
29
# File 'lib/keycloak-admin/client/client_client.rb', line 24

def list
  response = execute_http do
    RestClient::Resource.new(clients_url, @configuration.rest_client_options).get(headers)
  end
  JSON.parse(response).map { |client_as_hash| ClientRepresentation.from_hash(client_as_hash) }
end

#save(client_representation) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/keycloak-admin/client/client_client.rb', line 16

def save(client_representation)
  execute_http do
    RestClient::Resource.new(clients_url, @configuration.rest_client_options).post(
      create_payload(client_representation), headers
    )
  end
end

#service_account_user_url(client_id) ⇒ Object



67
68
69
# File 'lib/keycloak-admin/client/client_client.rb', line 67

def (client_id)
  "#{clients_url(client_id)}/service-account-user"
end

#update(client_representation) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/keycloak-admin/client/client_client.rb', line 42

def update(client_representation)
  execute_http do
    RestClient::Resource.new(clients_url(client_representation.id), @configuration.rest_client_options).put(
      create_payload(client_representation), headers
    )
  end

  get(client_representation.id)
end