Skip to content

Fix GRPCUseTLS flag HTTP API mapping #8771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/8771.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
api: Fixed a bug where the Check.GRPCUseTLS field could not be set using snake case.
```

58 changes: 58 additions & 0 deletions agent/http_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ var translateCheckTypeTCs = [][]translateKeyTestCase{
translateScriptArgsTCs,
translateDeregisterTCs,
translateDockerTCs,
translateGRPCUseTLSTCs,
translateTLSTCs,
translateServiceIDTCs,
}
Expand Down Expand Up @@ -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{}
Expand Down
4 changes: 4 additions & 0 deletions agent/structs/check_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions agent/structs/check_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down