mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 23:10:36 +01:00
Améliore le healthcheck Docker pour détecter les erreurs en temps réel
This commit is contained in:
@@ -17,34 +17,53 @@ auth: UserAuthenticator
|
||||
def twitchConfigurationHelp():
|
||||
return render_template("twitch-aide.html", token_redirect_url = _buildUrl())
|
||||
|
||||
@webapp.route("/configurations/twitch/request-token")
|
||||
async def twitchRequestToken():
|
||||
@webapp.route("/configurations/twitch/request-token")
|
||||
async def twitchRequestToken():
|
||||
global auth
|
||||
helper = ConfigurationHelper()
|
||||
twitch = await Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret'))
|
||||
auth = UserAuthenticator(twitch, USER_SCOPE, url=_buildUrl())
|
||||
return redirect(auth.return_auth_url())
|
||||
try:
|
||||
helper = ConfigurationHelper()
|
||||
import asyncio
|
||||
twitch = await asyncio.wait_for(
|
||||
Twitch(helper.getValue('twitch_client_id'), helper.getValue('twitch_client_secret')),
|
||||
timeout=30.0
|
||||
)
|
||||
auth = UserAuthenticator(twitch, USER_SCOPE, url=_buildUrl())
|
||||
return redirect(auth.return_auth_url())
|
||||
except asyncio.TimeoutError:
|
||||
logging.error('Timeout lors de la connexion à Twitch API pour la demande de token')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
except TwitchAPIException as e:
|
||||
logging.error(f'Erreur API Twitch lors de la demande de token : {e}')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
except Exception as e:
|
||||
logging.error(f'Erreur inattendue lors de la demande de token Twitch : {e}')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
@webapp.route("/configurations/twitch/receive-token")
|
||||
@webapp.route("/configurations/twitch/receive-token")
|
||||
async def twitchReceiveToken():
|
||||
global auth
|
||||
state = request.args.get('state')
|
||||
code = request.args.get('code')
|
||||
if state != auth.state :
|
||||
logging('bad returned state')
|
||||
logging.error('bad returned state')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
if code == None :
|
||||
logging('no returned state')
|
||||
logging.error('no returned code')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
|
||||
try:
|
||||
token, refresh = await auth.authenticate(user_token=code)
|
||||
import asyncio
|
||||
token, refresh = await asyncio.wait_for(auth.authenticate(user_token=code), timeout=30.0)
|
||||
helper = ConfigurationHelper()
|
||||
helper.createOrUpdate('twitch_access_token', token)
|
||||
helper.createOrUpdate('twitch_refresh_token', refresh)
|
||||
db.session.commit()
|
||||
except asyncio.TimeoutError:
|
||||
logging.error('Timeout lors de l\'authentification Twitch')
|
||||
except TwitchAPIException as e:
|
||||
logging(e)
|
||||
logging.error(f'Erreur API Twitch lors de l\'authentification : {e}')
|
||||
except Exception as e:
|
||||
logging.error(f'Erreur inattendue lors de l\'authentification Twitch : {e}')
|
||||
return redirect(url_for('openConfigurations'))
|
||||
|
||||
# hack pas fou mais on estime qu'on sera toujours en ssl en connecté
|
||||
|
||||
Reference in New Issue
Block a user