Skip to content
Snippets Groups Projects
Commit f410ec4b authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-2813: adapt TMSS to work against changed Keycloak Admin API

parent 7e533941
No related branches found
No related tags found
1 merge request!1283Resolve TMSS-2813
...@@ -8,10 +8,10 @@ from lofar.sas.tmss.tmss.exceptions import TMSSException ...@@ -8,10 +8,10 @@ from lofar.sas.tmss.tmss.exceptions import TMSSException
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
logger = logging.Logger(__name__) logger = logging.Logger(__name__)
KEYCLOAK_TOKEN_URL = os.environ.get('KEYCLOAK_TOKEN_URL', 'https://keycloak.astron.nl/auth/realms/SDC/protocol/openid-connect/token') KEYCLOAK_TOKEN_URL = os.environ.get('KEYCLOAK_TOKEN_URL', 'https://keycloak-sdc.astron.nl/realms/TMSS/protocol/openid-connect/token')
KEYCLOAK_ADMIN_USER = os.environ.get('KEYCLOAK_ADMIN_USER', 'secret') KEYCLOAK_ADMIN_USER = os.environ.get('KEYCLOAK_ADMIN_USER', 'secret')
KEYCLOAK_ADMIN_PASSWORD = os.environ.get('KEYCLOAK_ADMIN_PASSWORD', 'secret') KEYCLOAK_ADMIN_PASSWORD = os.environ.get('KEYCLOAK_ADMIN_PASSWORD', 'secret')
KEYCLOAK_API_BASE_URL = os.environ.get('KEYCLOAK_API_BASE_URL', 'https://keycloak.astron.nl/auth/admin/realms/SDC') KEYCLOAK_API_BASE_URL = os.environ.get('KEYCLOAK_API_BASE_URL', 'https://keycloak-sdc.astron.nl/admin/realms/TMSS')
class KeycloakAdminAPISession(requests.Session): class KeycloakAdminAPISession(requests.Session):
...@@ -65,10 +65,10 @@ def get_project_persons(include_projects: tuple = None): ...@@ -65,10 +65,10 @@ def get_project_persons(include_projects: tuple = None):
""" """
project_persons_map = {} project_persons_map = {}
with KeycloakAdminAPISession() as ksession: with KeycloakAdminAPISession() as ksession:
groups = ksession.get(url='%s/groups/' % KEYCLOAK_API_BASE_URL) groups = ksession.get(url='%s/groups/?search=Project' % KEYCLOAK_API_BASE_URL)
for group in groups: for group in groups:
if group['name'] == 'Project': if group['name'] == 'Project':
projects = group['subGroups'] projects = ksession.get(url='%s/groups/%s/children?max=99999' % (KEYCLOAK_API_BASE_URL, group['id']))
for project in projects: for project in projects:
if include_projects is None or project['name'] in include_projects: if include_projects is None or project['name'] in include_projects:
project_detail = ksession.get(url='%s/groups/%s/' % (KEYCLOAK_API_BASE_URL, project['id'])) project_detail = ksession.get(url='%s/groups/%s/' % (KEYCLOAK_API_BASE_URL, project['id']))
...@@ -121,9 +121,15 @@ def get_user_mapping(include_usernames: tuple = None, include_email: tuple = Non ...@@ -121,9 +121,15 @@ def get_user_mapping(include_usernames: tuple = None, include_email: tuple = Non
else: else:
users = [] users = []
for username in include_usernames or []: for username in include_usernames or []:
users += (ksession.get(url='%s/users/?username=%s' % (KEYCLOAK_API_BASE_URL, username))) try:
users += (ksession.get(url='%s/users/?username=%s' % (KEYCLOAK_API_BASE_URL, username)))
except:
logger.warning('Fetching user details from Keycloak failed for username=%s' % username)
for email in include_email or []: for email in include_email or []:
users += (ksession.get(url='%s/users/?email=%s' % (KEYCLOAK_API_BASE_URL, email))) try:
users += (ksession.get(url='%s/users/?email=%s' % (KEYCLOAK_API_BASE_URL, email)))
except:
logger.warning('Fetching user details from Keycloak failed for email=%s' % email)
for user in users: for user in users:
if 'attributes' in user and 'email' in user: if 'attributes' in user and 'email' in user:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment