github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/get/get_token_addon.go (about) 1 package get 2 3 import ( 4 "github.com/jenkins-x/jx-logging/pkg/log" 5 "github.com/jenkins-x/jx/v2/pkg/cmd/helper" 6 "github.com/jenkins-x/jx/v2/pkg/util" 7 "github.com/spf13/cobra" 8 9 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 10 "github.com/jenkins-x/jx/v2/pkg/cmd/templates" 11 ) 12 13 // GetTokenAddonOptions the command line options 14 type GetTokenAddonOptions struct { 15 GetTokenOptions 16 } 17 18 var ( 19 getTokenAddonLong = templates.LongDesc(` 20 Display the users with tokens for the addons 21 22 `) 23 24 getTokenAddonExample = templates.Examples(` 25 # List all users with tokens for all addons 26 jx get token addon 27 `) 28 ) 29 30 // NewCmdGetTokenAddon creates the command 31 func NewCmdGetTokenAddon(commonOpts *opts.CommonOptions) *cobra.Command { 32 options := &GetTokenAddonOptions{ 33 GetTokenOptions{ 34 Options: Options{ 35 CommonOptions: commonOpts, 36 }, 37 }, 38 } 39 40 cmd := &cobra.Command{ 41 Use: "addon", 42 Short: "Display the current users and if they have a token for the addons", 43 Long: getTokenAddonLong, 44 Example: getTokenAddonExample, 45 Aliases: []string{"issue-tracker"}, 46 Run: func(cmd *cobra.Command, args []string) { 47 options.Cmd = cmd 48 options.Args = args 49 err := options.Run() 50 helper.CheckErr(err) 51 }, 52 } 53 options.addFlags(cmd) 54 return cmd 55 } 56 57 // Run implements this command 58 func (o *GetTokenAddonOptions) Run() error { 59 authConfigSvc, err := o.AddonAuthConfigService("") 60 if err != nil { 61 return err 62 } 63 config := authConfigSvc.Config() 64 if len(config.Servers) == 0 { 65 log.Logger().Warnf("No addon servers registered. To register a new token for an addon server use: %s", util.ColorInfo("jx create token addon")) 66 return nil 67 } 68 return o.displayUsersWithTokens(authConfigSvc) 69 }