chore(decrypt): mention the key in error if specificed
This would allow the user to know which key is failing, and just update that if required Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
parent
8ef064b14a
commit
c2001919a5
1 changed files with 6 additions and 5 deletions
|
|
@ -34,7 +34,7 @@ def get_decrypted_password(doctype, name, fieldname="password", raise_exception=
|
|||
).run()
|
||||
|
||||
if result and result[0][0]:
|
||||
return decrypt(result[0][0])
|
||||
return decrypt(result[0][0], key=f"{doctype}.{name}.{fieldname}")
|
||||
|
||||
elif raise_exception:
|
||||
frappe.throw(
|
||||
|
|
@ -183,7 +183,7 @@ def encrypt(txt, encryption_key=None):
|
|||
return cstr(cipher_suite.encrypt(encode(txt)))
|
||||
|
||||
|
||||
def decrypt(txt, encryption_key=None):
|
||||
def decrypt(txt, encryption_key=None, key: str | None = None):
|
||||
# Only use encryption_key value generated with Fernet.generate_key().decode()
|
||||
|
||||
try:
|
||||
|
|
@ -192,12 +192,13 @@ def decrypt(txt, encryption_key=None):
|
|||
except InvalidToken:
|
||||
# encryption_key in site_config is changed and not valid
|
||||
frappe.throw(
|
||||
_("Encryption key is invalid! Please check site_config.json")
|
||||
+ "<br>"
|
||||
(_("Failed to decrypt key {0}").format(key) + "<br><br>" if key else "")
|
||||
+ _("Encryption key is invalid! Please check site_config.json")
|
||||
+ "<br><br>"
|
||||
+ _(
|
||||
"If you have recently restored the site you may need to copy the site config contaning original Encryption Key."
|
||||
)
|
||||
+ "<br>"
|
||||
+ "<br><br>"
|
||||
+ _(
|
||||
"Please visit https://frappecloud.com/docs/sites/migrate-an-existing-site#encryption-key for more information."
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue