-
Notifications
You must be signed in to change notification settings - Fork 34
Signed query #11
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
base: master
Are you sure you want to change the base?
Signed query #11
Conversation
|
Hmm, overwriting the query is pretty messy. And that conversion on the timestamp doesn't work. Hmm, maybe I'll just pass in an expires string for 'date' and then pull out the auth (rough code): func s3Url(bucket, key string) string {
return fmt.Sprintf("https://s3-external-1.amazonaws.com/%s/%s/%s", bucket, domain, key)
}
func s3SignedUrl(method, bucket, key string) (string, error) {
req, err := http.NewRequest(method, s3Url(bucket, key), nil)
if err != nil {
return "", err
}
expires := strconv.Itoa(int(time.Now().Unix())+3600)
req.Header.Set("Date", expires)
s3.Sign(req, keys)
auth := strings.Split(req.Header.Get("Authorization"), ":")
url := s3Url(bucket, key)+"?Signature="+auth[1]+"&Expires="+expires+"&AWSAccessKeyId="+keys.AccessKey
return url, nil
} |
|
You referring to I feel like this function should actually not modify the request, I'm not worried about duplicating code in writeSigURLData. It can |
|
Oh wow, does that work to pull out the auth header like that? |
|
Guess I didn't ready the spec closely enough, I see, the date Your code snippet in the comment above suggests it would be func Signature(r *http.Request, t time.Time, k Keys) stringThat would be used by the existing Sign and would also |
|
@kr yeah, I think that would be great. I've been going back and forth whether it would actually be cool to expose a Signer that's independent of the request - right now, I'm building the request essentially just to pass headers. Is there a way to just capture the the signing as simply as possible? |
|
Yeah good question. The string to sign has all these If you already have those parts sitting around separately, Signature(url, method, header, time, keys)
// vs
Signature(&http.Request{URL:url, Method:method, Header:header}, time, keys)Even though it's more code, I prefer the second one because (And if you have no headers to add, it could be a little shorter:) Signature(&http.Request{URL:url, Method:method}, time, keys)(This wouldn't work currently because package s3 assumes the |
Pass the signature as a query parameter. Takes a
time.Timeparameter. Don't love the SignURL name - SignQuery?Duplicating writeSigData with writeSigURLData - could fold these in to the same routine, and check for whether a time value got passed in and the either do
data' orexpires`.Not sure if this works. Also needs tests.