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

Make storage client work correctly with read only secondary accounts #376

Merged
merged 2 commits into from
Aug 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (c Client) GetFileService() FileServiceClient {

func (c Client) createAuthorizationHeader(canonicalizedString string) string {
signature := c.computeHmac256(canonicalizedString)
return fmt.Sprintf("%s %s:%s", "SharedKey", c.accountName, signature)
return fmt.Sprintf("%s %s:%s", "SharedKey", c.getCanonicalizedAccountName(), signature)
}

func (c Client) getAuthorizationHeader(verb, url string, headers map[string]string) (string, error) {
Expand All @@ -255,6 +255,12 @@ func (c Client) getStandardHeaders() map[string]string {
}
}

func (c Client) getCanonicalizedAccountName() string {
// since we may be trying to access a secondary storage account, we need to
// remove the -secondary part of the storage name
return strings.TrimSuffix(c.accountName, "-secondary")
}

func (c Client) buildCanonicalizedHeader(headers map[string]string) string {
cm := make(map[string]string)

Expand Down Expand Up @@ -296,7 +302,7 @@ func (c Client) buildCanonicalizedResourceTable(uri string) (string, error) {
return "", fmt.Errorf(errMsg, err.Error())
}

cr := "/" + c.accountName
cr := "/" + c.getCanonicalizedAccountName()

if len(u.Path) > 0 {
cr += u.Path
Expand All @@ -312,7 +318,7 @@ func (c Client) buildCanonicalizedResource(uri string) (string, error) {
return "", fmt.Errorf(errMsg, err.Error())
}

cr := "/" + c.accountName
cr := "/" + c.getCanonicalizedAccountName()

if len(u.Path) > 0 {
// Any portion of the CanonicalizedResource string that is derived from
Expand Down