Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

var applicationInstanceNameForList *string
var applicationInstanceNameForCreate *string
var applicationNameForList *string
var applicationNameForCreate *string

var tokenCmd = &cobra.Command{
Use: "token",
Expand Down Expand Up @@ -63,6 +65,24 @@ var listApplicationInstanceTokenCmd = &cobra.Command{
},
}

var listApplicationTokenCmd = &cobra.Command{
Use: "application",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
result, err := consoleAPIClient().ListApplicationToken(*applicationNameForList)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not list application token: %s\n", err)
os.Exit(1)
}
if len(result) == 0 {
fmt.Println("No tokens found")
}
for _, token := range result {
fmt.Printf("%s:\t%s\n", token.Name, token.Id)
}
},
}

var createTokenCmd = &cobra.Command{
Use: "create",
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -120,6 +140,19 @@ var createApplicationInstanceTokenCmd = &cobra.Command{
},
}

var createApplicationTokenCmd = &cobra.Command{
Use: "application --application=myapp <token-name>",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
result, err := consoleAPIClient().CreateApplicationToken(*applicationNameForCreate, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Could not create application token: %s\n", err)
os.Exit(1)
}
fmt.Printf("%s\n", result.Token)
},
}

var deleteTokenCmd = &cobra.Command{
Use: "delete <token-uuid>",
Args: cobra.ExactArgs(1),
Expand All @@ -138,12 +171,18 @@ func init() {
applicationInstanceNameForCreate = createApplicationInstanceTokenCmd.PersistentFlags().StringP("application-instance", "i", "", "Application instance name")
_ = listApplicationInstanceTokenCmd.MarkPersistentFlagRequired("application-instance")
_ = createApplicationInstanceTokenCmd.MarkPersistentFlagRequired("application-instance")
applicationNameForList = listApplicationTokenCmd.PersistentFlags().StringP("application", "a", "", "Application name")
applicationNameForCreate = createApplicationTokenCmd.PersistentFlags().StringP("application", "a", "", "Application name")
_ = listApplicationTokenCmd.MarkPersistentFlagRequired("application")
_ = createApplicationTokenCmd.MarkPersistentFlagRequired("application")
listTokenCmd.AddCommand(listApplicationInstanceTokenCmd)
listTokenCmd.AddCommand(listApplicationTokenCmd)
listTokenCmd.AddCommand(listAdminCmd)
tokenCmd.AddCommand(listTokenCmd)
tokenCmd.AddCommand(deleteTokenCmd)
tokenCmd.AddCommand(createTokenCmd)
createTokenCmd.AddCommand(createAdminTokenCmd)
createTokenCmd.AddCommand(createApplicationInstanceTokenCmd)
createTokenCmd.AddCommand(createApplicationTokenCmd)
rootCmd.AddCommand(tokenCmd)
}
30 changes: 30 additions & 0 deletions pkg/client/console_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions pkg/client/console_client_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading