You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importkeyringfromtypingimportOptionalKEYRING_SERVICE="faaadmv"classPaymentKeychain:
"""Secure storage for payment credentials."""@staticmethoddefstore(card_number: str, expiry: str, cvv: str, billing_zip: str) ->None:
"""Store payment info in OS keychain."""keyring.set_password(KEYRING_SERVICE, "card_number", card_number)
keyring.set_password(KEYRING_SERVICE, "card_expiry", expiry)
keyring.set_password(KEYRING_SERVICE, "card_cvv", cvv)
keyring.set_password(KEYRING_SERVICE, "billing_zip", billing_zip)
@staticmethoddefretrieve() ->Optional[dict]:
"""Retrieve payment info from OS keychain."""card_number=keyring.get_password(KEYRING_SERVICE, "card_number")
ifnotcard_number:
returnNonereturn {
"card_number": card_number,
"expiry": keyring.get_password(KEYRING_SERVICE, "card_expiry"),
"cvv": keyring.get_password(KEYRING_SERVICE, "card_cvv"),
"billing_zip": keyring.get_password(KEYRING_SERVICE, "billing_zip"),
}
@staticmethoddefdelete() ->None:
"""Remove all payment info from keychain."""forkeyin ("card_number", "card_expiry", "card_cvv", "billing_zip"):
try:
keyring.delete_password(KEYRING_SERVICE, key)
exceptkeyring.errors.PasswordDeleteError:
pass# Key doesn't exist
Sensitive Data Handling
frompydanticimportSecretStrclassPaymentInfo(BaseModel):
card_number: SecretStrcvv: SecretStr# Access secret value only when neededcard=payment.card_number.get_secret_value()