Handle failed login
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
IamTheFij 2022-11-15 12:59:37 -08:00
parent b47c5d5f32
commit 60963ef69d

View File

@ -4,6 +4,7 @@ from flask import Flask
from flask import Response from flask import Response
from flask import request from flask import request
from hvac import Client from hvac import Client
from hvac.exceptions import InvalidRequest
BIND_HOST = os.getenv("BIND_HOST", "0.0.0.0") BIND_HOST = os.getenv("BIND_HOST", "0.0.0.0")
@ -46,7 +47,11 @@ def login():
username, password = request.form["username"], request.form["password"] username, password = request.form["username"], request.form["password"]
client = Client(VAULT_ADDR) client = Client(VAULT_ADDR)
try:
client.auth.userpass.login(username, password) client.auth.userpass.login(username, password)
except InvalidRequest:
return Response(response="Unauthorized", status=401)
if not client.is_authenticated(): if not client.is_authenticated():
return Response(response="Unauthorized", status=401) return Response(response="Unauthorized", status=401)