mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-09 16:25:40 +02:00
Introduce service accounts and bootstrap tokens (#22)
This commit is contained in:
@@ -9,10 +9,10 @@ var quiet bool
|
||||
func NewCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List resources on the controller (workers, VMs)",
|
||||
Short: "List resources on the controller",
|
||||
}
|
||||
|
||||
command.AddCommand(newListWorkersCommand(), newListVMsCommand())
|
||||
command.AddCommand(newListWorkersCommand(), newListVMsCommand(), newListServiceAccountsCommand())
|
||||
|
||||
command.PersistentFlags().BoolVarP(&quiet, "", "q", false, "only show resource names")
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/gosuri/uitable"
|
||||
"github.com/spf13/cobra"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func newListServiceAccountsCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "service-accounts",
|
||||
Short: "List service accounts",
|
||||
RunE: runListServiceAccounts,
|
||||
}
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func runListServiceAccounts(cmd *cobra.Command, args []string) error {
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceAccounts, err := client.ServiceAccounts().List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if quiet {
|
||||
for _, serviceAccount := range serviceAccounts {
|
||||
fmt.Println(serviceAccount.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
table := uitable.New()
|
||||
|
||||
table.AddRow("Name", "Roles")
|
||||
|
||||
for _, serviceAccount := range serviceAccounts {
|
||||
var scopeList []string
|
||||
|
||||
for _, scope := range serviceAccount.Roles {
|
||||
scopeList = append(scopeList, string(scope))
|
||||
}
|
||||
|
||||
table.AddRow(serviceAccount.Name, strings.Join(scopeList, ", "))
|
||||
}
|
||||
|
||||
fmt.Println(table)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -9,8 +9,9 @@ import (
|
||||
|
||||
func newListVMsCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "vms",
|
||||
RunE: runListVMs,
|
||||
Use: "vms",
|
||||
Short: "List VMs",
|
||||
RunE: runListVMs,
|
||||
}
|
||||
|
||||
return command
|
||||
|
||||
Reference in New Issue
Block a user