Skip to content

Commit

Permalink
cli: Print a plugin suggestion on installed but expired pgp key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jan-kolarik committed Jan 7, 2025
1 parent 3516532 commit 709cd6d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dnf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2640,7 +2640,7 @@ def _prov_key_data(msg):
'package.\n'
'Check that the correct key URLs are configured for '
'this repository.') % repo.name
raise dnf.exceptions.Error(_prov_key_data(msg))
raise dnf.exceptions.InvalidInstalledGPGKeyError(_prov_key_data(msg))

# Check if the newly installed keys helped
result, errmsg = self._sig_check_pkg(po)
Expand Down
8 changes: 6 additions & 2 deletions dnf/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def gpgsigcheck(self, pkgs):
:raises: Will raise :class:`Error` if there's a problem
"""
error_messages = []
print_plugin_recommendation = False
for po in pkgs:
result, errmsg = self._sig_check_pkg(po)

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

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

def latest_changelogs(self, package):
Expand Down
4 changes: 4 additions & 0 deletions dnf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def __str__(self):
return self.errmap2str(self.errmap)


class InvalidInstalledGPGKeyError(Error):
pass


class LockError(Error):
pass

Expand Down

0 comments on commit 709cd6d

Please sign in to comment.