Skip to content

Commit

Permalink
do proper validation in sdk validator
Browse files Browse the repository at this point in the history
  • Loading branch information
jharley committed Mar 18, 2024
1 parent a3b686e commit 6cb2607
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions honeycombio/query_spec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package honeycombio

import (
"bytes"
"encoding/json"

"github.com/hashicorp/go-cty/cty"
Expand All @@ -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")
}

Expand Down

0 comments on commit 6cb2607

Please sign in to comment.