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

Fully implement AWS4 signing support #1

Merged
merged 1 commit into from
Jul 21, 2015

Conversation

stevenh
Copy link

@stevenh stevenh commented Jun 10, 2015

Fully implement AWS4 signing support

This fully implemeents AWS4 signing support, which was only partially added by 5d9165.

This adds the Sign field to Region, which can be used to sign a request with default sign method for that region.

In addition we have a single method that implements signing of requests for each supported signing method:

  • SignV2
  • SignV4
  • SignRoute53

Fix V4Signer adding headers to the request after calculating the canonicalHeaders, due to this change all the tests have had to be updated with corrected checksums and headers.

Unfortunately it was not possible to make this change 100% backwards compatible.

The following changes are API incompatible and hence may require users to update their code:

  • Removes Signature constants, as they are not used any more
  • Removes ServiceInfo type, as its not used any more
  • Removes Signer interface, as its not compatible with all signing methods.
  • Changes the type of Region.RDSEndpoint from ServiceInfo -> string
  • Renames Region.CloudWatchServicepoint -> CloudWatchEndpoint and changes its type from ServiceInfo -> string.
  • Changes NewService from (auth Auth, serviceInfo ServiceInfo) -> (auth Auth, endpoint string, region Region).
  • Changes NewV2Signer from (auth Auth, service ServiceInfo) -> (auth Auth, endpoint string)
  • Changes NewCloudWatch from (auth aws.Auth, region aws.ServiceInfo) -> NewCloudWatch(auth aws.Auth, region aws.Region)
  • Changes CanonicalRequest return from string to string, error

Also switch to using http status code constants while I'm here to ease comprehension.

signer := aws.NewV4Signer(as.Auth, "autoscaling", as.Region)
signer.Sign(hreq)
err = aws.SignV4(hreq, as.Auth, "autoscaling", as.Region.Name)
if err != nil {
Copy link

Choose a reason for hiding this comment

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

Not going to use if err =... ; err != nil - what's the benefit of doing it this way if you're returning immediately?

Copy link
Author

Choose a reason for hiding this comment

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

Fixing

@stevenh stevenh force-pushed the s3-aws4 branch 2 times, most recently from 59839ce to 944d07a Compare June 10, 2015 16:16
@stevenh
Copy link
Author

stevenh commented Jun 10, 2015

@leepa issues addressed and did a few more http status constants that I spotted while there.

@leepa
Copy link

leepa commented Jun 10, 2015

Seems sane - I assume tests pass and if they do 👍

}
reqSignpathSpaceFix := (&url.URL{Path: signpath}).String()
req.headers["Host"] = []string{u.Host}
req.headers["Date"] = []string{time.Now().In(time.UTC).Format(time.RFC1123)}
if s3.Auth.Token() != "" {
Copy link
Author

Choose a reason for hiding this comment

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

This header shouldnt be removed.

@stevenh stevenh force-pushed the s3-aws4 branch 2 times, most recently from 209d1b5 to cadc75f Compare July 17, 2015 14:39
@darkliquid
Copy link

Being such a large change, it's hard to spot anything, but looks fine and the rationale in the commit message makes sense. Hopefully upstream will accept this, though breaking API compatibility is not going to be an easy pill to swallow I imagine.

👍 review done

}
s = &Service{service: service, signer: signer}
return
// Create a new AWS service to handle making requests
Copy link

Choose a reason for hiding this comment

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

A couple of places we don't follow the official good convention for commenting functions and in others we do. Small nit pick. http://blog.golang.org/godoc-documenting-go-code

Copy link
Author

Choose a reason for hiding this comment

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

The reason for this is not our code, the methods I've added should be commented, updated old ones not.

@kynrai
Copy link

kynrai commented Jul 17, 2015

Aside from the above two comments, review done

This fully implemeents AWS4 signing support, which was only partially added by 5d9165.

This adds the Sign field to Region, which can be used to sign a request with default sign method for that region.

In addition we have a single method that implements signing of requests for each supported signing method:
* SignV2
* SignV4
* SignRoute53

Fix V4Signer adding headers to the request after calculating the canonicalHeaders, due to this change all the tests have had to be updated with corrected checksums and headers.

Unfortunately it was not possible to make this change 100% backwards compatible.

The following changes are API incompatible and hence may require users to update their code:
* Removes Signature constants, as they are not used any more
* Removes ServiceInfo type, as its not used any more
* Removes Signer interface, as its not compatible with all signing methods.
* Changes the type of Region.RDSEndpoint from ServiceInfo -> string
* Renames Region.CloudWatchServicepoint -> CloudWatchEndpoint and changes its type from ServiceInfo -> string.
* Changes NewService from (auth Auth, serviceInfo ServiceInfo) -> (auth Auth, endpoint string, region Region).
* Changes NewV2Signer from (auth Auth, service ServiceInfo) -> (auth Auth, endpoint string)
* Changes NewCloudWatch from (auth aws.Auth, region aws.ServiceInfo) -> NewCloudWatch(auth aws.Auth, region aws.Region)
* Changes CanonicalRequest return from string to string, error

Also switch to using http status code constants while I'm here to ease comprehension.
stevenh added a commit that referenced this pull request Jul 21, 2015
Fully implement AWS4 signing support
@stevenh stevenh merged commit 34a4365 into Unity-Technologies:master Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants