Fix GRPCUseTLS flag HTTP API mapping

This commit is contained in:
Aliaksandr Mianzhynski 2020-09-29 18:29:56 +03:00
parent e84c032ea7
commit 191d9f5484
3 changed files with 66 additions and 0 deletions

View File

@ -282,6 +282,7 @@ var translateCheckTypeTCs = [][]translateKeyTestCase{
translateScriptArgsTCs, translateScriptArgsTCs,
translateDeregisterTCs, translateDeregisterTCs,
translateDockerTCs, translateDockerTCs,
translateGRPCUseTLSTCs,
translateTLSTCs, translateTLSTCs,
translateServiceIDTCs, translateServiceIDTCs,
} }
@ -560,6 +561,63 @@ var translateTLSTCs = []translateKeyTestCase{
}, },
} }
// GRPCUseTLS: bool
func grpcUseTLSEqFn(out interface{}, want interface{}) error {
var got interface{}
switch v := out.(type) {
case structs.CheckDefinition:
got = v.GRPCUseTLS
case *structs.CheckDefinition:
got = v.GRPCUseTLS
case structs.CheckType:
got = v.GRPCUseTLS
case *structs.CheckType:
got = v.GRPCUseTLS
case structs.HealthCheckDefinition:
got = v.GRPCUseTLS
case *structs.HealthCheckDefinition:
got = v.GRPCUseTLS
default:
panic(fmt.Sprintf("unexpected type %T", out))
}
if got != want {
return fmt.Errorf("expected GRPCUseTLS to be %v, got %v", want, got)
}
return nil
}
var grpcUseTLSFields = []string{`"GRPCUseTLS": %s`, `"grpc_use_tls": %s`}
var translateGRPCUseTLSTCs = []translateKeyTestCase{
{
desc: "GRPCUseTLS: both set",
in: []interface{}{"true", "false"},
want: true,
jsonFmtStr: "{" + strings.Join(grpcUseTLSFields, ",") + "}",
equalityFn: grpcUseTLSEqFn,
},
{
desc: "GRPCUseTLS: first set",
in: []interface{}{`true`},
want: true,
jsonFmtStr: "{" + grpcUseTLSFields[0] + "}",
equalityFn: grpcUseTLSEqFn,
},
{
desc: "GRPCUseTLS: second set",
in: []interface{}{`true`},
want: true,
jsonFmtStr: "{" + grpcUseTLSFields[1] + "}",
equalityFn: grpcUseTLSEqFn,
},
{
desc: "GRPCUseTLS: neither set",
in: []interface{}{},
want: false, // zero value
jsonFmtStr: "{}",
equalityFn: grpcUseTLSEqFn,
},
}
// ServiceID: string // ServiceID: string
func serviceIDEqFn(out interface{}, want interface{}) error { func serviceIDEqFn(out interface{}, want interface{}) error {
var got interface{} var got interface{}

View File

@ -63,6 +63,7 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) {
DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"` DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"`
DockerContainerIDSnake string `json:"docker_container_id"` DockerContainerIDSnake string `json:"docker_container_id"`
TLSSkipVerifySnake bool `json:"tls_skip_verify"` TLSSkipVerifySnake bool `json:"tls_skip_verify"`
GRPCUseTLSSnake bool `json:"grpc_use_tls"`
ServiceIDSnake string `json:"service_id"` ServiceIDSnake string `json:"service_id"`
*Alias *Alias
@ -89,6 +90,9 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) {
if aux.TLSSkipVerifySnake { if aux.TLSSkipVerifySnake {
t.TLSSkipVerify = aux.TLSSkipVerifySnake t.TLSSkipVerify = aux.TLSSkipVerifySnake
} }
if aux.GRPCUseTLSSnake {
t.GRPCUseTLS = aux.GRPCUseTLSSnake
}
if t.ServiceID == "" { if t.ServiceID == "" {
t.ServiceID = aux.ServiceIDSnake t.ServiceID = aux.ServiceIDSnake
} }

View File

@ -76,6 +76,7 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) {
DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"` DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"`
DockerContainerIDSnake string `json:"docker_container_id"` DockerContainerIDSnake string `json:"docker_container_id"`
TLSSkipVerifySnake bool `json:"tls_skip_verify"` TLSSkipVerifySnake bool `json:"tls_skip_verify"`
GRPCUseTLSSnake bool `json:"grpc_use_tls"`
// These are going to be ignored but since we are disallowing unknown fields // These are going to be ignored but since we are disallowing unknown fields
// during parsing we have to be explicit about parsing but not using these. // during parsing we have to be explicit about parsing but not using these.
@ -104,6 +105,9 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) {
if aux.TLSSkipVerifySnake { if aux.TLSSkipVerifySnake {
t.TLSSkipVerify = aux.TLSSkipVerifySnake t.TLSSkipVerify = aux.TLSSkipVerifySnake
} }
if aux.GRPCUseTLSSnake {
t.GRPCUseTLS = aux.GRPCUseTLSSnake
}
if aux.Interval != nil { if aux.Interval != nil {
switch v := aux.Interval.(type) { switch v := aux.Interval.(type) {