Hi,
It seems to me this switch case in SerializeRuntimeAddServer which formats attributes to pass to the "add server" command doesn't fallthrough on each case:
|
func SerializeRuntimeAddServer(srv *models.RuntimeAddServer) string { //nolint:cyclop,maintidx |
|
b := &strings.Builder{} |
|
|
|
push := func(s string) { |
|
b.WriteByte(' ') |
|
b.WriteString(s) |
|
} |
|
pushi := func(key string, val *int64) { |
|
fmt.Fprintf(b, " %s %d", key, *val) |
|
} |
|
// push a quoted string |
|
pushq := func(key, val string) { |
|
fmt.Fprintf(b, ` %s "%s"`, key, val) |
|
} |
|
enabled := func(s string) bool { |
|
return s == "enabled" |
|
} |
|
|
|
// Address is mandatory and must come first, with an optional port number. |
|
addr := srv.Address |
|
if srv.Port != nil { |
|
addr += fmt.Sprintf(":%d", *srv.Port) |
|
} |
|
push(addr) |
|
|
|
switch { |
|
case enabled(srv.AgentCheck): |
|
push("agent-check") |
|
case srv.AgentAddr != "": |
|
pushq("agent-addr", srv.AgentAddr) |
|
case srv.AgentPort != nil: |
Therefore, the first case which matches, the switch is finished and won't insert the rest of the desired parameters into the resulting output string.
Golang switch statements break and don't fallthrough by default afaik, so this can be easily remedied by adding the fallthrough label to each case or using if statements.
Sorry, I've not got the time to make a PR myself.
Edit: I think it also misquotes some params using pushq, e.g. "verify" should not become verify "required", but simply verify required. The former will be rejected by the runtime API.
Cheers.
Hi,
It seems to me this switch case in
SerializeRuntimeAddServerwhich formats attributes to pass to the "add server" command doesn't fallthrough on each case:dataplaneapi/handlers/runtime_server.go
Lines 239 to 269 in 1b63b07
Therefore, the first case which matches, the switch is finished and won't insert the rest of the desired parameters into the resulting output string.
Golang switch statements break and don't fallthrough by default afaik, so this can be easily remedied by adding the fallthrough label to each case or using if statements.
Sorry, I've not got the time to make a PR myself.
Edit: I think it also misquotes some params using
pushq, e.g. "verify" should not becomeverify "required", but simplyverify required. The former will be rejected by the runtime API.Cheers.