-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcommand_scim_token.go
More file actions
90 lines (72 loc) · 2.33 KB
/
Copy pathcommand_scim_token.go
File metadata and controls
90 lines (72 loc) · 2.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Code generated by cli-terraform-generator; DO NOT EDIT.
package organization
import (
"time"
"github.com/spf13/cobra"
orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2"
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
"github.com/confluentinc/cli/v4/pkg/config"
"github.com/confluentinc/cli/v4/pkg/output"
)
type scimTokenCommand struct {
*pcmd.AuthenticatedCLICommand
}
type scimTokenOut struct {
ID string `human:"ID" serialized:"id"`
ConnectionName string `human:"Connection Name" serialized:"connection_name"`
Token string `human:"Token" serialized:"token"`
CreatedAt string `human:"Created At" serialized:"created_at"`
ExpiresAt string `human:"Expires At" serialized:"expires_at"`
}
func newScimTokenCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam
cmd := &cobra.Command{
Use: "scim-token",
Aliases: []string{"st"},
Short: "Manage Organization scim tokens.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin},
}
c := &scimTokenCommand{
AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner),
}
cmd.AddCommand(
c.newCreateCommand(),
c.newDeleteCommand(),
c.newListCommand(),
)
return cmd
}
func printScimToken(cmd *cobra.Command, scimToken orgv2.OrgV2ScimToken) error {
table := output.NewTable(cmd)
out := &scimTokenOut{
ID: scimToken.GetId(),
ConnectionName: scimToken.GetConnectionName(),
Token: scimToken.GetToken(),
CreatedAt: scimToken.GetCreatedAt().Format(time.RFC3339),
ExpiresAt: scimToken.GetExpiresAt().Format(time.RFC3339),
}
table.Add(out)
return table.Print()
}
func (c *scimTokenCommand) validArgs(cmd *cobra.Command, args []string) []string {
if len(args) > 0 {
return nil
}
return c.validArgsMultiple(cmd, args)
}
func (c *scimTokenCommand) validArgsMultiple(cmd *cobra.Command, args []string) []string {
if err := c.PersistentPreRunE(cmd, args); err != nil {
return nil
}
return c.autocompleteScimTokens()
}
func (c *scimTokenCommand) autocompleteScimTokens() []string {
scimTokens, err := c.V2Client.ListOrgScimTokens()
if err != nil {
return nil
}
suggestions := make([]string, len(scimTokens))
for i, scimToken := range scimTokens {
suggestions[i] = scimToken.GetId()
}
return suggestions
}