~jtv/gwacl/close-body

« back to all changes in this revision

Viewing changes to storage_base.go

  • Committer: Tarmac
  • Author(s): Raphael Badin
  • Date: 2013-07-26 10:51:26 UTC
  • mfrom: (199.2.7 signed-access)
  • Revision ID: tarmac-20130726105126-tap0rioeb63uefk0
[r=julian-edwards][bug=][author=rvb] Add support for the Windows Azure Shared Access Signature URL mechanism.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    "Range",
42
42
}
43
43
 
44
 
// Calculate the value required for an Authorization header.
45
 
func composeAuthHeader(req *http.Request, accountName, accountKey string) string {
46
 
    signable := composeStringToSign(req, accountName)
 
44
// sign returns the base64-encoded HMAC-SHA256 signature of the given string
 
45
// using the given base64-encoded key.
 
46
func sign(accountKey, signable string) string {
47
47
    // Allegedly, this is already UTF8 encoded.
48
48
    decodedKey, err := base64.StdEncoding.DecodeString(accountKey)
49
49
    if err != nil {
57
57
    var hashed []byte
58
58
    hashed = hash.Sum(hashed)
59
59
    b64Hashed := base64.StdEncoding.EncodeToString(hashed)
 
60
    return b64Hashed
 
61
}
 
62
 
 
63
// Calculate the value required for an Authorization header.
 
64
func composeAuthHeader(req *http.Request, accountName, accountKey string) string {
 
65
    signable := composeStringToSign(req, accountName)
 
66
 
 
67
    b64Hashed := sign(accountKey, signable)
60
68
    return fmt.Sprintf("SharedKey %s:%s", accountName, b64Hashed)
61
69
}
62
70
 
338
346
    return context.getContainerURL(container) + "/" + url.QueryEscape(filename)
339
347
}
340
348
 
 
349
// GetAnonymousFileURL returns an anonymously-accessible URL for a given file
 
350
// in the given container.
 
351
func (context *StorageContext) GetAnonymousFileURL(container, filename string, expires time.Time) string {
 
352
    url := context.GetFileURL(container, filename)
 
353
    values := getReadBlobAccessValues(container, filename, context.Account, context.Key, expires)
 
354
    return fmt.Sprintf("%s?%s", url, values.Encode())
 
355
}
 
356
 
341
357
type ListContainersRequest struct {
342
358
    Marker string
343
359
}