github.hscsec.cn/hashicorp/consul@v1.4.5/command/acl/bootstrap/bootstrap.go (about) 1 package bootstrap 2 3 import ( 4 "flag" 5 "fmt" 6 7 "github.com/hashicorp/consul/command/acl" 8 "github.com/hashicorp/consul/command/flags" 9 "github.com/mitchellh/cli" 10 ) 11 12 func New(ui cli.Ui) *cmd { 13 c := &cmd{UI: ui} 14 c.init() 15 return c 16 } 17 18 type cmd struct { 19 UI cli.Ui 20 flags *flag.FlagSet 21 http *flags.HTTPFlags 22 help string 23 } 24 25 func (c *cmd) init() { 26 c.flags = flag.NewFlagSet("", flag.ContinueOnError) 27 c.http = &flags.HTTPFlags{} 28 flags.Merge(c.flags, c.http.ClientFlags()) 29 flags.Merge(c.flags, c.http.ServerFlags()) 30 c.help = flags.Usage(help, c.flags) 31 } 32 33 func (c *cmd) Run(args []string) int { 34 if err := c.flags.Parse(args); err != nil { 35 return 1 36 } 37 38 client, err := c.http.APIClient() 39 if err != nil { 40 c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err)) 41 return 1 42 } 43 44 token, _, err := client.ACL().Bootstrap() 45 if err != nil { 46 c.UI.Error(fmt.Sprintf("Failed ACL bootstrapping: %v", err)) 47 return 1 48 } 49 50 acl.PrintToken(token, c.UI, false) 51 return 0 52 } 53 54 func (c *cmd) Synopsis() string { 55 return synopsis 56 } 57 58 func (c *cmd) Help() string { 59 return flags.Usage(c.help, nil) 60 } 61 62 const synopsis = "Bootstrap Consul's ACL system" 63 64 // TODO (ACL-V2) - maybe embed link to bootstrap reset docs 65 const help = ` 66 Usage: consul acl bootstrap [options] 67 68 The bootstrap command will request Consul to generate a new token with unlimited privileges to use 69 for management purposes and output its details. This can only be done once and afterwards bootstrapping 70 will be disabled. If all tokens are lost and you need to bootstrap again you can follow the bootstrap 71 reset procedure 72 `