-
Notifications
You must be signed in to change notification settings - Fork 469
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
Expose BatchEntryDelete On CLI #4371
Expose BatchEntryDelete On CLI #4371
Conversation
Signed-off-by: JU4N98 <juanpablocabana2@gmail.com>
Signed-off-by: JU4N98 <juanpablocabana2@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the contribution @JU4N98! And sorry for the delay on my part
Left a handful of comments, mostly around UX. It leads me to wonder about the output we print ... if folks are providing programmatic input, should we be providing programatic output? What is the path to recovering from a batch delete call where half the requests failed? just thinking out loud ...
cmd/spire-server/cli/entry/delete.go
Outdated
entryID string | ||
env *commoncli.Env | ||
printer cliprinter.Printer | ||
entriesIDs StringsFlag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, this should probably be
entriesIDs StringsFlag | |
entryIDs StringsFlag |
cmd/spire-server/cli/entry/delete.go
Outdated
@@ -40,16 +43,54 @@ func (*deleteCommand) Synopsis() string { | |||
} | |||
|
|||
func (c *deleteCommand) AppendFlags(f *flag.FlagSet) { | |||
f.StringVar(&c.entryID, "entryID", "", "The Registration Entry ID of the record to delete") | |||
f.Var(&c.entriesIDs, "entryID", "The Registration Entry ID of the record to delete. Can be used more than once") | |||
f.StringVar(&c.path, "data", "", "Path to a file containing deletion JSON (optional). If set to '-', read the JSON from stdin.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this flag name to file
instead? I think it's a bit clearer that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention something about batch deletion here ... maybe like:
f.StringVar(&c.path, "data", "", "Path to a file containing deletion JSON (optional). If set to '-', read the JSON from stdin.") | |
f.StringVar(&c.path, "data", "", "Path to a file containing a JSON structure for batch deletion (optional). If set to '-', read from stdin.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, i think that file is a better description than data.
cmd/spire-server/cli/entry/delete.go
Outdated
@@ -40,16 +43,54 @@ func (*deleteCommand) Synopsis() string { | |||
} | |||
|
|||
func (c *deleteCommand) AppendFlags(f *flag.FlagSet) { | |||
f.StringVar(&c.entryID, "entryID", "", "The Registration Entry ID of the record to delete") | |||
f.Var(&c.entriesIDs, "entryID", "The Registration Entry ID of the record to delete. Can be used more than once") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should allow multiple entryID flags to be passed. It definitely feels like the natural thing to do, but there are other batch endpoints that we'll need to support on CLI (like entry create) that can't be supported in this way ... so to keep things consistent, I feel we should support file-based batch operations only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, i didn't notice that entry create doesn't support batch create without a file. I'm going to fix that and keep the file flag.
} | ||
|
||
for _, result := range failed { | ||
env.ErrPrintf("Failed to delete entry with ID %s (code: %s, msg: %q)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably print out a newline or two between the success and error lines
codes.Code(result.Status.Code), | ||
result.Status.Message) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should print a newline here and another message summarizing, e.g. "Deleted X entries successfully" or "Deleted X entries successfully, but failed to delete Y entries"
} | ||
|
||
if len(failed) > 0 { | ||
return errors.New("failed to delete one or more entries") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI command should only error if the call as a whole has errored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed create.go as a guide:
spire/cmd/spire-server/cli/entry/create.go
Line 284 in 5aa2122
if len(failed) > 0 { |
Maybe I misunderstood the code of entry create, but I think that we are doing the same there.
Thanks for the comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok ... consistency is best 😊 thanks for pointing that out
Signed-off-by: JU4N98 <juanpablocabana2@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @JU4N98 !!
Hey @JU4N98, looks like the Windows unit tests need to be fixed up following changes to help text output: https://github.com/spiffe/spire/actions/runs/5907969226/job/16186854897?pr=4371 Mind patching it so we can get this merged in for 1.8.0? |
Signed-off-by: JU4N98 <juanpablocabana2@gmail.com>
Signed-off-by: JU4N98 <juanpablocabana2@gmail.com>
hey @evan2645 windows unit test should be fixed right now |
Affected functionality
This PR affects the entry delete on cli.
Description of change
This PR allows:
In both cases, the output is similar to entry create, first the succeeded entry deletions are enumerated and then the failed ones.
Which issue this PR fixes
This PR fixes the issue #4248.