github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/utils.go (about)

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