-
Notifications
You must be signed in to change notification settings - Fork 1
CLI: Update hypeman SDK to 1f34cf2541 and add new flags #41
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
base: main
Are you sure you want to change the base?
Changes from all commits
d994913
ebaa09f
f66ded9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/kernel/hypeman-go" | ||
| "github.com/kernel/hypeman-go/option" | ||
|
|
@@ -24,6 +25,14 @@ var psCmd = cli.Command{ | |
| Aliases: []string{"q"}, | ||
| Usage: "Only display instance IDs", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "state", | ||
| Usage: "Filter instances by state (e.g., Running, Stopped, Standby)", | ||
| }, | ||
| &cli.StringSliceFlag{ | ||
| Name: "metadata", | ||
| Usage: "Filter by metadata key-value pair (KEY=VALUE, can be repeated)", | ||
| }, | ||
| }, | ||
| Action: handlePs, | ||
| HideHelpCommand: true, | ||
|
|
@@ -37,8 +46,26 @@ func handlePs(ctx context.Context, cmd *cli.Command) error { | |
| opts = append(opts, debugMiddlewareOption) | ||
| } | ||
|
|
||
| params := hypeman.InstanceListParams{} | ||
|
|
||
| if state := cmd.String("state"); state != "" { | ||
| params.State = hypeman.InstanceListParamsState(state) | ||
| } | ||
|
|
||
| if metadataSpecs := cmd.StringSlice("metadata"); len(metadataSpecs) > 0 { | ||
| metadata := make(map[string]string) | ||
| for _, m := range metadataSpecs { | ||
| parts := strings.SplitN(m, "=", 2) | ||
| if len(parts) == 2 { | ||
| metadata[parts[0]] = parts[1] | ||
| } | ||
| } | ||
| params.Metadata = metadata | ||
| } | ||
|
|
||
| instances, err := client.Instances.List( | ||
| ctx, | ||
| params, | ||
| opts..., | ||
| ) | ||
| if err != nil { | ||
|
|
@@ -47,11 +74,12 @@ func handlePs(ctx context.Context, cmd *cli.Command) error { | |
|
|
||
| showAll := cmd.Bool("all") | ||
| quietMode := cmd.Bool("quiet") | ||
| stateFilter := cmd.String("state") | ||
|
|
||
| // Filter instances | ||
| // Filter instances client-side only when no server-side filter is active | ||
| var filtered []hypeman.Instance | ||
| for _, inst := range *instances { | ||
| if showAll || inst.State == "Running" { | ||
| if showAll || stateFilter != "" || inst.State == "Running" { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metadata filter results silently dropped by client-side filteringHigh Severity When Additional Locations (1)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading empty-result message when using --state filterMedium Severity When a user passes |
||
| filtered = append(filtered, inst) | ||
| } | ||
| } | ||
|
|
||


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.
Malformed metadata flags silently set empty map on params
Low Severity
If all
--metadatavalues are malformed (missing=), the loop skips every entry butparams.Metadatais still set to an emptymap[string]string{}. An empty map may serialize differently than an omitted/nil field in the API request, potentially causing unexpected server-side behavior. The user also gets no feedback that their filter was invalid and silently ignored.