Skip to content

Commit

Permalink
Storage fixes (#14395)
Browse files Browse the repository at this point in the history
Omit x-ms-blob-type request header for AppendBlock() operation.
Fixed XML error unmarshalling for some table APIs.
  • Loading branch information
jhendrixMSFT committed Mar 5, 2021
1 parent 66e4cea commit 4b53918
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 152 deletions.
1 change: 0 additions & 1 deletion storage/appendblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ type AppendBlockOptions struct {
func (b *Blob) AppendBlock(chunk []byte, options *AppendBlockOptions) error {
params := url.Values{"comp": {"appendblock"}}
headers := b.Container.bsc.client.getStandardHeaders()
headers["x-ms-blob-type"] = string(BlobTypeAppend)
headers["Content-Length"] = fmt.Sprintf("%v", len(chunk))

if options != nil {
Expand Down
34 changes: 32 additions & 2 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ type AzureStorageServiceError struct {
APIVersion string
}

// AzureTablesServiceError contains fields of the error response from
// Azure Table Storage Service REST API in Atom format.
// See https://msdn.microsoft.com/en-us/library/azure/dd179382.aspx
type AzureTablesServiceError struct {
Code string `xml:"code"`
Message string `xml:"message"`
StatusCode int
RequestID string
Date string
APIVersion string
}

func (e AzureTablesServiceError) Error() string {
return fmt.Sprintf("storage: service returned error: StatusCode=%d, ErrorCode=%s, ErrorMessage=%s, RequestInitiated=%s, RequestId=%s, API Version=%s",
e.StatusCode, e.Code, e.Message, e.Date, e.RequestID, e.APIVersion)
}

type odataErrorMessage struct {
Lang string `json:"lang"`
Value string `json:"value"`
Expand Down Expand Up @@ -828,8 +845,21 @@ func (c Client) execInternalJSONCommon(verb, url string, headers map[string]stri
err = serviceErrFromStatusCode(resp.StatusCode, resp.Status, requestID, date, version)
return respToRet, req, resp, err
}
// try unmarshal as odata.error json
err = json.Unmarshal(respBody, &respToRet.odata)
// response contains storage service error object, unmarshal
if resp.Header.Get("Content-Type") == "application/xml" {
storageErr := AzureTablesServiceError{
StatusCode: resp.StatusCode,
RequestID: requestID,
Date: date,
APIVersion: version,
}
if err := xml.Unmarshal(respBody, &storageErr); err != nil {
storageErr.Message = fmt.Sprintf("Response body could no be unmarshaled: %v. Body: %v.", err, string(respBody))
}
err = storageErr
} else {
err = json.Unmarshal(respBody, &respToRet.odata)
}
}

return respToRet, req, resp, err
Expand Down
58 changes: 27 additions & 31 deletions storage/recordings/AppendBlobSuite/TestPutAppendBlob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ interactions:
form: {}
headers:
Authorization:
- SharedKey golangrocksonazure:5lvWHtXWMNCv807HBlQbFhmXKbfOp3A8dq/tTGxoDIc=
- SharedKey golangrocksonazure:VQ3U3AgA+6jRRSVnwOeixfwpL1la5l4HFITEws73a2Q=
User-Agent:
- Go/go1.12.4 (amd64-windows) azure-storage-go/latest api-version/2018-03-28
- Go/go1.15.1 (amd64-windows) azure-storage-go/v51.3.0 api-version/2018-03-28
blob
x-ms-date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
x-ms-version:
- "2018-03-28"
url: https://golangrocksonazure.blob.core.windows.net/cnt-33appendblobsuitetestputappe?restype=container
Expand All @@ -22,15 +22,15 @@ interactions:
Content-Length:
- "0"
Date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
Etag:
- '"0x8D6E3BCCDFAFBBF"'
- '"0x8D8E00416CDFF62"'
Last-Modified:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:44 GMT
Server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
X-Ms-Request-Id:
- 3781395b-e01e-00b7-6fa5-15d5a7000000
- 41952a91-501e-0012-1bec-11e43d000000
X-Ms-Version:
- "2018-03-28"
status: 201 Created
Expand All @@ -41,14 +41,14 @@ interactions:
form: {}
headers:
Authorization:
- SharedKey golangrocksonazure:S5PgAFqyK8UBwh6TI3qWZlC6FosgMKjaekntS/skijA=
- SharedKey golangrocksonazure:4yu4lzswyubjg2VV1Ehf5Zl/E456Zp7/OBfiViJJxSI=
User-Agent:
- Go/go1.12.4 (amd64-windows) azure-storage-go/latest api-version/2018-03-28
- Go/go1.15.1 (amd64-windows) azure-storage-go/v51.3.0 api-version/2018-03-28
blob
x-ms-blob-type:
- AppendBlob
x-ms-date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
x-ms-version:
- "2018-03-28"
url: https://golangrocksonazure.blob.core.windows.net/cnt-33appendblobsuitetestputappe/blob/33appendblobsuitetestputappendblob
Expand All @@ -59,15 +59,15 @@ interactions:
Content-Length:
- "0"
Date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
Etag:
- '"0x8D6E3BCCDFD7B24"'
- '"0x8D8E00416D2DB57"'
Last-Modified:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:44 GMT
Server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
X-Ms-Request-Id:
- 3781397e-e01e-00b7-0ea5-15d5a7000000
- 41952aa7-501e-0012-2fec-11e43d000000
X-Ms-Request-Server-Encrypted:
- "true"
X-Ms-Version:
Expand All @@ -80,12 +80,12 @@ interactions:
form: {}
headers:
Authorization:
- SharedKey golangrocksonazure:AowIOO8KDWMTJGs99tmLN2efeY7Btyga8t0LFSsfATA=
- SharedKey golangrocksonazure:7SYRC+2ktl0SOYb60CWMwIHK6gEj4nJojxvnXtOnYhw=
User-Agent:
- Go/go1.12.4 (amd64-windows) azure-storage-go/latest api-version/2018-03-28
- Go/go1.15.1 (amd64-windows) azure-storage-go/v51.3.0 api-version/2018-03-28
blob
x-ms-date:
- Tue, 28 May 2019 22:35:37 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
x-ms-version:
- "2018-03-28"
url: https://golangrocksonazure.blob.core.windows.net/cnt-33appendblobsuitetestputappe/blob/33appendblobsuitetestputappendblob
Expand All @@ -100,29 +100,25 @@ interactions:
Content-Type:
- application/octet-stream
Date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
Etag:
- '"0x8D6E3BCCDFD7B24"'
- '"0x8D8E00416D2DB57"'
Last-Modified:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:44 GMT
Server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
X-Ms-Access-Tier:
- Cool
X-Ms-Access-Tier-Inferred:
- "true"
X-Ms-Blob-Committed-Block-Count:
- "0"
X-Ms-Blob-Type:
- AppendBlob
X-Ms-Creation-Time:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:44 GMT
X-Ms-Lease-State:
- available
X-Ms-Lease-Status:
- unlocked
X-Ms-Request-Id:
- 37813989-e01e-00b7-18a5-15d5a7000000
- 41952ab8-501e-0012-3eec-11e43d000000
X-Ms-Server-Encrypted:
- "true"
X-Ms-Version:
Expand All @@ -135,12 +131,12 @@ interactions:
form: {}
headers:
Authorization:
- SharedKey golangrocksonazure:XdOf6r50NJa2wUmQt1iWNJZa/PSVqe9M3TU3YlCJK5A=
- SharedKey golangrocksonazure:9la7KSNSu/8iy7qvnqZxqsBHs5jvam0fiHp6A8myI54=
User-Agent:
- Go/go1.12.4 (amd64-windows) azure-storage-go/latest api-version/2018-03-28
- Go/go1.15.1 (amd64-windows) azure-storage-go/v51.3.0 api-version/2018-03-28
blob
x-ms-date:
- Tue, 28 May 2019 22:35:37 GMT
- Fri, 05 Mar 2021 18:25:44 GMT
x-ms-version:
- "2018-03-28"
url: https://golangrocksonazure.blob.core.windows.net/cnt-33appendblobsuitetestputappe?restype=container
Expand All @@ -151,11 +147,11 @@ interactions:
Content-Length:
- "0"
Date:
- Tue, 28 May 2019 22:35:36 GMT
- Fri, 05 Mar 2021 18:25:43 GMT
Server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
X-Ms-Request-Id:
- 37813996-e01e-00b7-25a5-15d5a7000000
- 41952ae2-501e-0012-60ec-11e43d000000
X-Ms-Version:
- "2018-03-28"
status: 202 Accepted
Expand Down
Loading

0 comments on commit 4b53918

Please sign in to comment.