From 73d25ab871a719ab323b37e27da8eceed6587c94 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Thu, 24 Aug 2023 14:26:40 +0200 Subject: [PATCH] crypto: Print warning when deprecated features are used --- dnf/crypto.py | 19 ++++++++++++++++--- dnf/yum/misc.py | 5 ++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dnf/crypto.py b/dnf/crypto.py index 63b814cad5..7fc80c68fd 100644 --- a/dnf/crypto.py +++ b/dnf/crypto.py @@ -29,13 +29,17 @@ import dnf.yum.misc import logging import os +import warnings GPG_HOME_ENV = 'GNUPGHOME' logger = logging.getLogger('dnf') def _extract_signing_subkey(key): # :deprecated, undocumented - """ Deprecated feature. It was used internally. It is no longer used. """ + """ It was used internally and is no longer used. """ + msg = "Function `_extract_signing_subkey` is deprecated. Will be removed after 2024-01-01." + warnings.warn(msg, DeprecationWarning, stacklevel=2) + return dnf.util.first(subkey for subkey in key.subkeys if subkey.can_sign) @@ -50,6 +54,9 @@ def import_repo_keys(repo): It was used internally. In 2018, the code was rewritten into libdnf. This code is no longer used. It was broken in 2018 - the `repo._key_import._confirm` method now needs 5 arguments. It is now fixed and marked as deprecated. Please do not use. """ + msg = "Function `import_repo_keys` is deprecated. Will be removed after 2024-01-01." + warnings.warn(msg, DeprecationWarning, stacklevel=2) + gpgdir = repo._pubring_dir known_keys = keyids_from_pubring(gpgdir) for keyurl in repo.gpgkey: @@ -69,7 +76,10 @@ def import_repo_keys(repo): def keyids_from_pubring(gpgdir): # :deprecated, undocumented - """ Used internally by deprecated function `import_repo_keys` """ + """ It is used internally by deprecated function `import_repo_keys` """ + msg = "Function `keyids_from_pubring` is deprecated. Will be removed after 2024-01-01." + warnings.warn(msg, DeprecationWarning, stacklevel=2) + keyids = [] for keyid in libdnf.repo.keyidsFromPubring(gpgdir): keyids.append(keyid) @@ -97,7 +107,10 @@ def log_dns_key_import(keyinfo, dns_result): @contextlib.contextmanager def pubring_dir(pubring_dir): # :deprecated, undocumented - """ Deprecated feature. It was used internally. It is no longer used. """ + """ It was used internally and is no longer used. """ + msg = "Function `pubring_dir` is deprecated. Will be removed after 2024-01-01." + warnings.warn(msg, DeprecationWarning, stacklevel=2) + orig = os.environ.get(GPG_HOME_ENV, None) os.environ[GPG_HOME_ENV] = pubring_dir try: diff --git a/dnf/yum/misc.py b/dnf/yum/misc.py index 0c151470b6..0d6498bae6 100644 --- a/dnf/yum/misc.py +++ b/dnf/yum/misc.py @@ -39,6 +39,7 @@ import re import shutil import tempfile +import warnings _default_checksums = ['sha256'] @@ -161,7 +162,9 @@ def keyInstalled(ts, keyid, timestamp): def import_key_to_pubring(rawkey, keyid, gpgdir=None, make_ro_copy=True): # :deprecated, undocumented - """ Used internally by deprecated function `import_repo_keys` """ + """ It is used internally by deprecated function `import_repo_keys` """ + msg = "Function `import_key_to_pubring` is deprecated. Will be removed after 2024-01-01." + warnings.warn(msg, DeprecationWarning, stacklevel=2) if not os.path.exists(gpgdir): os.makedirs(gpgdir)