terraform/builtin/providers/aws/utils.go

20 lines
609 B
Go

package aws
import "encoding/base64"
// 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
}