Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SecretStr and SecretBytes. (#452)
* feat: add SecretStr and SecretBytes. * chore: update HISTORY.rst * fix: file permissions were incorrect. * feat: lint, format, fix comments. * feat: changed inner type of SecretBytes in the schema to string as there is no bytes type in json. * feat: remove format from secret str and secret bytes. * feat: fix schema mapping.
- Loading branch information
1 parent
694abaf
commit 4a8faca
Showing
9 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel, SecretStr, SecretBytes, ValidationError | ||
|
||
class SimpleModel(BaseModel): | ||
password: SecretStr | ||
password_bytes: SecretBytes | ||
|
||
print(SimpleModel(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')) | ||
# > SimpleModel password=SecretStr('**********') password_bytes=SecretBytes(b'**********') | ||
|
||
sm = SimpleModel(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes') | ||
print(sm.password.get_secret_value()) | ||
# > IAmSensitive | ||
print(sm.password_bytes.get_secret_value()) | ||
# > b'IAmSensitiveBytes' | ||
|
||
|
||
try: | ||
SimpleModel(password=[1,2,3], password_bytes=[1,2,3]) | ||
except ValidationError as e: | ||
print(e) | ||
""" | ||
2 validation error | ||
password | ||
str type expected (type=type_error.str) | ||
password_bytes | ||
byte type expected (type=type_error.bytes) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters