only set default on H2PingUseTLS if H2PING is set

This commit is contained in:
tarat44 2021-10-06 22:13:01 -04:00
parent c5479cefe6
commit ecdcfd6360
5 changed files with 22 additions and 4 deletions

View File

@ -1541,6 +1541,13 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
return nil return nil
} }
var H2PingUseTLSVal bool
if stringVal(v.H2PING) != "" {
H2PingUseTLSVal = boolValWithDefault(v.H2PingUseTLS, true)
} else {
H2PingUseTLSVal = boolVal(v.H2PingUseTLS)
}
id := types.CheckID(stringVal(v.ID)) id := types.CheckID(stringVal(v.ID))
return &structs.CheckDefinition{ return &structs.CheckDefinition{
@ -1571,7 +1578,7 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
FailuresBeforeCritical: intVal(v.FailuresBeforeCritical), FailuresBeforeCritical: intVal(v.FailuresBeforeCritical),
FailuresBeforeWarning: intValWithDefault(v.FailuresBeforeWarning, intVal(v.FailuresBeforeCritical)), FailuresBeforeWarning: intValWithDefault(v.FailuresBeforeWarning, intVal(v.FailuresBeforeCritical)),
H2PING: stringVal(v.H2PING), H2PING: stringVal(v.H2PING),
H2PingUseTLS: boolValWithDefault(v.H2PingUseTLS, true), H2PingUseTLS: H2PingUseTLSVal,
DeregisterCriticalServiceAfter: b.durationVal(fmt.Sprintf("check[%s].deregister_critical_service_after", id), v.DeregisterCriticalServiceAfter), DeregisterCriticalServiceAfter: b.durationVal(fmt.Sprintf("check[%s].deregister_critical_service_after", id), v.DeregisterCriticalServiceAfter),
OutputMaxSize: intValWithDefault(v.OutputMaxSize, checks.DefaultBufSize), OutputMaxSize: intValWithDefault(v.OutputMaxSize, checks.DefaultBufSize),
EnterpriseMeta: v.EnterpriseMeta.ToStructs(), EnterpriseMeta: v.EnterpriseMeta.ToStructs(),

View File

@ -5638,7 +5638,6 @@ func TestLoad_FullConfig(t *testing.T) {
Timeout: 4868 * time.Second, Timeout: 4868 * time.Second,
TTL: 11222 * time.Second, TTL: 11222 * time.Second,
DeregisterCriticalServiceAfter: 68482 * time.Second, DeregisterCriticalServiceAfter: 68482 * time.Second,
H2PingUseTLS: true,
}, },
}, },
Connect: &structs.ServiceConnect{}, Connect: &structs.ServiceConnect{},

View File

@ -729,7 +729,7 @@ var translateH2PingUseTLS = []translateKeyTestCase{
desc: "H2PingUseTLS: neither set", desc: "H2PingUseTLS: neither set",
in: []interface{}{}, in: []interface{}{},
want: true, // zero value want: true, // zero value
jsonFmtStr: "{}", jsonFmtStr: "{" + `"h2ping":"testing"` + "}",
equalityFn: h2pingUseTLSEqFn, equalityFn: h2pingUseTLSEqFn,
}, },
} }

View File

@ -76,7 +76,7 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) {
}{ }{
Alias: (*Alias)(t), Alias: (*Alias)(t),
} }
// Set default values
aux.H2PingUseTLS = true aux.H2PingUseTLS = true
aux.H2PingUseTLSSnake = true aux.H2PingUseTLSSnake = true
if err = lib.UnmarshalJSON(data, &aux); err != nil { if err = lib.UnmarshalJSON(data, &aux); err != nil {
@ -111,6 +111,11 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) {
if !aux.H2PingUseTLSSnake { if !aux.H2PingUseTLSSnake {
t.H2PingUseTLS = aux.H2PingUseTLSSnake t.H2PingUseTLS = aux.H2PingUseTLSSnake
} }
// unset default values if it is not an H2Ping check
if t.H2PING == "" {
aux.H2PingUseTLS = false
aux.H2PingUseTLSSnake = false
}
// Parse special values // Parse special values
if aux.Interval != nil { if aux.Interval != nil {

View File

@ -93,8 +93,10 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) {
}{ }{
Alias: (*Alias)(t), Alias: (*Alias)(t),
} }
// set default values
aux.H2PingUseTLS = true aux.H2PingUseTLS = true
aux.H2PingUseTLSSnake = true aux.H2PingUseTLSSnake = true
if err = lib.UnmarshalJSON(data, aux); err != nil { if err = lib.UnmarshalJSON(data, aux); err != nil {
return err return err
} }
@ -162,6 +164,11 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) {
if !aux.H2PingUseTLSSnake { if !aux.H2PingUseTLSSnake {
t.H2PingUseTLS = aux.H2PingUseTLSSnake t.H2PingUseTLS = aux.H2PingUseTLSSnake
} }
// unset default values if it is not an H2Ping check
if t.H2PING == "" {
aux.H2PingUseTLS = false
aux.H2PingUseTLSSnake = false
}
return nil return nil