Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --list and --delete commands to rpmkeys #2921

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

ffesti
Copy link
Contributor

@ffesti ffesti commented Feb 21, 2024

This is a bit of a hack as it manipulates the parsed cli parameters to
to the "right thing" and then calls rpmcliQuery and rpmErase.

@ffesti ffesti marked this pull request as draft February 21, 2024 07:31
@ffesti
Copy link
Contributor Author

ffesti commented Feb 21, 2024

This feels a bit too quick and dirty. Comments welcome.

tools/rpmkeys.c Outdated
ARGV_t gpgargs = argvNew();
for (char * const * arg = args; *arg; arg++) {
if (strncmp(*arg, "gpg-pubkey-", 11)) {
char * gpgarg = rpmExpand("gpg-pubkey-", *arg, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the macro expand? That seems weird/wrong in this context.

tools/rpmkeys.c Outdated
@@ -75,7 +74,29 @@ int main(int argc, char *argv[])
break;
/* XXX TODO: actually implement these... */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe delete this comment while at it? 😄 A fine example of why comments are so bad - they don't get updated along with the code.

@pmatilai
Copy link
Member

pmatilai commented Feb 21, 2024

I think I initially wanted to add a sane API for these and then have rpmkeys use that, and when that seemed painful I gave up. But the user wont care how it's achieved if it works in a meaningful manner. And, for the user this is far saner than 'rpmkeys --import -> rpm -q -> rpm --erase'.

Two things:

  1. Lets make the option names consistent - either they all should have plural -keys, or none should have it. Since the pre-existing --import doesn't have it, maybe the --delete and --list shouldn't have either (the "key" context comes from the command name)? Or, we could add --import-keys as alias to --import.
  2. Tests for both added operations.

tools/rpmkeys.c Outdated
case MODE_LISTKEY:
if (args != NULL) {
argerror(_("--list-keys does not take any arguments"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should (take optional arguments), actually. It could be useful for eg checking whether a particular key is imported, without having to query all and grep.

tools/rpmkeys.c Outdated
if (args != NULL) {
argerror(_("--list-keys does not take any arguments"));
}
ARGV_t query = argvSplitString("gpg-pubkey", " ", ARGV_NONE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit creative way to initialize an argv... I think

ARGV_t query = NULL;
argvAdd(&query, "gpg-pubkey");

...would be a well worth the one extra line in obviousness 😄

@ffesti
Copy link
Contributor Author

ffesti commented Feb 21, 2024

Well, I stuck to the names that were in the code...

but it turns out the "keys" in in the name of the utility already and we don't need to repeat that in the cli parameter. It also uses "--delete" while rpm itself uses "--erase". Not sure if that is good because it is a slightly different operation or bad because it is inconsistent. Opinions?

@pmatilai
Copy link
Member

pmatilai commented Feb 22, 2024

Well, I stuck to the names that were in the code...

I know. My not-so-thoroughly thought up names from 10+ years ago, and a fine example of why not to leave such half-assed pieces laying around in the codebase 😆

It also uses "--delete" while rpm itself uses "--erase". Not sure if that is good because it is a slightly different operation or bad because it is inconsistent. Opinions?

I'm quite sure I chose the names for familiarity from gpg, which has --list-keys and --delete-keys. (interestingly --import is just --import in gpg too). I always quite disliked the "erase" terminology in rpm anyhow. At least I associate erasing with emptying content (think fill data with zeros) as opposed to making the whole thing unreachable (think unlink file)

@ffesti ffesti marked this pull request as ready for review February 22, 2024 07:49
tools/rpmkeys.c Outdated
@@ -42,6 +41,20 @@ static struct poptOption optionsTable[] = {
POPT_TABLEEND
};

static ARGV_t gpgkeyargs(ARGV_const_t args) {
ARGV_t gpgargs = argvNew();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argvNew() is wholly unnecessary here (it almost always is), just initialize to NULl and argvAdd() and similar will alloc it as needed.

tools/rpmkeys.c Outdated
ARGV_t gpgargs = argvNew();
for (char * const * arg = args; *arg; arg++) {
if (strncmp(*arg, "gpg-pubkey-", 11)) {
char * gpgarg = rpmExpand("gpg-pubkey-", *arg, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why the macro expand? 'rpmkeys --delete %{somemacro}' seems like a weird use-case to support, I'd think for something like OpenPGP keys you'd rather always be explicit about the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why moving the code elsewhere didn't solve the issue...

This is a  bit of a hack as it manipulates the parsed cli parameters to
to the "right thing" and then calls rpmcliQuery and rpmErase.
Copy link
Member

@pmatilai pmatilai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine now, thanks.

@pmatilai pmatilai merged commit 1dc7e76 into rpm-software-management:master Feb 28, 2024
1 check passed
@ffesti ffesti deleted the 2404 branch March 6, 2024 08:34
@dmnks dmnks added RFE CLI Command-line interface labels Mar 21, 2024
@dmnks dmnks changed the title Add --list-keys and --delete-key to rpmkeys Add --list-keys and --delete-key to rpmkeys Mar 21, 2024
@dmnks dmnks changed the title Add --list-keys and --delete-key to rpmkeys Add --list and --delete commands to rpmkeys Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Command-line interface RFE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants