Debian Codegraph @

storage/internal/auth/authorizer_shared_key_lite.go

raw symbols SCIP
1 package authscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/
2
3 import (
4 "net/httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/"
5 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
6
7 "github.com/Azure/go-autorest/autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/"
8 )
9
10 // SharedKeyLiteAuthorizer implements an authorization for Shared Key Lite
11 // this can be used for interaction with Blob, File and Queue Storage Endpoints
12 type SharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer# struct {
13 storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountName. string
14 storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountKey. string
15 }
16
17 // NewSharedKeyLiteAuthorizer crates a SharedKeyLiteAuthorizer using the given credentials
18 func NewSharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/NewSharedKeyLiteAuthorizer().(accountName, accountKey string) *SharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer# {
19 return &SharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#{
20 storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountName.: accountName,
21 storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountKey.: accountKey,
22 }
23 }
24
25 // WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose
26 // value is "SharedKeyLite " followed by the computed key.
27 // This can be used for the Blob, Queue, and File Services
28 //
29 // from: https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key
30 // You may use Shared Key Lite authorization to authorize a request made against the
31 // 2009-09-19 version and later of the Blob and Queue services,
32 // and version 2014-02-14 and later of the File services.
33 func (skl *SharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#) WithAuthorizationscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#WithAuthorization().() autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.PrepareDecoratorscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/PrepareDecorator# {
34 return func(p autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.Preparerscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/Preparer#) autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.Preparerscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/Preparer# {
35 return autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.PreparerFuncscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/PreparerFunc#(func(r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#, error) {
36 r, err := p.Preparescip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/Preparer#Prepare().(r)
37 if err != nil {
38 return r, err
39 }
40
41 key, err := buildSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildSharedKeyLite().(skl.storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountName., skl.storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountKey., r)
42 if err != nil {
43 return r, err
44 }
45
46 sharedKeyHeader := formatSharedKeyLiteAuthorizationHeaderscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/formatSharedKeyLiteAuthorizationHeader().(skl.storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteAuthorizer#storageAccountName., *key)
47 return autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.Preparescip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/Prepare().(r, autorestscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/.WithHeaderscip-go gomod github.com/Azure/go-autorest/autorest v0.11.19 `github.com/Azure/go-autorest/autorest`/WithHeader().(HeaderAuthorizationscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/HeaderAuthorization., sharedKeyHeader))
48 })
49 }
50 }
51 func buildSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildSharedKeyLite().(accountName, storageAccountKey string, r *httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#) (*string, error) {
52 // first ensure the relevant headers are configured
53 prepareHeadersForRequestscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/prepareHeadersForRequest().(r)
54
55 sharedKey, err := computeSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/computeSharedKeyLite().(r.Methodscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#Method., r.URLscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#URL..Stringscip-go gomod github.com/golang/go/src go1.13 `net/url`/URL#String().(), accountName, r.Headerscip-go gomod github.com/golang/go/src go1.13 `net/http`/Request#Header.)
56 if err != nil {
57 return nil, err
58 }
59
60 // we then need to HMAC that value
61 hmacdValue := hmacValuescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/hmacValue().(storageAccountKey, *sharedKey)
62 return &hmacdValue, nil
63 }
64
65 // computeSharedKeyLite computes the Shared Key Lite required for Storage Authentication
66 // NOTE: this function assumes that the `x-ms-date` field is set
67 func computeSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/computeSharedKeyLite().(verb, url string, accountName string, headers httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#) (*string, error) {
68 canonicalizedResource, err := buildCanonicalizedResourcescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedResource().(url, accountName)
69 if err != nil {
70 return nil, err
71 }
72
73 canonicalizedHeaders := buildCanonicalizedHeaderscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedHeader().(headers)
74 canonicalizedString := buildCanonicalizedStringForSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedStringForSharedKeyLite().(verb, headers, canonicalizedHeaders, *canonicalizedResource)
75 return &canonicalizedString, nil
76 }
77
78 func buildCanonicalizedStringForSharedKeyLitescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedStringForSharedKeyLite().(verb string, headers httpscip-go gomod github.com/golang/go/src go1.13 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#, canonicalizedHeaders, canonicalizedResource string) string {
79 return stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Joinscip-go gomod github.com/golang/go/src go1.13 strings/Join().([]string{
80 verb,
81 headers.Getscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#Get().(HeaderContentMD5scip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/HeaderContentMD5.), // TODO: this appears to always be empty?
82 headers.Getscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#Get().(HeaderContentTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/HeaderContentType.),
83 "", // date should be nil, apparently :shrug:
84 canonicalizedHeaders,
85 canonicalizedResource,
86 }, "\n")
87 }