forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (35 loc) · 1017 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package aws
import (
"encoding/base64"
"encoding/json"
"reflect"
"regexp"
)
// Base64Encode encodes data if the input isn't already encoded using base64.StdEncoding.EncodeToString.
// If the input is already base64 encoded, return the original input unchanged.
func base64Encode(data []byte) string {
// Check whether the data is already Base64 encoded; don't double-encode
if isBase64Encoded(data) {
return string(data)
}
// data has not been encoded encode and return
return base64.StdEncoding.EncodeToString(data)
}
func isBase64Encoded(data []byte) bool {
_, err := base64.StdEncoding.DecodeString(string(data))
return err == nil
}
func looksLikeJsonString(s interface{}) bool {
return regexp.MustCompile(`^\s*{`).MatchString(s.(string))
}
func jsonBytesEqual(b1, b2 []byte) bool {
var o1 interface{}
if err := json.Unmarshal(b1, &o1); err != nil {
return false
}
var o2 interface{}
if err := json.Unmarshal(b2, &o2); err != nil {
return false
}
return reflect.DeepEqual(o1, o2)
}