Skip to content

Commit

Permalink
Replace NormalizeJsonString with local helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Nam authored and Sharon Nam committed Jun 21, 2023
1 parent 5108afe commit c322122
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion internal/service/events/rule.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package events

import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -65,7 +67,7 @@ func ResourceRule() *schema.Resource {
ValidateFunc: validateEventPatternValue(),
AtLeastOneOf: []string{"schedule_expression", "event_pattern"},
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v.(string))
json, _ := JsonMarshal(v.(string), true)
return json
},
},
Expand Down Expand Up @@ -107,6 +109,31 @@ func ResourceRule() *schema.Resource {

CustomizeDiff: verify.SetTagsDiff,
}

}

func JsonMarshal(jsonString interface{}, safe bool) (string, error) {
var j interface{}

if jsonString == nil || jsonString.(string) == "" {
return "", nil
}

s := jsonString.(string)

err := json.Unmarshal([]byte(s), &j)
if err != nil {
return s, err
}

b, _ := json.Marshal(j)

if safe {
b = bytes.Replace(b, []byte("\\u003c"), []byte("<"), -1)
b = bytes.Replace(b, []byte("\\u003e"), []byte(">"), -1)
b = bytes.Replace(b, []byte("\\u0026"), []byte("&"), -1)
}
return string(b[:]), nil
}

func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down

0 comments on commit c322122

Please sign in to comment.