🔒 chore(api_key.py): refactor mask_api_key validator to improve readability and maintainability

🔒 chore(api_key.py): update api_key field in ApiKeyRead model to remove index=True and unique=True constraints
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-28 06:48:38 -03:00
commit 4bc4a39e5e

View file

@ -39,10 +39,10 @@ class UnmaskedApiKeyRead(ApiKeyBase):
class ApiKeyRead(ApiKeyBase):
id: UUID
api_key: str = Field(index=True, unique=True)
api_key: str = Field()
user_id: UUID = Field()
@validator("api_key", always=True)
def mask_api_key(cls, v):
# This validator will always run, and will mask the API key
return f"{v[:2]}{'*' * (len(v) - 4)}{v[-2:]}"
return f"{v[:8]}{'*' * (len(v) - 8)}"