-
Notifications
You must be signed in to change notification settings - Fork 787
/
get_token_addon.go
75 lines (65 loc) · 1.72 KB
/
get_token_addon.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
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
package cmd
import (
"io"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1/terminal"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
)
// GetTokenAddonOptions the command line options
type GetTokenAddonOptions struct {
GetTokenOptions
}
var (
getTokenAddonLong = templates.LongDesc(`
Display the users with tokens for the addons
`)
getTokenAddonExample = templates.Examples(`
# List all users with tokens for all addons
jx get token addon
`)
)
// NewCmdGetTokenAddon creates the command
func NewCmdGetTokenAddon(f Factory, in terminal.FileReader, out terminal.FileWriter, errOut io.Writer) *cobra.Command {
options := &GetTokenAddonOptions{
GetTokenOptions{
GetOptions: GetOptions{
CommonOptions: CommonOptions{
Factory: f,
In: in,
Out: out,
Err: errOut,
},
},
},
}
cmd := &cobra.Command{
Use: "addon",
Short: "Display the current users and if they have a token for the addons",
Long: getTokenAddonLong,
Example: getTokenAddonExample,
Aliases: []string{"issue-tracker"},
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
options.addFlags(cmd)
return cmd
}
// Run implements this command
func (o *GetTokenAddonOptions) Run() error {
authConfigSvc, err := o.createAddonAuthConfigService()
if err != nil {
return err
}
config := authConfigSvc.Config()
if len(config.Servers) == 0 {
log.Warnf("No addon servers registered. To register a new token for an addon server use: %s\n", util.ColorInfo("jx create token addon"))
return nil
}
return o.displayUsersWithTokens(authConfigSvc)
}