Skip to content

Commit 89af159

Browse files
committed
BUG/MAJOR: runtime_server: fix adding all the server options for server
1 parent 80e6082 commit 89af159

File tree

1 file changed

+150
-78
lines changed

1 file changed

+150
-78
lines changed

handlers/runtime_server.go

Lines changed: 150 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (h *DeleteRuntimeServerHandlerImpl) Handle(params server.DeleteRuntimeServe
243243
// SerializeRuntimeAddServer returns a string in the HAProxy config format, suitable
244244
// for the "add server" operation over the control socket.
245245
// Not all the Server attributes are available in this case.
246-
func SerializeRuntimeAddServer(srv *models.RuntimeAddServer, version *cn_runtime.HAProxyVersion) string { //nolint:cyclop,maintidx
246+
func SerializeRuntimeAddServer(srv *models.RuntimeAddServer, version *cn_runtime.HAProxyVersion) string { //nolint: cyclop,maintidx
247247
b := &strings.Builder{}
248248

249249
push := func(s string) {
@@ -255,11 +255,14 @@ func SerializeRuntimeAddServer(srv *models.RuntimeAddServer, version *cn_runtime
255255
}
256256
// push a quoted string
257257
pushq := func(key, val string) {
258-
fmt.Fprintf(b, ` %s "%s"`, key, val)
258+
fmt.Fprintf(b, ` %s %s`, key, val)
259259
}
260260
enabled := func(s string) bool {
261261
return s == "enabled"
262262
}
263+
disabled := func(s string) bool {
264+
return s == "disabled"
265+
}
263266

264267
// Address is mandatory and must come first, with an optional port number.
265268
addr := srv.Address
@@ -268,159 +271,228 @@ func SerializeRuntimeAddServer(srv *models.RuntimeAddServer, version *cn_runtime
268271
}
269272
push(addr)
270273

271-
switch {
272-
case enabled(srv.AgentCheck):
274+
if enabled(srv.AgentCheck) {
273275
push("agent-check")
274-
case srv.AgentAddr != "":
276+
}
277+
if srv.AgentAddr != "" {
275278
pushq("agent-addr", srv.AgentAddr)
276-
case srv.AgentPort != nil:
279+
}
280+
if srv.AgentPort != nil {
277281
pushi("agent-port", srv.AgentPort)
278-
case srv.AgentInter != nil:
282+
}
283+
if srv.AgentInter != nil {
279284
pushi("agent-inter", srv.AgentInter)
280-
case srv.AgentSend != "":
285+
}
286+
if srv.AgentSend != "" {
281287
pushq("agent-send", srv.AgentSend)
282-
case srv.Allow0rtt:
288+
}
289+
if srv.Allow0rtt {
283290
push("allow-0rtt")
284-
case srv.Alpn != "":
291+
}
292+
if srv.Alpn != "" {
285293
pushq("alpn", srv.Alpn)
286-
case enabled(srv.Backup):
294+
}
295+
if enabled(srv.Backup) {
287296
push("backup")
288-
case srv.SslCafile != "":
297+
}
298+
if srv.SslCafile != "" {
289299
pushq("ca-file", srv.SslCafile)
290-
case enabled(srv.Check):
300+
}
301+
if enabled(srv.Check) {
291302
push("check")
292-
case srv.CheckAlpn != "":
303+
}
304+
if srv.CheckAlpn != "" {
293305
pushq("check-alpn", srv.CheckAlpn)
294-
case srv.HealthCheckAddress != "":
306+
}
307+
if srv.HealthCheckAddress != "" {
295308
pushq("addr", srv.HealthCheckAddress)
296-
case srv.HealthCheckPort != nil:
309+
}
310+
if srv.HealthCheckPort != nil {
297311
pushi("port", srv.HealthCheckPort)
298-
case srv.CheckProto != "":
312+
}
313+
if srv.CheckProto != "" {
299314
pushq("check-proto", srv.CheckProto)
300-
case enabled(srv.CheckSendProxy):
315+
}
316+
if enabled(srv.CheckSendProxy) {
301317
push("check-send-proxy")
302-
case srv.CheckSni != "":
318+
}
319+
if srv.CheckSni != "" {
303320
pushq("check-sni", srv.CheckSni)
304-
case enabled(srv.CheckSsl):
321+
}
322+
if enabled(srv.CheckSsl) {
305323
push("check-ssl")
306-
case enabled(srv.CheckViaSocks4):
324+
}
325+
if enabled(srv.CheckViaSocks4) {
307326
push("check-via-socks4")
308-
case srv.Ciphers != "":
327+
}
328+
if srv.Ciphers != "" {
309329
pushq("ciphers", srv.Ciphers)
310-
case srv.Ciphersuites != "":
330+
}
331+
if srv.Ciphersuites != "" {
311332
pushq("ciphersuites", srv.Ciphersuites)
312-
case srv.CrlFile != "":
333+
}
334+
if srv.CrlFile != "" {
313335
pushq("crl-file", srv.CrlFile)
314-
case srv.SslCertificate != "":
336+
}
337+
if srv.SslCertificate != "" {
315338
pushq("crt", srv.SslCertificate)
316-
case enabled(srv.Maintenance):
339+
}
340+
if enabled(srv.Maintenance) {
317341
push("disabled")
318-
case srv.Downinter != nil:
342+
}
343+
if srv.Downinter != nil {
319344
pushi("downinter", srv.Downinter)
320-
case !enabled(srv.Maintenance):
345+
}
346+
if disabled(srv.Maintenance) {
321347
required := new(cn_runtime.HAProxyVersion)
322348
required.ParseHAProxyVersion("3.0.0")
323349
if !cn_runtime.IsBiggerOrEqual(required, version) {
324350
push("enabled")
325351
}
326-
case srv.ErrorLimit != nil:
352+
}
353+
if srv.ErrorLimit != nil {
327354
pushi("error-limit", srv.ErrorLimit)
328-
case srv.Fall != nil:
355+
}
356+
if srv.Fall != nil {
329357
pushi("fall", srv.Fall)
330-
case srv.Fastinter != nil:
358+
}
359+
if srv.Fastinter != nil {
331360
pushi("fastinter", srv.Fastinter)
332-
case enabled(srv.ForceSslv3):
361+
}
362+
if enabled(srv.ForceSslv3) {
333363
push("force-sslv3")
334-
case enabled(srv.ForceTlsv10):
364+
}
365+
if enabled(srv.ForceTlsv10) {
335366
push("force-tlsv10")
336-
case enabled(srv.ForceTlsv11):
367+
}
368+
if enabled(srv.ForceTlsv11) {
337369
push("force-tlsv11")
338-
case enabled(srv.ForceTlsv12):
370+
}
371+
if enabled(srv.ForceTlsv12) {
339372
push("force-tlsv12")
340-
case enabled(srv.ForceTlsv13):
373+
}
374+
if enabled(srv.ForceTlsv13) {
341375
push("force-tlsv13")
342-
case srv.ID != "":
376+
}
377+
if srv.ID != "" {
343378
pushq("id", srv.ID)
344-
case srv.Inter != nil:
379+
}
380+
if srv.Inter != nil {
345381
pushi("inter", srv.Inter)
346-
case srv.Maxconn != nil:
382+
}
383+
if srv.Maxconn != nil {
347384
pushi("maxconn", srv.Maxconn)
348-
case srv.Maxqueue != nil:
385+
}
386+
if srv.Maxqueue != nil {
349387
pushi("maxqueue", srv.Maxqueue)
350-
case srv.Minconn != nil:
388+
}
389+
if srv.Minconn != nil {
351390
pushi("minconn", srv.Minconn)
352-
case !enabled(srv.SslReuse):
391+
}
392+
if disabled(srv.SslReuse) {
353393
push("no-ssl-reuse")
354-
case enabled(srv.NoSslv3):
394+
}
395+
if enabled(srv.NoSslv3) {
355396
push("no-sslv3")
356-
case enabled(srv.NoTlsv10):
397+
}
398+
if enabled(srv.NoTlsv10) {
357399
push("no-tlsv10")
358-
case enabled(srv.NoTlsv11):
400+
}
401+
if enabled(srv.NoTlsv11) {
359402
push("no-tlsv11")
360-
case enabled(srv.NoTlsv12):
403+
}
404+
if enabled(srv.NoTlsv12) {
361405
push("no-tlsv12")
362-
case enabled(srv.NoTlsv13):
406+
}
407+
if enabled(srv.NoTlsv13) {
363408
push("no-tlsv13")
364-
case !enabled(srv.TLSTickets):
409+
}
410+
if disabled(srv.TLSTickets) {
365411
push("no-tls-tickets")
366-
case srv.Npn != "":
412+
}
413+
if srv.Npn != "" {
367414
pushq("npm", srv.Npn)
368-
case srv.Observe != "":
415+
}
416+
if srv.Observe != "" {
369417
pushq("observe", srv.Observe)
370-
case srv.OnError != "":
418+
}
419+
if srv.OnError != "" {
371420
pushq("on-error", srv.OnError)
372-
case srv.OnMarkedDown != "":
421+
}
422+
if srv.OnMarkedDown != "" {
373423
pushq("on-marked-down", srv.OnMarkedDown)
374-
case srv.OnMarkedUp != "":
424+
}
425+
if srv.OnMarkedUp != "" {
375426
pushq("on-marked-up", srv.OnMarkedUp)
376-
case srv.PoolLowConn != nil:
427+
}
428+
if srv.PoolLowConn != nil {
377429
pushi("pool-low-conn", srv.PoolLowConn)
378-
case srv.PoolMaxConn != nil:
430+
}
431+
if srv.PoolMaxConn != nil {
379432
pushi("pool-max-conn", srv.PoolMaxConn)
380-
case srv.PoolPurgeDelay != nil:
433+
}
434+
if srv.PoolPurgeDelay != nil {
381435
pushi("pool-purge-delay", srv.PoolPurgeDelay)
382-
case srv.Proto != "":
436+
}
437+
if srv.Proto != "" {
383438
pushq("proto", srv.Proto)
384-
case len(srv.ProxyV2Options) > 0:
439+
}
440+
if len(srv.ProxyV2Options) > 0 {
385441
pushq("proxy-v2-options", strings.Join(srv.ProxyV2Options, ","))
386-
case srv.Rise != nil:
442+
}
443+
if srv.Rise != nil {
387444
pushi("rise", srv.Rise)
388-
case enabled(srv.SendProxy):
445+
}
446+
if enabled(srv.SendProxy) {
389447
push("send-proxy")
390-
case enabled(srv.SendProxyV2):
448+
}
449+
if enabled(srv.SendProxyV2) {
391450
push("send-proxy-v2")
392-
case enabled(srv.SendProxyV2Ssl):
451+
}
452+
if enabled(srv.SendProxyV2Ssl) {
393453
push("send-proxy-v2-ssl")
394-
case enabled(srv.SendProxyV2SslCn):
454+
}
455+
if enabled(srv.SendProxyV2SslCn) {
395456
push("send-proxy-v2-ssl-cn")
396-
case srv.Slowstart != nil:
457+
}
458+
if srv.Slowstart != nil {
397459
pushi("slowstart", srv.Slowstart)
398-
case srv.Sni != "":
460+
}
461+
if srv.Sni != "" {
399462
pushq("sni", srv.Sni)
400-
case srv.Source != "":
463+
}
464+
if srv.Source != "" {
401465
pushq("source", srv.Source)
402-
case enabled(srv.Ssl):
466+
}
467+
if enabled(srv.Ssl) {
403468
push("ssl")
404-
case srv.SslMaxVer != "":
469+
}
470+
if srv.SslMaxVer != "" {
405471
pushq("ssl-max-ver", srv.SslMaxVer)
406-
case srv.SslMinVer != "":
472+
}
473+
if srv.SslMinVer != "" {
407474
pushq("ssl-min-ver", srv.SslMinVer)
408-
case enabled(srv.Tfo):
475+
}
476+
if enabled(srv.Tfo) {
409477
push("tfo")
410-
case enabled(srv.TLSTickets):
478+
}
479+
if enabled(srv.TLSTickets) {
411480
push("tls-tickets")
412-
case srv.Track != "":
481+
}
482+
if srv.Track != "" {
413483
pushq("track", srv.Track)
414-
/* XXX usesrc is not supported */
415-
case srv.Verify != "":
484+
}
485+
if srv.Verify != "" {
416486
pushq("verify", srv.Verify)
417-
case srv.Verifyhost != "":
487+
}
488+
if srv.Verifyhost != "" {
418489
pushq("verifyhost", srv.Verifyhost)
419-
case srv.Weight != nil:
490+
}
491+
if srv.Weight != nil {
420492
pushi("weight", srv.Weight)
421-
case srv.Ws != "":
493+
}
494+
if srv.Ws != "" {
422495
pushq("ws", srv.Ws)
423496
}
424-
425497
return b.String()
426498
}

0 commit comments

Comments
 (0)