log the failed encrypted content to debug
This commit is contained in:
parent
50a7442d02
commit
9603683c18
|
@ -3,6 +3,8 @@ from io import BytesIO
|
||||||
import gnupg
|
import gnupg
|
||||||
|
|
||||||
from app.config import GNUPGHOME
|
from app.config import GNUPGHOME
|
||||||
|
from app.log import LOG
|
||||||
|
from app.utils import random_string
|
||||||
|
|
||||||
gpg = gnupg.GPG(gnupghome=GNUPGHOME)
|
gpg = gnupg.GPG(gnupghome=GNUPGHOME)
|
||||||
gpg.encoding = "utf-8"
|
gpg.encoding = "utf-8"
|
||||||
|
@ -24,6 +26,12 @@ def load_public_key(public_key: str) -> str:
|
||||||
def encrypt_file(data: BytesIO, fingerprint: str) -> str:
|
def encrypt_file(data: BytesIO, fingerprint: str) -> str:
|
||||||
r = gpg.encrypt_file(data, fingerprint, always_trust=True)
|
r = gpg.encrypt_file(data, fingerprint, always_trust=True)
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
|
# save the content for debugging
|
||||||
|
random_file_name = random_string(20) + ".eml"
|
||||||
|
full_path = f"/tmp/{random_file_name}"
|
||||||
|
with open(full_path, "wb") as f:
|
||||||
|
f.write(data.getbuffer())
|
||||||
|
LOG.error("Log to %s", full_path)
|
||||||
raise PGPException("Cannot encrypt")
|
raise PGPException("Cannot encrypt")
|
||||||
|
|
||||||
return str(r)
|
return str(r)
|
||||||
|
|
Loading…
Reference in New Issue