Skip to content

Commit 709cd6d

Browse files
committed
cli: Print a plugin suggestion on installed but expired pgp key
When PGP key for a repository is installed, but already expired, suggest enabling the expired-pgp-keys plugin to reimport the new key and resolve the issue.
1 parent 3516532 commit 709cd6d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

dnf/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ def _prov_key_data(msg):
26402640
'package.\n'
26412641
'Check that the correct key URLs are configured for '
26422642
'this repository.') % repo.name
2643-
raise dnf.exceptions.Error(_prov_key_data(msg))
2643+
raise dnf.exceptions.InvalidInstalledGPGKeyError(_prov_key_data(msg))
26442644

26452645
# Check if the newly installed keys helped
26462646
result, errmsg = self._sig_check_pkg(po)

dnf/cli/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def gpgsigcheck(self, pkgs):
284284
:raises: Will raise :class:`Error` if there's a problem
285285
"""
286286
error_messages = []
287+
print_plugin_recommendation = False
287288
for po in pkgs:
288289
result, errmsg = self._sig_check_pkg(po)
289290

@@ -304,6 +305,8 @@ def gpgsigcheck(self, pkgs):
304305
self._get_key_for_package(po, fn)
305306
except (dnf.exceptions.Error, ValueError) as e:
306307
error_messages.append(str(e))
308+
if isinstance(e, dnf.exceptions.InvalidInstalledGPGKeyError):
309+
print_plugin_recommendation = True
307310

308311
else:
309312
# Fatal error
@@ -312,8 +315,9 @@ def gpgsigcheck(self, pkgs):
312315
if error_messages:
313316
for msg in error_messages:
314317
logger.critical(msg)
315-
logger.info("\nUse the `--enableplugin=expired-pgp-keys' "
316-
"parameter to resolve the problem.\n")
318+
if print_plugin_recommendation:
319+
msg = '\n' + _("Try to add '--enableplugin=expired-pgp-keys' to resolve the problem.") + '\n'
320+
logger.info(msg)
317321
raise dnf.exceptions.Error(_("GPG check FAILED"))
318322

319323
def latest_changelogs(self, package):

dnf/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def __str__(self):
8686
return self.errmap2str(self.errmap)
8787

8888

89+
class InvalidInstalledGPGKeyError(Error):
90+
pass
91+
92+
8993
class LockError(Error):
9094
pass
9195

0 commit comments

Comments
 (0)