Skip to content

Commit

Permalink
Support authorization via object payload
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Feb 1, 2024
1 parent 57cd6ce commit 0a14993
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pystream/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ class Config:
@field_validator("authorization", mode='before', check_fields=False)
def parse_authorization(cls, value: Any) -> Dict[str, SecretStr]:
"""Validates the authorization parameter."""
val = json.loads(value, object_pairs_hook=as_dict)
if isinstance(val, dict):
r = {}
for k, v in val.items():
if len(k) < 3:
raise ValueError(f"[{k}: {v}] username should be at least 4 or more characters")
if len(v) < 8:
raise ValueError(f"[{k}: {v}] password should be at least 8 or more characters")
r[k] = v
return r
raise ValueError("input should be a valid dictionary with username as key and password as value")
if isinstance(value, dict):
val = value
else:
val = json.loads(value, object_pairs_hook=as_dict)
if not isinstance(val, dict):
raise ValueError("input should be a valid dictionary with username as key and password as value")
r = {}
for k, v in val.items():
if len(k) < 3:
raise ValueError(f"[{k}: {v}] username should be at least 4 or more characters")
if len(v) < 8:
raise ValueError(f"[{k}: {v}] password should be at least 8 or more characters")
r[k] = v
return r

# noinspection PyMethodParameters
@field_validator("video_host", mode='after', check_fields=True)
Expand Down

0 comments on commit 0a14993

Please sign in to comment.