From b43f7a2ebb9ede567a3dbd71668525ea168f779a Mon Sep 17 00:00:00 2001 From: gluap Date: Sun, 26 Dec 2021 11:48:36 +0100 Subject: [PATCH] retry: should only modify client on success. --- api/obs/api/routes/login.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api/obs/api/routes/login.py b/api/obs/api/routes/login.py index 4a8bc1a..bd6cb32 100644 --- a/api/obs/api/routes/login.py +++ b/api/obs/api/routes/login.py @@ -1,6 +1,7 @@ import asyncio import logging -import os + +from requests.exceptions import RequestException from sqlalchemy import select @@ -25,21 +26,20 @@ logging.getLogger('oic').setLevel(logging.INFO) @auth.before_server_start async def connect_auth_client(app, loop): client.allow["issuer_mismatch"] = True - client.provider_config(app.config.KEYCLOAK_URL) try: client.provider_config(app.config.KEYCLOAK_URL) - except: + client.store_registration_info( + RegistrationResponse( + client_id=app.config.KEYCLOAK_CLIENT_ID, + client_secret=app.config.KEYCLOAK_CLIENT_SECRET, + ) + ) + except RequestException: log.exception(f"could not connect to {app.config.KEYCLOAK_URL}") log.info("will retry") await asyncio.sleep(2) log.info("retrying") - await connect_auth_client(app,loop) - client.store_registration_info( - RegistrationResponse( - client_id=app.config.KEYCLOAK_CLIENT_ID, - client_secret=app.config.KEYCLOAK_CLIENT_SECRET, - ) - ) + await connect_auth_client(app, loop) @auth.route("/login")