remove GPG_1_3_1 check

This commit is contained in:
Leif Liddy 2022-10-15 17:57:17 +02:00
parent 427718c5ae
commit 8767c52920
No known key found for this signature in database
GPG key ID: 8A7AD507B1EEF020
2 changed files with 47 additions and 92 deletions

1
changelog/62895.changed Normal file
View file

@ -0,0 +1 @@
Removed GPG_1_3_1 check

View file

@ -21,7 +21,6 @@ import salt.utils.files
import salt.utils.path
import salt.utils.stringutils
from salt.exceptions import SaltInvocationError
from salt.utils.versions import LooseVersion as _LooseVersion
log = logging.getLogger(__name__)
@ -65,12 +64,9 @@ VERIFY_TRUST_LEVELS = {
"4": "Ultimate",
}
GPG_1_3_1 = False
try:
import gnupg
HAS_GPG_BINDINGS = True
GPG_1_3_1 = _LooseVersion(gnupg.__version__) >= _LooseVersion("1.3.1")
except ImportError:
HAS_GPG_BINDINGS = False
@ -183,9 +179,6 @@ def _create_gpg(user=None, gnupghome=None):
if not gnupghome:
gnupghome = _get_user_gnupghome(user)
if GPG_1_3_1:
gpg = gnupg.GPG(homedir=gnupghome) # pylint: disable=unexpected-keyword-arg
else:
gpg = gnupg.GPG(gnupghome=gnupghome)
return gpg
@ -238,11 +231,6 @@ def search_keys(text, keyserver=None, user=None):
salt '*' gpg.search_keys user@example.com keyserver=keyserver.ubuntu.com user=username
"""
if GPG_1_3_1:
raise SaltInvocationError(
"The search_keys function is not support with this version of python-gnupg."
)
else:
if not keyserver:
keyserver = "pgp.mit.edu"
@ -778,19 +766,6 @@ def import_key(text=None, filename=None, user=None, gnupghome=None):
imported_data = gpg.import_keys(text)
if GPG_1_3_1:
counts = imported_data.counts
if counts.get("imported") or counts.get("imported_rsa"):
ret["message"] = "Successfully imported key(s)."
elif counts.get("unchanged"):
ret["message"] = "Key(s) already exist in keychain."
elif counts.get("not_imported"):
ret["res"] = False
ret["message"] = "Unable to import key."
elif not counts.get("count"):
ret["res"] = False
ret["message"] = "Unable to import key."
else:
if imported_data.imported or imported_data.imported_rsa:
ret["message"] = "Successfully imported key(s)."
elif imported_data.unchanged:
@ -1069,21 +1044,10 @@ def sign(
else:
gpg_passphrase = None
# Check for at least one secret key to sign with
gnupg_version = _LooseVersion(gnupg.__version__)
if text:
if gnupg_version >= _LooseVersion("1.3.1"):
signed_data = gpg.sign(text, default_key=keyid, passphrase=gpg_passphrase)
else:
signed_data = gpg.sign(text, keyid=keyid, passphrase=gpg_passphrase)
elif filename:
with salt.utils.files.flopen(filename, "rb") as _fp:
if gnupg_version >= _LooseVersion("1.3.1"):
signed_data = gpg.sign(
text, default_key=keyid, passphrase=gpg_passphrase
)
else:
signed_data = gpg.sign_file(_fp, keyid=keyid, passphrase=gpg_passphrase)
if output:
with salt.utils.files.flopen(output, "wb") as fout:
@ -1255,16 +1219,6 @@ def encrypt(
if text:
result = gpg.encrypt(text, recipients, passphrase=gpg_passphrase)
elif filename:
if GPG_1_3_1:
# This version does not allow us to encrypt using the
# file stream # have to read in the contents and encrypt.
with salt.utils.files.flopen(filename, "rb") as _fp:
_contents = salt.utils.stringutils.to_unicode(_fp.read())
result = gpg.encrypt(
_contents, recipients, passphrase=gpg_passphrase, output=output
)
else:
# This version allows encrypting the file stream
with salt.utils.files.flopen(filename, "rb") as _fp:
if output:
result = gpg.encrypt_file(