-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathservicetoken_delete.go
More file actions
49 lines (40 loc) · 1.33 KB
/
servicetoken_delete.go
File metadata and controls
49 lines (40 loc) · 1.33 KB
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
47
48
49
package servicetoken
import (
"fmt"
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
)
type DeleteArgs struct {
ID int64
}
func DeleteCommand(deps *di.Deps) *cobra.Command {
args := &DeleteArgs{}
cmd := &cobra.Command{
Use: "delete",
Short: "Delete a service token",
Long: "Delete a service token by ID. This also removes any dedicated subject associated with the token.",
Example: `# delete a service token
sts service-token delete --id 123456789`,
RunE: deps.CmdRunEWithApi(RunServiceTokenDeleteCommand(args)),
}
common.AddRequiredIDFlagVar(cmd, &args.ID, "ID of the service token to delete")
return cmd
}
func RunServiceTokenDeleteCommand(args *DeleteArgs) di.CmdWithApiFn {
return func(cmd *cobra.Command, cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo) common.CLIError {
resp, err := api.ServiceTokenApi.DeleteServiceToken(cli.Context, args.ID).Execute()
if err != nil {
return common.NewResponseError(err, resp)
}
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"deleted-service-token": args.ID,
})
} else {
cli.Printer.Success(fmt.Sprintf("Service token deleted: %d", args.ID))
}
return nil
}
}