Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: fixes double base64 encode #10871

Merged
merged 1 commit into from
Dec 27, 2016

Conversation

curtisallen
Copy link
Contributor

@curtisallen curtisallen commented Dec 20, 2016

Add a utility that ensures a byte array is not doubly base64 encoded

Reference https://play.golang.org/p/RnEBFCJ9h0
Fixes #10786

@curtisallen curtisallen changed the title fixes double base64 encode provider/aws: fixes double base64 encode Dec 20, 2016
@@ -0,0 +1,13 @@
package aws
Copy link

@nathany nathany Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a generic utils.go file, maybe this file should be named base64.go and likewise for the test file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was looking for examples in other packages on what to name this file. In the aws package, there's an auth_helper.go. In other packages there are utils.go, just not sure which is the best fit for this use case.

func base64Encode(data []byte) string {
// Check whether the user_data is already Base64 encoded; don't double-encode
if _, base64DecodeError := base64.StdEncoding.DecodeString(string(data)); base64DecodeError != nil {
return base64.StdEncoding.EncodeToString(data)
Copy link

@nathany nathany Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since an error represents the expected path of not being encoded and therefore needing encoding, this may be clearer with a few more comments. // not encoded, so encode it // already encoded.

Or maybe splitting out an isBase64Encoded() bool function instead?

Copy link

@nathany nathany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good change to me, applying the same base64Encode logic consistently.

Copy link

@nathany nathany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

just a few comments on the comments

// Base64Encode encodes data if the input isn't already encoded useing base64.StdEncoding.EncodeToString.
// If the input is already base64 encoded, return the original input unchanged.
func base64Encode(data []byte) string {
// Check whether the user_data is already Base64 encoded; don't double-encode
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this context it's just data, not user_data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks will fix


import "encoding/base64"

// Base64Encode encodes data if the input isn't already encoded useing base64.StdEncoding.EncodeToString.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/useing/using/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops good catch

Add a utility that ensures a byte array is not doubly base64 encoded
Fixes hashicorp#10786
@jen20
Copy link
Contributor

jen20 commented Dec 27, 2016

This LGTM, I'm going to rename the file after merge however. Thanks @curtisallen!

@jen20 jen20 merged commit fce99df into hashicorp:master Dec 27, 2016
@nathany
Copy link

nathany commented Jan 4, 2017

Thanks James. Did you intend to rename utils.go?

hub is pretty useful for amending pull requests (see article)

@ghost
Copy link

ghost commented Apr 18, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provider AWS: Autoscaling Launch Configuration base64 encodes user_data regardless of input
3 participants