Debian Codegraph @

storage/internal/auth/authorizer_shared_key_lite_table.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 // SharedKeyLiteTableAuthorizer implements an authorization for Shared Key Lite
11 // this can be used for interaction with Table Storage Endpoints
12 type SharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer# struct {
13 storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#storageAccountName. string
14 storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#storageAccountKey. string
15 }
16
17 // NewSharedKeyLiteAuthorizer crates a SharedKeyLiteAuthorizer using the given credentials
18 func NewSharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/NewSharedKeyLiteTableAuthorizer().(accountName, accountKey string) *SharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer# {
19 return &SharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#{
20 storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#storageAccountName.: accountName,
21 storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#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 *SharedKeyLiteTableAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#) WithAuthorizationscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#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 := buildSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildSharedKeyLiteTable().(skl.storageAccountNamescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#storageAccountName., skl.storageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/SharedKeyLiteTableAuthorizer#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`/SharedKeyLiteTableAuthorizer#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
52 func buildSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildSharedKeyLiteTable().(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) {
53 // first ensure the relevant headers are configured
54 prepareHeadersForRequestscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/prepareHeadersForRequest().(r)
55
56 sharedKey, err := computeSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/computeSharedKeyLiteTable().(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.)
57 if err != nil {
58 return nil, err
59 }
60
61 // we then need to HMAC that value
62 hmacdValue := hmacValuescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/hmacValue().(storageAccountKey, *sharedKey)
63 return &hmacdValue, nil
64 }
65
66 // computeSharedKeyLite computes the Shared Key Lite required for Storage Authentication
67 // NOTE: this function assumes that the `x-ms-date` field is set
68 func computeSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/computeSharedKeyLiteTable().(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) {
69 dateHeader := headers.Getscip-go gomod github.com/golang/go/src go1.13 `net/http`/Header#Get().("x-ms-date")
70 canonicalizedResource, err := buildCanonicalizedResourcescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedResource().(url, accountName)
71 if err != nil {
72 return nil, err
73 }
74
75 canonicalizedString := buildCanonicalizedStringForSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedStringForSharedKeyLiteTable().(*canonicalizedResource, dateHeader)
76 return &canonicalizedString, nil
77 }
78
79 func buildCanonicalizedStringForSharedKeyLiteTablescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/buildCanonicalizedStringForSharedKeyLiteTable().(canonicalizedResource, dateHeader string) string {
80 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{
81 dateHeader,
82 canonicalizedResource,
83 }, "\n")
84 }