Files
orchard/internal/command/get/bootstrap_token.go
T
Nikolay Edigaryev 5c3b47a247 --help fixes and new "orchard logs vm" command (#41)
* Make sure we list names/VM names as required argument in the --help

* Introduce "orchard logs vm" command

* Make sure each command has a Short field

* Future-proof port-forward, ssh and vnc commands

To support not only the VM resource.
2023-03-23 15:59:57 +04:00

54 lines
1.1 KiB
Go

package get
import (
"fmt"
"github.com/cirruslabs/orchard/internal/bootstraptoken"
"github.com/cirruslabs/orchard/internal/config"
"github.com/cirruslabs/orchard/pkg/client"
"github.com/spf13/cobra"
)
func newGetBootstrapTokenCommand() *cobra.Command {
command := &cobra.Command{
Use: "bootstrap-token NAME",
Short: "Retrieve a bootstrap token for the specified service account",
RunE: runGetBootstrapToken,
Args: cobra.ExactArgs(1),
}
return command
}
func runGetBootstrapToken(cmd *cobra.Command, args []string) error {
name := args[0]
configHandle, err := config.NewHandle()
if err != nil {
return err
}
defaultContext, err := configHandle.DefaultContext()
if err != nil {
return err
}
client, err := client.New()
if err != nil {
return err
}
serviceAccount, err := client.ServiceAccounts().Get(cmd.Context(), name)
if err != nil {
return err
}
bootstrapToken, err := bootstraptoken.New(defaultContext.Certificate, serviceAccount.Name, serviceAccount.Token)
if err != nil {
return err
}
fmt.Println(bootstrapToken)
return nil
}