Skip to content

Commit

Permalink
Set username and password optional to deliver a 401 error when they'r…
Browse files Browse the repository at this point in the history
…e missing
  • Loading branch information
LDiazN committed Jan 17, 2025
1 parent c69b37d commit ddc93da
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
log = logging.getLogger(__name__)

class ProbeLogin(BaseModel):
username : str
# Allow None username and password
# to deliver informational 401 error when they're missing
username : str | None = None
# not actually used but necessary to be compliant with the old API schema
password : str
password : str | None = None

class ProbeLoginResponse(BaseModel):
token : str
Expand All @@ -32,6 +34,9 @@ def probe_login_post(
) -> ProbeLoginResponse:
global log

if probe_login.username is None or probe_login.password is None:
raise HTTPException(status_code=401, detail="Missing credentials")

token = probe_login.username
# TODO: We have to find a way to explicitly log metrics with prometheus.
# We're currently using the instrumentator default metrics, like http response counts
Expand Down

0 comments on commit ddc93da

Please sign in to comment.