From d3f4696eeaa782b10c67be9204fb5bd233d15001 Mon Sep 17 00:00:00 2001 From: Richard Nemeth Date: Mon, 13 Nov 2023 13:18:49 +0000 Subject: [PATCH] fix: docs, lint etc --- src/keycloak/_version.py | 4 +-- src/keycloak/connection.py | 6 ++-- src/keycloak/keycloak_admin.py | 52 ++++--------------------------- src/keycloak/keycloak_openid.py | 8 ++--- src/keycloak/openid_connection.py | 3 +- src/keycloak/urls_patterns.py | 1 - 6 files changed, 18 insertions(+), 56 deletions(-) diff --git a/src/keycloak/_version.py b/src/keycloak/_version.py index d6030e7..8ebd529 100644 --- a/src/keycloak/_version.py +++ b/src/keycloak/_version.py @@ -21,6 +21,6 @@ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import pkg_resources +from importlib import metadata -__version__ = pkg_resources.get_distribution("python-keycloak").version +__version__ = metadata.version("python-keycloak") diff --git a/src/keycloak/connection.py b/src/keycloak/connection.py index 63918fe..0dfeaff 100644 --- a/src/keycloak/connection.py +++ b/src/keycloak/connection.py @@ -43,7 +43,8 @@ class ConnectionManager(object): :type headers: dict :param timeout: Timeout to use for requests to the server. :type timeout: int - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param proxies: The proxies servers requests is sent by. :type proxies: dict @@ -58,7 +59,8 @@ class ConnectionManager(object): :type headers: dict :param timeout: Timeout to use for requests to the server. :type timeout: int - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param proxies: The proxies servers requests is sent by. :type proxies: dict diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index d9f65c0..88637d2 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -63,7 +63,8 @@ class KeycloakAdmin: :type realm_name: str :param client_id: client id :type client_id: str - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param client_secret_key: client secret key (optional, required only for access type confidential) @@ -119,7 +120,8 @@ class KeycloakAdmin: :type realm_name: str :param client_id: client id :type client_id: str - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param client_secret_key: client secret key (optional, required only for access type confidential) @@ -1239,7 +1241,7 @@ class KeycloakAdmin: return raise_error_from_response(data_raw, KeycloakGetError) def get_server_info(self): - """Get themes, social providers, auth providers, and event listeners available on this server. + """Get themes, social providers, etc. on this server. ServerInfoRepresentation https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_serverinforepresentation @@ -1783,48 +1785,6 @@ class KeycloakAdmin: data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists ) - def create_client_authz_scope_based_permission(self, client_id, payload, skip_exists=False): - """Create scope-based permission of client. - - Payload example:: - - payload={ - "type": "resource", - "logic": "POSITIVE", - "decisionStrategy": "UNANIMOUS", - "name": "Permission-Name", - "resources": [ - resource_id - ], - "policies": [ - policy_id - ], - "scopes": [ - scope_id - ] - - :param client_id: id in ClientRepresentation - https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_clientrepresentation - :type client_id: str - :param payload: PolicyRepresentation - https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_policyrepresentation - :type payload: dict - :param skip_exists: Skip creation in case the object already exists - :type skip_exists: bool - :return: Keycloak server response - :rtype: bytes - - """ - params_path = {"realm-name": self.realm_name, "id": client_id} - - data_raw = self.connection.raw_post( - urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPE_BASED_PERMISSION.format(**params_path), - data=json.dumps(payload), - ) - return raise_error_from_response( - data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists - ) - def get_client_authz_scopes(self, client_id): """Get scopes from client. @@ -4272,7 +4232,7 @@ class KeycloakAdmin: urls_patterns.URL_ADMIN_ADD_CLIENT_AUTHZ_SCOPE_PERMISSION.format(**params_path), data=json.dumps(payload), ) - return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[201]) + return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201]) def update_client_authz_scope_permission(self, payload, client_id, scope_id): """Update permissions for a given scope. diff --git a/src/keycloak/keycloak_openid.py b/src/keycloak/keycloak_openid.py index 8431f6f..7884699 100644 --- a/src/keycloak/keycloak_openid.py +++ b/src/keycloak/keycloak_openid.py @@ -69,7 +69,8 @@ class KeycloakOpenID: :param client_id: client id :param realm_name: realm name :param client_secret_key: client secret key - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :param custom_headers: dict of custom header to pass to each HTML request :param proxies: dict of proxies to sent the request by. :param timeout: connection timeout in seconds @@ -96,7 +97,8 @@ class KeycloakOpenID: :type realm_name: str :param client_secret_key: client secret key :type client_secret_key: str - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param custom_headers: dict of custom header to pass to each HTML request :type custom_headers: dict @@ -715,7 +717,6 @@ class KeycloakOpenID: ) return raise_error_from_response(data_raw, KeycloakPostError) - def device(self): """Get device authorization grant. @@ -743,7 +744,6 @@ class KeycloakOpenID: data_raw = self.connection.raw_post(URL_DEVICE.format(**params_path), data=payload) return raise_error_from_response(data_raw, KeycloakPostError) - def update_client(self, token: str, client_id: str, payload: dict): """Update a client. diff --git a/src/keycloak/openid_connection.py b/src/keycloak/openid_connection.py index c7141fe..c41af1c 100644 --- a/src/keycloak/openid_connection.py +++ b/src/keycloak/openid_connection.py @@ -87,7 +87,8 @@ class KeycloakOpenIDConnection(ConnectionManager): :type realm_name: str :param client_id: client id :type client_id: str - :param verify: Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use + :param verify: Boolean value to enable or disable certificate validation or a string + containing a path to a CA bundle to use :type verify: Union[bool,str] :param client_secret_key: client secret key (optional, required only for access type confidential) diff --git a/src/keycloak/urls_patterns.py b/src/keycloak/urls_patterns.py index a931c59..0531bd8 100644 --- a/src/keycloak/urls_patterns.py +++ b/src/keycloak/urls_patterns.py @@ -122,7 +122,6 @@ URL_ADMIN_CLIENT_AUTHZ_ROLE_BASED_POLICY = URL_ADMIN_CLIENT_AUTHZ + "/policy/rol URL_ADMIN_CLIENT_AUTHZ_RESOURCE_BASED_PERMISSION = ( URL_ADMIN_CLIENT_AUTHZ + "/permission/resource?max=-1" ) -URL_ADMIN_CLIENT_AUTHZ_SCOPE_BASED_PERMISSION = URL_ADMIN_CLIENT_AUTHZ + "/permission/scope?max=-1" URL_ADMIN_CLIENT_AUTHZ_POLICY = URL_ADMIN_CLIENT_AUTHZ + "/policy/{policy-id}" URL_ADMIN_CLIENT_AUTHZ_POLICY_SCOPES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/scopes" URL_ADMIN_CLIENT_AUTHZ_POLICY_RESOURCES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/resources"