Skip to content

Commit

Permalink
Merge pull request #268 from capeprivacy/justin/add-token-list
Browse files Browse the repository at this point in the history
add token flag to list
  • Loading branch information
justin1121 authored Apr 12, 2023
2 parents d6c1394 + 10e5c5d commit c420fe5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cmd/cape/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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 := authToken()
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) {
Expand All @@ -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)
Expand Down

0 comments on commit c420fe5

Please sign in to comment.