From 8435c5373c33fe2642ce37c61be1a0f51ba2b7e1 Mon Sep 17 00:00:00 2001 From: Mart van Santen <mart@greenhost.nl> Date: Thu, 9 Dec 2021 09:25:36 +0100 Subject: [PATCH] Cleanup --- login/kratos.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/login/kratos.py b/login/kratos.py index 60593af..fc50257 100644 --- a/login/kratos.py +++ b/login/kratos.py @@ -241,11 +241,14 @@ class KratosUser(): # We override the default Redirect handler with our custom handler to # be able to catch the cookies. opener = urllib.request.build_opener(RedirectFilter) - print(f"Opening: {recovery_url}") + + # We rewrite the URL we got. It can be we run this from an enviroment + # with different KRATUS_PUBLIC_URL API endpoint then kratos provide + # itself. For example in the case running as a job to create an admin + # account before TLS is setup/working search = re.match(r'.*(self-service.recovery.flow.*)$', recovery_url) if search: recovery_url = api_url + "/" + search.group(1) - print(f"Opening: {recovery_url}") opener.open(recovery_url) # If we do not have a 2xx status, urllib throws an error, as we "stopped" # at our redirect, we expect a 3xx status @@ -254,9 +257,9 @@ class KratosUser(): cookies = req.headers.get_all('Set-Cookie') url = req.headers.get('Location') else: - raise BackendError(f'Unable to fetch recovery link {recovery_url}') from req + raise BackendError('Unable to fetch recovery link') from req else: - raise BackendError(f'Unable to fetch recovery link: {recovery_url}') + raise BackendError('Unable to fetch recovery link') # Step 2: Extract cookies and data for next step. We expect to have an # authorized session now. We need the cookies for followup calls -- GitLab