Browse Source

Fixed docstring.

hotfix/merge
Marcos Pereira 6 years ago
parent
commit
3e60e7469b
  1. 4
      keycloak/authorization/__init__.py
  2. 32
      keycloak/keycloak_admin.py
  3. 1
      keycloak/keycloak_openid.py
  4. 6
      keycloak/urls_patterns.py

4
keycloak/authorization/__init__.py

@ -75,13 +75,15 @@ class Authorization:
self.policies[policy_name].add_permission(permission)
if pol['type'] == 'resource':
from pprint import pprint
permission = Permission(name=pol['name'],
type=pol['type'],
logic=pol['logic'],
decision_strategy=pol['decisionStrategy'])
permission.resources = ast.literal_eval(pol['config']['resources'])
permission.resources = ast.literal_eval(pol['config'].get('resources', "[]"))
for policy_name in ast.literal_eval(pol['config']['applyPolicies']):
if self.policies.get(policy_name) is not None:
self.policies[policy_name].add_permission(permission)

32
keycloak/keycloak_admin.py

@ -24,7 +24,8 @@ from .urls_patterns import \
URL_ADMIN_SEND_UPDATE_ACCOUNT, URL_ADMIN_RESET_PASSWORD, URL_ADMIN_SEND_VERIFY_EMAIL, URL_ADMIN_GET_SESSIONS, \
URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENTS, URL_ADMIN_CLIENT, URL_ADMIN_CLIENT_ROLES, URL_ADMIN_REALM_ROLES, \
URL_ADMIN_GROUP, URL_ADMIN_GROUPS, URL_ADMIN_GROUP_CHILD, URL_ADMIN_USER_GROUP, URL_ADMIN_GROUP_MEMBERS, \
URL_ADMIN_USER_GROUPS, URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_USER_CLIENT_ROLES, URL_ADMIN_USER_STORAGE
URL_ADMIN_USER_GROUPS, URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_USER_CLIENT_ROLES, URL_ADMIN_USER_STORAGE, \
URL_ADMIN_CLIENT_AUTHZ_SETTINGS, URL_ADMIN_CLIENT_AUTHZ_RESOURCES, URL_ADMIN_IDPS
from .keycloak_openid import KeycloakOpenID
@ -556,17 +557,44 @@ class KeycloakAdmin:
clients = self.get_clients()
for client in clients:
if client_name == client['name']:
if client_name == client.get('name') or client_name == client.get('clientId'):
return client["id"]
return None
def get_client_authz_settings(self, client_id):
"""
Get authorization json from client.
:param client_id: id in ClientRepresentation
http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_clientrepresentation
:return: Keycloak server response
"""
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.connection.raw_get(URL_ADMIN_CLIENT_AUTHZ_SETTINGS.format(**params_path))
return data_raw
def get_client_authz_resources(self, client_id):
"""
Get resources from client.
:param client_id: id in ClientRepresentation
http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_clientrepresentation
:return: Keycloak server response
"""
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.connection.raw_get(URL_ADMIN_CLIENT_AUTHZ_RESOURCES.format(**params_path))
return data_raw
def create_client(self, payload, skip_exists=False):
"""
Create a client
ClientRepresentation: http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_clientrepresentation
:param skip_exists: Skip if client already exist.
:param payload: ClientRepresentation
:return: Keycloak server response (UserRepresentation)
"""

1
keycloak/keycloak_openid.py

@ -391,3 +391,4 @@ class KeycloakOpenID:
permissions += policy.permissions
return list(set(permissions))

6
keycloak/urls_patterns.py

@ -50,9 +50,15 @@ URL_ADMIN_CLIENTS = "admin/realms/{realm-name}/clients"
URL_ADMIN_CLIENT = "admin/realms/{realm-name}/clients/{id}"
URL_ADMIN_CLIENT_ROLES = "admin/realms/{realm-name}/clients/{id}/roles"
URL_ADMIN_CLIENT_ROLE = "admin/realms/{realm-name}/clients/{id}/roles/{role-name}"
URL_ADMIN_CLIENT_AUTHZ_SETTINGS = "admin/realms/{realm-name}/clients/{id}/authz/resource-server/settings"
URL_ADMIN_CLIENT_AUTHZ_RESOURCES = "admin/realms/{realm-name}/clients/{id}/authz/resource-server/resource"
URL_ADMIN_CLIENT_CERTS = "admin/realms/{realm-name}/clients/{id}/certificates/{attr}"
URL_ADMIN_REALM_ROLES = "admin/realms/{realm-name}/roles"
URL_ADMIN_USER_STORAGE = "admin/realms/{realm-name}/user-storage/{id}/sync"
<<<<<<< HEAD
URL_ADMIN_IDPS = "admin/realms/{realm}/identity-provider/instances"
=======
>>>>>>> remotes/njordr/python-keycloak/master
Loading…
Cancel
Save