mirror of https://github.com/hashicorp/consul
Merge pull request #4184 from hashicorp/bugfix/gh-4076
Fix #4076 - Agent configured Watches now work with HTTPS only agentspull/4193/head
commit
41f4bb44f7
|
@ -646,14 +646,19 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {
|
|||
|
||||
// Determine the primary http(s) endpoint.
|
||||
var netaddr net.Addr
|
||||
https := false
|
||||
if len(cfg.HTTPAddrs) > 0 {
|
||||
netaddr = cfg.HTTPAddrs[0]
|
||||
} else {
|
||||
netaddr = cfg.HTTPSAddrs[0]
|
||||
https = true
|
||||
}
|
||||
addr := netaddr.String()
|
||||
if netaddr.Network() == "unix" {
|
||||
addr = "unix://" + addr
|
||||
https = false
|
||||
} else if https {
|
||||
addr = "https://" + addr
|
||||
}
|
||||
|
||||
// Fire off a goroutine for each new watch plan.
|
||||
|
@ -669,7 +674,19 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {
|
|||
wp.Handler = makeHTTPWatchHandler(a.LogOutput, httpConfig)
|
||||
}
|
||||
wp.LogOutput = a.LogOutput
|
||||
if err := wp.Run(addr); err != nil {
|
||||
|
||||
config := api.DefaultConfig()
|
||||
if https {
|
||||
if a.config.CAPath != "" {
|
||||
config.TLSConfig.CAPath = a.config.CAPath
|
||||
}
|
||||
if a.config.CAFile != "" {
|
||||
config.TLSConfig.CAFile = a.config.CAFile
|
||||
}
|
||||
config.TLSConfig.Address = addr
|
||||
}
|
||||
|
||||
if err := wp.RunWithConfig(addr, config); err != nil {
|
||||
a.logger.Printf("[ERR] agent: Failed to run watch: %v", err)
|
||||
}
|
||||
}(wp)
|
||||
|
|
|
@ -2206,3 +2206,23 @@ func TestAgent_reloadWatches(t *testing.T) {
|
|||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgent_reloadWatchesHTTPS(t *testing.T) {
|
||||
t.Parallel()
|
||||
a := TestAgent{Name: t.Name(), UseTLS: true}
|
||||
a.Start()
|
||||
defer a.Shutdown()
|
||||
|
||||
// Normal watch with http addr set, should succeed
|
||||
newConf := *a.config
|
||||
newConf.Watches = []map[string]interface{}{
|
||||
{
|
||||
"type": "key",
|
||||
"key": "asdf",
|
||||
"args": []interface{}{"ls"},
|
||||
},
|
||||
}
|
||||
if err := a.reloadWatches(&newConf); err != nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,17 @@ const (
|
|||
maxBackoffTime = 180 * time.Second
|
||||
)
|
||||
|
||||
// Run is used to run a watch plan
|
||||
func (p *Plan) Run(address string) error {
|
||||
return p.RunWithConfig(address, nil)
|
||||
}
|
||||
|
||||
// Run is used to run a watch plan
|
||||
func (p *Plan) RunWithConfig(address string, conf *consulapi.Config) error {
|
||||
// Setup the client
|
||||
p.address = address
|
||||
conf := consulapi.DefaultConfig()
|
||||
if conf == nil {
|
||||
conf = consulapi.DefaultConfig()
|
||||
}
|
||||
conf.Address = address
|
||||
conf.Datacenter = p.Datacenter
|
||||
conf.Token = p.Token
|
||||
|
|
Loading…
Reference in New Issue