-
Notifications
You must be signed in to change notification settings - Fork 1
/
tokensBootstrap.go
46 lines (35 loc) · 957 Bytes
/
tokensBootstrap.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
package tokens
import (
"context"
"fmt"
"github.com/clintjedwards/gofer/internal/cli/cl"
proto "github.com/clintjedwards/gofer/proto/go"
"github.com/spf13/cobra"
)
var cmdTokensBootstrap = &cobra.Command{
Use: "bootstrap",
Short: "Bootstrap creates the initial management token",
RunE: tokensBootstrap,
}
func init() {
CmdTokens.AddCommand(cmdTokensBootstrap)
}
func tokensBootstrap(_ *cobra.Command, _ []string) error {
cl.State.Fmt.Print("Creating Token")
conn, err := cl.State.Connect()
if err != nil {
cl.State.Fmt.PrintErr(err)
cl.State.Fmt.Finish()
return err
}
client := proto.NewGoferClient(conn)
resp, err := client.BootstrapToken(context.Background(), &proto.BootstrapTokenRequest{})
if err != nil {
cl.State.Fmt.PrintErr(fmt.Sprintf("could not get token: %v", err))
cl.State.Fmt.Finish()
return err
}
cl.State.Fmt.PrintSuccess(fmt.Sprintf("Token: %s", resp.Token))
cl.State.Fmt.Finish()
return nil
}