mirror of https://github.com/hashicorp/consul
command: remote exec takes -token parameter
parent
71aae88f3f
commit
320ab1448d
|
@ -55,6 +55,7 @@ const (
|
||||||
type rExecConf struct {
|
type rExecConf struct {
|
||||||
datacenter string
|
datacenter string
|
||||||
prefix string
|
prefix string
|
||||||
|
token string
|
||||||
|
|
||||||
foreignDC bool
|
foreignDC bool
|
||||||
localDC string
|
localDC string
|
||||||
|
@ -136,6 +137,7 @@ func (c *ExecCommand) Run(args []string) int {
|
||||||
cmdFlags.DurationVar(&c.conf.replWait, "wait-repl", rExecReplicationWait, "")
|
cmdFlags.DurationVar(&c.conf.replWait, "wait-repl", rExecReplicationWait, "")
|
||||||
cmdFlags.DurationVar(&c.conf.wait, "wait", rExecQuietWait, "")
|
cmdFlags.DurationVar(&c.conf.wait, "wait", rExecQuietWait, "")
|
||||||
cmdFlags.BoolVar(&c.conf.verbose, "verbose", false, "")
|
cmdFlags.BoolVar(&c.conf.verbose, "verbose", false, "")
|
||||||
|
cmdFlags.StringVar(&c.conf.token, "token", "", "")
|
||||||
httpAddr := HTTPAddrFlag(cmdFlags)
|
httpAddr := HTTPAddrFlag(cmdFlags)
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
|
@ -173,7 +175,11 @@ func (c *ExecCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and test the HTTP client
|
// Create and test the HTTP client
|
||||||
client, err := HTTPClientDC(*httpAddr, c.conf.datacenter)
|
client, err := HTTPClientConfig(func(clientConf *consulapi.Config) {
|
||||||
|
clientConf.Address = *httpAddr
|
||||||
|
clientConf.Datacenter = c.conf.datacenter
|
||||||
|
clientConf.Token = c.conf.token
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
||||||
return 1
|
return 1
|
||||||
|
@ -625,6 +631,8 @@ Options:
|
||||||
-wait-repl=200ms Period to wait for replication before firing event. This is an
|
-wait-repl=200ms Period to wait for replication before firing event. This is an
|
||||||
optimization to allow stale reads to be performed.
|
optimization to allow stale reads to be performed.
|
||||||
-verbose Enables verbose output
|
-verbose Enables verbose output
|
||||||
|
-token="" ACL token to use during requests. Defaults to that
|
||||||
|
of the agent.
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,15 @@ func HTTPAddrFlag(f *flag.FlagSet) *string {
|
||||||
|
|
||||||
// HTTPClient returns a new Consul HTTP client with the given address.
|
// HTTPClient returns a new Consul HTTP client with the given address.
|
||||||
func HTTPClient(addr string) (*consulapi.Client, error) {
|
func HTTPClient(addr string) (*consulapi.Client, error) {
|
||||||
return HTTPClientDC(addr, "")
|
return HTTPClientConfig(func(c *consulapi.Config) {
|
||||||
|
c.Address = addr
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPClientDC returns a new Consul HTTP client with the given address and datacenter
|
// HTTPClientConfig is used to return a new API client and modify its
|
||||||
func HTTPClientDC(addr, dc string) (*consulapi.Client, error) {
|
// configuration by passing in a config modifier function.
|
||||||
|
func HTTPClientConfig(fn func(c *consulapi.Config)) (*consulapi.Client, error) {
|
||||||
conf := consulapi.DefaultConfig()
|
conf := consulapi.DefaultConfig()
|
||||||
if envAddr := os.Getenv(HTTPAddrEnvName); addr == "" && envAddr != "" {
|
fn(conf)
|
||||||
addr = envAddr
|
|
||||||
}
|
|
||||||
conf.Address = addr
|
|
||||||
conf.Datacenter = dc
|
|
||||||
return consulapi.NewClient(conf)
|
return consulapi.NewClient(conf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue