This commit is contained in:
parent
b47c5d5f32
commit
60963ef69d
7
main.py
7
main.py
@ -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)
|
||||||
client.auth.userpass.login(username, password)
|
try:
|
||||||
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user