github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/cmd/swarmctl/cluster/unlockkey.go (about) 1 package cluster 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/docker/swarmkit/api" 8 "github.com/docker/swarmkit/cmd/swarmctl/common" 9 "github.com/docker/swarmkit/manager/encryption" 10 "github.com/spf13/cobra" 11 ) 12 13 // get the unlock key 14 15 func displayUnlockKey(cmd *cobra.Command) error { 16 conn, err := common.DialConn(cmd) 17 if err != nil { 18 return err 19 } 20 defer conn.Close() 21 22 resp, err := api.NewCAClient(conn).GetUnlockKey(common.Context(cmd), &api.GetUnlockKeyRequest{}) 23 if err != nil { 24 return err 25 } 26 27 if len(resp.UnlockKey) == 0 { 28 fmt.Printf("Managers not auto-locked") 29 } 30 fmt.Printf("Managers auto-locked. Unlock key: %s\n", encryption.HumanReadableKey(resp.UnlockKey)) 31 return nil 32 } 33 34 var ( 35 unlockKeyCmd = &cobra.Command{ 36 Use: "unlock-key <cluster name>", 37 Short: "Get the unlock key for a cluster", 38 RunE: func(cmd *cobra.Command, args []string) error { 39 if len(args) == 0 { 40 return errors.New("cluster name missing") 41 } 42 43 if len(args) > 1 { 44 return errors.New("unlock-key command takes exactly 1 argument") 45 } 46 47 return displayUnlockKey(cmd) 48 }, 49 } 50 )