From 4e68d47a5ddf17a30c1eaf98d0aaadee0a504f8a Mon Sep 17 00:00:00 2001 From: Justin Patriquin Date: Wed, 12 Apr 2023 09:16:49 -0300 Subject: [PATCH 1/2] add token flag to list --- cmd/cape/cmd/list.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/cape/cmd/list.go b/cmd/cape/cmd/list.go index bb611e1..4add0b8 100644 --- a/cmd/cape/cmd/list.go +++ b/cmd/cape/cmd/list.go @@ -50,6 +50,7 @@ var listCmd = &cobra.Command{ func init() { rootCmd.AddCommand(listCmd) + listCmd.PersistentFlags().StringP("token", "t", "", "authorization token to use") listCmd.PersistentFlags().IntP("limit", "", 50, "Limit the number of functions returned.") listCmd.PersistentFlags().IntP("offset", "", 0, "Number of functions to skip before listing.") } @@ -77,11 +78,17 @@ func list(cmd *cobra.Command, args []string) error { return UserError{Msg: "list does not take any arguments", Err: fmt.Errorf("invalid number of input arguments")} } - t, err := authToken() - if err != nil { - return err + token, _ := cmd.Flags().GetString("token") + if token == "" { + t, err := getAuthToken() + if err != nil { + return err + } + + token = t } - auth := entities.FunctionAuth{Type: entities.AuthenticationTypeUserToken, Token: t} + + auth := entities.FunctionAuth{Type: entities.AuthenticationTypeUserToken, Token: token} err = doList(u, insecure, auth, limit, offset, format) if err != nil { if errors.Is(err, ErrUnauthorized) { @@ -93,7 +100,7 @@ func list(cmd *cobra.Command, args []string) error { return nil } -func doList(url string, insecure bool, auth entities.FunctionAuth, limit int, offset int, format string) error { //nolint:gocognit +func doList(url string, insecure bool, auth entities.FunctionAuth, limit int, offset int, format string) error { endpoint := fmt.Sprintf("%s/v1/functions?limit=%d&offset=%d", url, limit, offset) req, err := http.NewRequest("GET", endpoint, nil) From 10e5c5d605adc43b0d0c3714cac11664cb1d291b Mon Sep 17 00:00:00 2001 From: Justin Patriquin Date: Wed, 12 Apr 2023 09:20:56 -0300 Subject: [PATCH 2/2] fix list test by using authToken func --- cmd/cape/cmd/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cape/cmd/list.go b/cmd/cape/cmd/list.go index 4add0b8..a0b7d85 100644 --- a/cmd/cape/cmd/list.go +++ b/cmd/cape/cmd/list.go @@ -80,7 +80,7 @@ func list(cmd *cobra.Command, args []string) error { token, _ := cmd.Flags().GetString("token") if token == "" { - t, err := getAuthToken() + t, err := authToken() if err != nil { return err }