From 6cb260793eacf0fb3e5208422d28a8187eab5561 Mon Sep 17 00:00:00 2001 From: Jason Harley Date: Mon, 18 Mar 2024 15:08:23 -0400 Subject: [PATCH] do proper validation in sdk validator --- honeycombio/query_spec.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/honeycombio/query_spec.go b/honeycombio/query_spec.go index e650b511..de8bc565 100644 --- a/honeycombio/query_spec.go +++ b/honeycombio/query_spec.go @@ -1,6 +1,7 @@ package honeycombio import ( + "bytes" "encoding/json" "github.com/hashicorp/go-cty/cty" @@ -17,9 +18,9 @@ type querySpecValidateDiagFunc func(q *honeycombio.QuerySpec) diag.Diagnostics func validateQueryJSON(validators ...querySpecValidateDiagFunc) schema.SchemaValidateDiagFunc { return func(i interface{}, path cty.Path) diag.Diagnostics { var q honeycombio.QuerySpec - - err := json.Unmarshal([]byte(i.(string)), &q) - if err != nil { + dec := json.NewDecoder(bytes.NewReader([]byte(i.(string)))) + dec.DisallowUnknownFields() + if err := dec.Decode(&q); err != nil { return diag.Errorf("value of query_json is not a valid query specification") }