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

feat: Add 'keyring list' command to CLI #3331

Merged
merged 30 commits into from
Jan 1, 2025

Conversation

ChrisBQu
Copy link
Collaborator

@ChrisBQu ChrisBQu commented Dec 16, 2024

Relevant issue(s)

Resolves #2756

Description

I am adding support for a new feature in the CLI. By running defradb keyring list, the names of the keys in the fileKeyring will be listed out.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Specify the platform(s) on which this was tested:

  • Windows

@ChrisBQu ChrisBQu self-assigned this Dec 16, 2024
@ChrisBQu ChrisBQu added feature New feature or request area/cli Related to the CLI binary labels Dec 16, 2024
@ChrisBQu ChrisBQu added this to the DefraDB v0.16 milestone Dec 16, 2024
@fredcarle
Copy link
Collaborator

Please add the feat: prefix to the title 🙂

Comment on lines 58 to 59
// List does not need to be returned here
// This function is a stub
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: It would be nice to have a bit more details as to why list does not need to be returned for the system keyring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems like a fair suggestion. I agree with it. I've added a bit more to it.

I'm not sure how much detail you (or other team members(?)) think this comment should go into. I'm open to discussion on this point if anyone feels strongly.

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 72.91667% with 13 lines in your changes missing coverage. Please review.

Project coverage is 78.03%. Comparing base (9306e7d) to head (b78eacf).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
cli/keyring_list.go 67.74% 7 Missing and 3 partials ⚠️
keyring/file.go 72.73% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3331      +/-   ##
===========================================
+ Coverage    77.92%   78.03%   +0.11%     
===========================================
  Files          388      389       +1     
  Lines        35398    35446      +48     
===========================================
+ Hits         27582    27660      +78     
+ Misses        6177     6143      -34     
- Partials      1639     1643       +4     
Flag Coverage Δ
all-tests 78.03% <72.92%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cli/cli.go 100.00% <100.00%> (ø)
keyring/system.go 36.00% <100.00%> (+36.00%) ⬆️
keyring/file.go 67.57% <72.73%> (+2.18%) ⬆️
cli/keyring_list.go 67.74% <67.74%> (ø)

... and 12 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9306e7d...b78eacf. Read the comment docs.

@ChrisBQu ChrisBQu changed the title Add 'keyring list' command to CLI feat: Add 'keyring list' command to CLI Dec 16, 2024
@ChrisBQu ChrisBQu marked this pull request as draft December 16, 2024 18:35
@ChrisBQu ChrisBQu marked this pull request as ready for review December 18, 2024 15:10
@ChrisBQu ChrisBQu requested a review from a team December 18, 2024 15:11
// The OS keyring does not support listing keys
// This function is a stub for now because the Keyring interface requires it
// Currently, the 'defradb keyring list' command uses only fileKeyring
return nil, nil
Copy link
Contributor

@AndrewSisley AndrewSisley Dec 18, 2024

Choose a reason for hiding this comment

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

todo: I was worried you would leave this func like this :) Sorry I should have clarified on discord.

I agree that this is the best choice for now, however I think it should error, not silently return - otherwise the users will go bald from the large amount of head scratching that they'll do when trying to figure out why their added keys never appear in the keyring! (it looks like it is empty when they call list on an os-keyring no?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see the logic behind it throwing an error. My original thoughts were that this function should never actually get called so there was no need to have it do anything. But as I think over it some more, that's all the more reason to make it throw an error. I think you are right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've made the changes. I'm going to tag you for re-review, so let me know what you think!

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

I would request changes, but am on holiday and don't want to block the PR. Please address/push-back my one todo before merge :)

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM. Just a couple comments that you can resolve if you want to.

)

var (
ErrNotFound = keyring.ErrNotFound // ErrNotFound is returned when a keyring item is not found.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: Not a fan of descriptive comments more than a handful of words being located on the same line as code.

Comment on lines 25 to 27
assert.Nil(t, keys, "keys should be nil when List is called")
assert.Error(t, err, "an error should be returned when List is called")
assert.Equal(t, ErrSystemKeyringListInvoked, err, "the error should be ErrSystemKeyringListInvoked")
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: We tend to prefer using require instead of assert but regardless of which one you chose, you could replace assert.Error and assert.Equal with assert.ErrorIs (or require.ErrorIs).

assert.ErrorIs(t, err, ErrSystemKeyringListInvoked)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still a bit of growing pains getting used to writing Go! But I agree with this suggestion (both parts.)

Making this change.

@ChrisBQu ChrisBQu merged commit f7b996c into sourcenetwork:develop Jan 1, 2025
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Related to the CLI binary feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to list keys using keyring command
3 participants