Make gpg.receive_keys report failure when GPG does

This makes `gpg.present` report the correct result when a
keyserver is unreachable and thus fixes issue 65169 in
concert with several related fixes in this branch.
This commit is contained in:
jeanluc 2023-09-12 00:10:53 +02:00 committed by Pedro Algarvio
parent b97022a705
commit 60fd084cf5
2 changed files with 9 additions and 9 deletions

1
changelog/65169.fixed.md Normal file
View file

@ -0,0 +1 @@
Fixed `gpg.present` succeeds when the keyserver is unreachable

View file

@ -934,21 +934,20 @@ def receive_keys(keyserver=None, keys=None, user=None, gnupghome=None):
if "ok" in result:
if result["ok"] == "1":
ret["message"].append(
"Key {} added to keychain".format(result["fingerprint"])
f"Key {result['fingerprint']} added to keychain"
)
elif result["ok"] == "0":
ret["message"].append(
"Key {} already exists in keychain".format(
result["fingerprint"]
)
f"Key {result['fingerprint']} already exists in keychain"
)
elif "problem" in result:
ret["message"].append("Unable to add key to keychain")
elif not bool(recv_data):
ret["message"].append(
f"Unable to add key to keychain: {result.get('text', 'No further description')}"
)
if not bool(recv_data):
ret["res"] = False
ret["message"] = [
f"Something went wrong during gpg call: {recv_data.stderr}"
]
ret["message"].append(f"GPG reported failure: {recv_data.stderr}")
except AttributeError:
ret["res"] = False
ret["message"] = ["Invalid return from python-gpg"]