-
Notifications
You must be signed in to change notification settings - Fork 9
/
api_tokens_list.go
46 lines (40 loc) · 1.24 KB
/
api_tokens_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package api_tokens
import (
"fmt"
"log"
"os"
"github.com/provideservices/provide-cli/cmd/common"
provide "github.com/provideservices/provide-go/api/ident"
"github.com/spf13/cobra"
)
var apiTokensListCmd = &cobra.Command{
Use: "list",
Short: "Retrieve a list of API tokens",
Long: `Retrieve a list of API tokens scoped to the authorized API token`,
Run: listAPITokens,
}
func listAPITokens(cmd *cobra.Command, args []string) {
token := common.RequireAPIToken()
params := map[string]interface{}{}
if common.ApplicationID != "" {
params["application_id"] = common.ApplicationID
}
resp, err := provide.ListTokens(token, params)
if err != nil {
log.Printf("Failed to retrieve API tokens list; %s", err.Error())
os.Exit(1)
}
// if status != 200 {
// log.Printf("Failed to retrieve API tokens list; received status: %d", status)
// os.Exit(1)
// }
for i := range resp {
apiToken := resp[i]
result := fmt.Sprintf("%s\t%s\n", apiToken.ID.String(), *apiToken.Token)
fmt.Print(result)
}
}
func init() {
apiTokensListCmd.Flags().StringVar(&common.ApplicationID, "application", "", "application identifier to filter API tokens")
apiTokensListCmd.Flags().BoolVarP(&optional, "optional", "", false, "List all the optional flags")
}