From 191d9f5484f8c909b3472d483f2d9ea0c319316c Mon Sep 17 00:00:00 2001 From: Aliaksandr Mianzhynski Date: Tue, 29 Sep 2020 18:29:56 +0300 Subject: [PATCH 1/2] Fix GRPCUseTLS flag HTTP API mapping --- agent/http_decode_test.go | 58 +++++++++++++++++++++++++++++++ agent/structs/check_definition.go | 4 +++ agent/structs/check_type.go | 4 +++ 3 files changed, 66 insertions(+) diff --git a/agent/http_decode_test.go b/agent/http_decode_test.go index 32c59cec2..bbfabc6c3 100644 --- a/agent/http_decode_test.go +++ b/agent/http_decode_test.go @@ -282,6 +282,7 @@ var translateCheckTypeTCs = [][]translateKeyTestCase{ translateScriptArgsTCs, translateDeregisterTCs, translateDockerTCs, + translateGRPCUseTLSTCs, translateTLSTCs, 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 func serviceIDEqFn(out interface{}, want interface{}) error { var got interface{} diff --git a/agent/structs/check_definition.go b/agent/structs/check_definition.go index 08119ab89..82c36a16d 100644 --- a/agent/structs/check_definition.go +++ b/agent/structs/check_definition.go @@ -63,6 +63,7 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"` DockerContainerIDSnake string `json:"docker_container_id"` TLSSkipVerifySnake bool `json:"tls_skip_verify"` + GRPCUseTLSSnake bool `json:"grpc_use_tls"` ServiceIDSnake string `json:"service_id"` *Alias @@ -89,6 +90,9 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { if aux.TLSSkipVerifySnake { t.TLSSkipVerify = aux.TLSSkipVerifySnake } + if aux.GRPCUseTLSSnake { + t.GRPCUseTLS = aux.GRPCUseTLSSnake + } if t.ServiceID == "" { t.ServiceID = aux.ServiceIDSnake } diff --git a/agent/structs/check_type.go b/agent/structs/check_type.go index e1b8f53f8..0cf256cc8 100644 --- a/agent/structs/check_type.go +++ b/agent/structs/check_type.go @@ -76,6 +76,7 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) { DeregisterCriticalServiceAfterSnake interface{} `json:"deregister_critical_service_after"` DockerContainerIDSnake string `json:"docker_container_id"` 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 // 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 { t.TLSSkipVerify = aux.TLSSkipVerifySnake } + if aux.GRPCUseTLSSnake { + t.GRPCUseTLS = aux.GRPCUseTLSSnake + } if aux.Interval != nil { switch v := aux.Interval.(type) { From 73ebb31a1e0c102e08d8d24f13634cf3acb630d8 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 20 Oct 2020 16:42:06 -0400 Subject: [PATCH 2/2] Add changelog entry --- .changelog/8771.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changelog/8771.txt diff --git a/.changelog/8771.txt b/.changelog/8771.txt new file mode 100644 index 000000000..57b68665a --- /dev/null +++ b/.changelog/8771.txt @@ -0,0 +1,4 @@ +```release-note:bug +api: Fixed a bug where the Check.GRPCUseTLS field could not be set using snake case. +``` +