Browse Source

fix: docs, lint etc

pull/506/head
Richard Nemeth 12 months ago
parent
commit
d3f4696eea
  1. 4
      src/keycloak/_version.py
  2. 6
      src/keycloak/connection.py
  3. 52
      src/keycloak/keycloak_admin.py
  4. 8
      src/keycloak/keycloak_openid.py
  5. 3
      src/keycloak/openid_connection.py
  6. 1
      src/keycloak/urls_patterns.py

4
src/keycloak/_version.py

@ -21,6 +21,6 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # 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. # 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")

6
src/keycloak/connection.py

@ -43,7 +43,8 @@ class ConnectionManager(object):
:type headers: dict :type headers: dict
:param timeout: Timeout to use for requests to the server. :param timeout: Timeout to use for requests to the server.
:type timeout: int :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] :type verify: Union[bool,str]
:param proxies: The proxies servers requests is sent by. :param proxies: The proxies servers requests is sent by.
:type proxies: dict :type proxies: dict
@ -58,7 +59,8 @@ class ConnectionManager(object):
:type headers: dict :type headers: dict
:param timeout: Timeout to use for requests to the server. :param timeout: Timeout to use for requests to the server.
:type timeout: int :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] :type verify: Union[bool,str]
:param proxies: The proxies servers requests is sent by. :param proxies: The proxies servers requests is sent by.
:type proxies: dict :type proxies: dict

52
src/keycloak/keycloak_admin.py

@ -63,7 +63,8 @@ class KeycloakAdmin:
:type realm_name: str :type realm_name: str
:param client_id: client id :param client_id: client id
:type client_id: str :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] :type verify: Union[bool,str]
:param client_secret_key: client secret key :param client_secret_key: client secret key
(optional, required only for access type confidential) (optional, required only for access type confidential)
@ -119,7 +120,8 @@ class KeycloakAdmin:
:type realm_name: str :type realm_name: str
:param client_id: client id :param client_id: client id
:type client_id: str :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] :type verify: Union[bool,str]
:param client_secret_key: client secret key :param client_secret_key: client secret key
(optional, required only for access type confidential) (optional, required only for access type confidential)
@ -1239,7 +1241,7 @@ class KeycloakAdmin:
return raise_error_from_response(data_raw, KeycloakGetError) return raise_error_from_response(data_raw, KeycloakGetError)
def get_server_info(self): 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 ServerInfoRepresentation
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_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 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): def get_client_authz_scopes(self, client_id):
"""Get scopes from client. """Get scopes from client.
@ -4272,7 +4232,7 @@ class KeycloakAdmin:
urls_patterns.URL_ADMIN_ADD_CLIENT_AUTHZ_SCOPE_PERMISSION.format(**params_path), urls_patterns.URL_ADMIN_ADD_CLIENT_AUTHZ_SCOPE_PERMISSION.format(**params_path),
data=json.dumps(payload), 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): def update_client_authz_scope_permission(self, payload, client_id, scope_id):
"""Update permissions for a given scope. """Update permissions for a given scope.

8
src/keycloak/keycloak_openid.py

@ -69,7 +69,8 @@ class KeycloakOpenID:
:param client_id: client id :param client_id: client id
:param realm_name: realm name :param realm_name: realm name
:param client_secret_key: client secret key :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 custom_headers: dict of custom header to pass to each HTML request
:param proxies: dict of proxies to sent the request by. :param proxies: dict of proxies to sent the request by.
:param timeout: connection timeout in seconds :param timeout: connection timeout in seconds
@ -96,7 +97,8 @@ class KeycloakOpenID:
:type realm_name: str :type realm_name: str
:param client_secret_key: client secret key :param client_secret_key: client secret key
:type client_secret_key: str :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] :type verify: Union[bool,str]
:param custom_headers: dict of custom header to pass to each HTML request :param custom_headers: dict of custom header to pass to each HTML request
:type custom_headers: dict :type custom_headers: dict
@ -715,7 +717,6 @@ class KeycloakOpenID:
) )
return raise_error_from_response(data_raw, KeycloakPostError) return raise_error_from_response(data_raw, KeycloakPostError)
def device(self): def device(self):
"""Get device authorization grant. """Get device authorization grant.
@ -743,7 +744,6 @@ class KeycloakOpenID:
data_raw = self.connection.raw_post(URL_DEVICE.format(**params_path), data=payload) data_raw = self.connection.raw_post(URL_DEVICE.format(**params_path), data=payload)
return raise_error_from_response(data_raw, KeycloakPostError) return raise_error_from_response(data_raw, KeycloakPostError)
def update_client(self, token: str, client_id: str, payload: dict): def update_client(self, token: str, client_id: str, payload: dict):
"""Update a client. """Update a client.

3
src/keycloak/openid_connection.py

@ -87,7 +87,8 @@ class KeycloakOpenIDConnection(ConnectionManager):
:type realm_name: str :type realm_name: str
:param client_id: client id :param client_id: client id
:type client_id: str :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] :type verify: Union[bool,str]
:param client_secret_key: client secret key :param client_secret_key: client secret key
(optional, required only for access type confidential) (optional, required only for access type confidential)

1
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_RESOURCE_BASED_PERMISSION = (
URL_ADMIN_CLIENT_AUTHZ + "/permission/resource?max=-1" 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 = URL_ADMIN_CLIENT_AUTHZ + "/policy/{policy-id}"
URL_ADMIN_CLIENT_AUTHZ_POLICY_SCOPES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/scopes" URL_ADMIN_CLIENT_AUTHZ_POLICY_SCOPES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/scopes"
URL_ADMIN_CLIENT_AUTHZ_POLICY_RESOURCES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/resources" URL_ADMIN_CLIENT_AUTHZ_POLICY_RESOURCES = URL_ADMIN_CLIENT_AUTHZ_POLICY + "/resources"

Loading…
Cancel
Save