🔒 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:
parent
5605b2aa44
commit
4bc4a39e5e
1 changed files with 2 additions and 2 deletions
|
|
@ -39,10 +39,10 @@ class UnmaskedApiKeyRead(ApiKeyBase):
|
||||||
|
|
||||||
class ApiKeyRead(ApiKeyBase):
|
class ApiKeyRead(ApiKeyBase):
|
||||||
id: UUID
|
id: UUID
|
||||||
api_key: str = Field(index=True, unique=True)
|
api_key: str = Field()
|
||||||
user_id: UUID = Field()
|
user_id: UUID = Field()
|
||||||
|
|
||||||
@validator("api_key", always=True)
|
@validator("api_key", always=True)
|
||||||
def mask_api_key(cls, v):
|
def mask_api_key(cls, v):
|
||||||
# This validator will always run, and will mask the API key
|
# 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)}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue