agent: convert the proxy bind_port to int if it is a float
This commit is contained in:
parent
446429bc06
commit
54ad6fc050
|
@ -2200,6 +2200,19 @@ func (a *Agent) applyProxyConfigDefaults(p *structs.ConnectManagedProxy) (map[st
|
|||
// Default to localhost and the port the service registered with
|
||||
config["local_service_address"] = fmt.Sprintf("127.0.0.1:%d", target.Port)
|
||||
}
|
||||
|
||||
// Basic type conversions for expected types.
|
||||
if raw, ok := config["bind_port"]; ok {
|
||||
switch v := raw.(type) {
|
||||
case float64:
|
||||
// Common since HCL/JSON parse as float64
|
||||
config["bind_port"] = int(v)
|
||||
|
||||
// NOTE(mitchellh): No default case since errors and validation
|
||||
// are handled by the ServiceDefinition.Validate function.
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2677,6 +2677,24 @@ func TestAgent_AddProxy(t *testing.T) {
|
|||
wantTCPCheck: "127.10.10.10:1234",
|
||||
wantErr: false,
|
||||
},
|
||||
|
||||
{
|
||||
// This test is necessary since JSON and HCL both will parse
|
||||
// numbers as a float64.
|
||||
desc: "managed proxy with custom bind port (float64)",
|
||||
proxy: &structs.ConnectManagedProxy{
|
||||
ExecMode: structs.ProxyExecModeDaemon,
|
||||
Command: []string{"consul", "connect", "proxy"},
|
||||
Config: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"bind_address": "127.10.10.10",
|
||||
"bind_port": float64(1234),
|
||||
},
|
||||
TargetServiceID: "web",
|
||||
},
|
||||
wantTCPCheck: "127.10.10.10:1234",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
BIN
website/source/assets/videos/connect-video-cli.mp4 (Stored with Git LFS)
BIN
website/source/assets/videos/connect-video-cli.mp4 (Stored with Git LFS)
Binary file not shown.
BIN
website/source/assets/videos/connect-video-ui.mp4 (Stored with Git LFS)
BIN
website/source/assets/videos/connect-video-ui.mp4 (Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue