github.com/simonswine/terraform@v0.9.0-beta2/builtin/providers/aws/utils.go (about)

     1  package aws
     2  
     3  import (
     4  	"encoding/base64"
     5  	"regexp"
     6  )
     7  
     8  // Base64Encode encodes data if the input isn't already encoded using base64.StdEncoding.EncodeToString.
     9  // If the input is already base64 encoded, return the original input unchanged.
    10  func base64Encode(data []byte) string {
    11  	// Check whether the data is already Base64 encoded; don't double-encode
    12  	if isBase64Encoded(data) {
    13  		return string(data)
    14  	}
    15  	// data has not been encoded encode and return
    16  	return base64.StdEncoding.EncodeToString(data)
    17  }
    18  
    19  func isBase64Encoded(data []byte) bool {
    20  	_, err := base64.StdEncoding.DecodeString(string(data))
    21  	return err == nil
    22  }
    23  
    24  func looksLikeJsonString(s interface{}) bool {
    25  	return regexp.MustCompile(`^\s*{`).MatchString(s.(string))
    26  }