Skip to content

Commit

Permalink
Add from/to filters to minder history list. (#3928)
Browse files Browse the repository at this point in the history
Added from/to filters to `minder history list`.

This change adds `--from` and `--to` optional flags, which let the
customer specify a time window for evaluation times. Allowed formats
are those supported by the library we're currently using (viper) and
are listed
[here](https://github.com/spf13/cast/blob/48ddde5701366ade1d3aba346e09bb58430d37c6/cast_test.go#L934-L952).

Fixes #3927
  • Loading branch information
blkt authored Jul 19, 2024
1 parent 8d7f92f commit 547c691
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cmd/cli/app/history/history_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/stacklok/minder/cmd/cli/app"
"github.com/stacklok/minder/cmd/cli/app/common"
Expand Down Expand Up @@ -59,6 +60,10 @@ func listCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc
remediationStatus := viper.GetStringSlice("remediation-status")
alertStatus := viper.GetStringSlice("alert-status")

// time range
from := viper.GetTime("from")
to := viper.GetTime("to")

// page options
cursorStr := viper.GetString("cursor")
size := viper.GetUint64("size")
Expand Down Expand Up @@ -88,7 +93,7 @@ func listCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc
}

// list all the things
resp, err := client.ListEvaluationHistory(ctx, &minderv1.ListEvaluationHistoryRequest{
req := &minderv1.ListEvaluationHistoryRequest{
Context: &minderv1.Context{Project: &project},
EntityType: entityType,
EntityName: entityName,
Expand All @@ -99,7 +104,19 @@ func listCommand(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc
From: nil,
To: nil,
Cursor: cursorFromOptions(cursorStr, size),
})
}

// Viper returns time.Time rather than a pointer to it, so we
// have to check whether from and/or to were specified by
// other means.
if cmd.Flags().Lookup("from").Changed {
req.From = timestamppb.New(from)
}
if cmd.Flags().Lookup("to").Changed {
req.To = timestamppb.New(to)
}

resp, err := client.ListEvaluationHistory(ctx, req)
if err != nil {
return cli.MessageAndError("Error getting profile status", err)
}
Expand Down Expand Up @@ -217,6 +234,8 @@ func init() {
listCmd.Flags().String("eval-status", "", evalFilterMsg)
listCmd.Flags().String("remediation-status", "", remediationFilterMsg)
listCmd.Flags().String("alert-status", "", alertFilterMsg)
listCmd.Flags().String("from", "", "Filter evaluation history list by time")
listCmd.Flags().String("to", "", "Filter evaluation history list by time")
listCmd.Flags().StringP("cursor", "c", "", "Fetch previous or next page from the list")
listCmd.Flags().Uint64P("size", "s", defaultPageSize, "Change the number of items fetched")
}
Expand Down

0 comments on commit 547c691

Please sign in to comment.