forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
26 lines (22 loc) · 734 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
package aws
import (
"encoding/base64"
"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))
}