Skip to content

Commit

Permalink
Update keycloak_client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-pimenta-DME committed Nov 16, 2023
1 parent 4d51c38 commit 8534344
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions identityutils/keycloak_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import json
import logging
import os
from keycloak import KeycloakOpenID, KeycloakOpenIDConnection, KeycloakAdmin, KeycloakUMA, ConnectionManager, \
urls_patterns
from keycloak import KeycloakOpenIDConnection, KeycloakAdmin, urls_patterns
from keycloak.exceptions import raise_error_from_response, KeycloakGetError, KeycloakPostError, KeycloakPutError

logger = logging.getLogger('um-identity-service')



class KeycloakClient:

def __init__(self, server_url, realm, username, password):
Expand Down Expand Up @@ -217,15 +213,6 @@ def register_general_policy(self, policy, client_id, policy_type):
data_raw, KeycloakPostError, expected_codes=[201, 409], skip_exists=True
)

def register_general_policy(self, policy, client_id, policy_type):
_client_id = self.keycloak_admin.get_client_id(client_id)
params_path = {"realm-name": self.realm, "id": _client_id}
url = urls_patterns.URL_ADMIN_CLIENT_AUTHZ + "/policy/" + policy_type + "?max=-1"
data_raw = self.keycloak_admin.raw_post(url.format(**params_path), data=json.dumps(policy))
return raise_error_from_response(
data_raw, KeycloakPostError, expected_codes=[201, 409], skip_exists=True
)

def assign_resources_permissions(self, permissions, client_id):
if not isinstance(permissions, list):
permissions = [permissions]
Expand Down Expand Up @@ -506,5 +493,4 @@ def delete_resource_permissions(self, client_id, permission_id):
)

def create_client(self, payload, skip_exists=True):
return self.keycloak_admin.create_client(payload=payload, skip_exists=skip_exists)

return self.keycloak_admin.create_client(payload=payload, skip_exists=skip_exists)

0 comments on commit 8534344

Please sign in to comment.