Skip to content

Commit 02ed1ff

Browse files
authored
PYTHON-4197: Convert str usage to SecretStr (#30)
1 parent ed8b758 commit 02ed1ff

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

{{cookiecutter.project_slug}}/backend/app/app/schemas/emails.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from pydantic import BaseModel, EmailStr
2-
from typing import List
1+
from pydantic import BaseModel, EmailStr, SecretStr
32

43

54
class EmailContent(BaseModel):
@@ -11,4 +10,4 @@ class EmailContent(BaseModel):
1110
class EmailValidation(BaseModel):
1211
email: EmailStr
1312
subject: str
14-
token: str
13+
token: SecretStr

{{cookiecutter.project_slug}}/backend/app/app/schemas/token.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional
2-
from pydantic import ConfigDict, BaseModel
2+
from pydantic import BaseModel, ConfigDict, SecretStr
33
from odmantic import Model, ObjectId
44

55

66
class RefreshTokenBase(BaseModel):
7-
token: str
7+
token: SecretStr
88
authenticates: Optional[Model] = None
99

1010

@@ -21,8 +21,8 @@ class RefreshToken(RefreshTokenUpdate):
2121

2222

2323
class Token(BaseModel):
24-
access_token: str
25-
refresh_token: Optional[str] = None
24+
access_token: SecretStr
25+
refresh_token: Optional[SecretStr] = None
2626
token_type: str
2727

2828

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from typing import Optional
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, SecretStr
33

44

55
class NewTOTP(BaseModel):
6-
secret: Optional[str] = None
6+
secret: Optional[SecretStr] = None
77
key: str
88
uri: str
99

1010

1111
class EnableTOTP(BaseModel):
1212
claim: str
1313
uri: str
14-
password: Optional[str] = None
14+
password: Optional[SecretStr] = None

{{cookiecutter.project_slug}}/backend/app/app/schemas/user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22
from typing_extensions import Annotated
3-
from pydantic import ConfigDict, BaseModel, Field, EmailStr, StringConstraints, field_validator
3+
from pydantic import BaseModel, ConfigDict, Field, EmailStr, StringConstraints, field_validator, SecretStr
44
from odmantic import ObjectId
55

66

@@ -56,6 +56,6 @@ def evaluate_totp_secret(cls, totp_secret):
5656

5757
# Additional properties stored in DB
5858
class UserInDB(UserInDBBase):
59-
hashed_password: Optional[str] = None
60-
totp_secret: Optional[str] = None
59+
hashed_password: Optional[SecretStr] = None
60+
totp_secret: Optional[SecretStr] = None
6161
totp_counter: Optional[int] = None

0 commit comments

Comments
 (0)