Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Breaking Changes
* Updated to latest `azcore`. Public surface area is unchanged.
* [#16978](https://github.com/Azure/azure-sdk-for-go/pull/16978): The `DownloadResponse.Body` parameter is now `*RetryReaderOptions`.

### Bugs Fixed

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/highlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (b BlobClient) DownloadBlobToWriterAt(ctx context.Context, offset int64, co
if err != nil {
return err
}
body := dr.Body(o.RetryReaderOptionsPerBlock)
body := dr.Body(&o.RetryReaderOptionsPerBlock)
if o.Progress != nil {
rangeProgress := int64(0)
body = streaming.NewResponseProgress(
Expand Down
12 changes: 8 additions & 4 deletions sdk/storage/azblob/zc_response_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ type DownloadResponse struct {
// while reading, it will make additional requests to reestablish a connection and
// continue reading. Specifying a RetryReaderOption's with MaxRetryRequests set to 0
// (the default), returns the original response body and no retries will be performed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment include something about passing in 'nil' to accept the default options?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should, added!

func (r *DownloadResponse) Body(o RetryReaderOptions) io.ReadCloser {
if o.MaxRetryRequests == 0 { // No additional retries
// Pass in nil for options to accept the default options.
func (r *DownloadResponse) Body(options *RetryReaderOptions) io.ReadCloser {
if options == nil {
options = &RetryReaderOptions{}
}
if options.MaxRetryRequests == 0 { // No additional retries
return r.RawResponse.Body
}
return NewRetryReader(r.ctx, r.RawResponse, r.getInfo, o,
return NewRetryReader(r.ctx, r.RawResponse, r.getInfo, *options,
func(ctx context.Context, getInfo HTTPGetterInfo) (*http.Response, error) {
accessConditions := &BlobAccessConditions{
ModifiedAccessConditions: &ModifiedAccessConditions{IfMatch: &getInfo.ETag},
Expand All @@ -63,7 +67,7 @@ func (r *DownloadResponse) Body(o RetryReaderOptions) io.ReadCloser {
Offset: &getInfo.Offset,
Count: &getInfo.Count,
BlobAccessConditions: accessConditions,
CpkInfo: o.CpkInfo,
CpkInfo: options.CpkInfo,
//CpkScopeInfo: o.CpkScopeInfo,
}
resp, err := r.b.Download(ctx, &options)
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azblob/zt_append_blob_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (s *azblobUnrecordedTestSuite) TestAppendBlockFromURL() {
destData, err := ioutil.ReadAll(downloadResp.RawResponse.Body)
_assert.Nil(err)
_assert.Equal(destData, sourceData)
_ = downloadResp.Body(RetryReaderOptions{}).Close()
_ = downloadResp.Body(nil).Close()
}

//nolint
Expand Down Expand Up @@ -294,7 +294,7 @@ func (s *azblobUnrecordedTestSuite) TestAppendBlockFromURLWithMD5() {
// Check data integrity through downloading.
downloadResp, err := destBlob.BlobClient.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, sourceData)

Expand Down
8 changes: 4 additions & 4 deletions sdk/storage/azblob/zt_blob_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *azblobTestSuite) TestBlobStartCopyDestEmpty() {
_assert.Nil(err)
_assert.Equal(*resp.ContentLength, int64(len(blockBlobDefaultData)))
_assert.Equal(string(data), blockBlobDefaultData)
_ = resp.Body(RetryReaderOptions{}).Close()
_ = resp.Body(nil).Close()
}

func (s *azblobTestSuite) TestBlobStartCopyMetadata() {
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *azblobUnrecordedTestSuite) TestBlobStartCopyUsingSASSrc() {
_assert.Nil(err)
_assert.Equal(*resp2.ContentLength, int64(len(blockBlobDefaultData)))
_assert.Equal(string(data), blockBlobDefaultData)
_ = resp2.Body(RetryReaderOptions{}).Close()
_ = resp2.Body(nil).Close()
}

//nolint
Expand Down Expand Up @@ -3473,8 +3473,8 @@ func (s *azblobUnrecordedTestSuite) TestDownloadBlockBlobUnexpectedEOF() {
}

//nolint
func InjectErrorInRetryReaderOptions(err error) RetryReaderOptions {
return RetryReaderOptions{
func InjectErrorInRetryReaderOptions(err error) *RetryReaderOptions {
return &RetryReaderOptions{
MaxRetryRequests: 1,
doInjectError: true,
doInjectErrorRound: 0,
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azblob/zt_blob_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *azblobUnrecordedTestSuite) TestStageBlockWithTags() {

contentResp, err := bbClient.Download(ctx, nil)
_assert.Nil(err)
contentData, err := ioutil.ReadAll(contentResp.Body(RetryReaderOptions{}))
contentData, err := ioutil.ReadAll(contentResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(contentData, []uint8(strings.Join(data, "")))

Expand Down Expand Up @@ -328,7 +328,7 @@ func (s *azblobUnrecordedTestSuite) TestStageBlockFromURLWithTags() {

downloadResp, err := destBlob.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, sourceData)
}
Expand Down Expand Up @@ -401,7 +401,7 @@ func (s *azblobUnrecordedTestSuite) TestCopyBlockBlobFromURLWithTags() {

downloadResp, err := destBlob.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, sourceData)
_assert.Equal(*downloadResp.TagCount, int64(1))
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azblob/zt_blob_versioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *azblobTestSuite) TestCreateAndDownloadBlobSpecialCharactersWithVID() {

dResp, err := blobURL.WithVersionID(*resp.VersionID).Download(ctx, nil)
_assert.Nil(err)
d1, err := ioutil.ReadAll(dResp.Body(RetryReaderOptions{}))
d1, err := ioutil.ReadAll(dResp.Body(nil))
_assert.Nil(err)
_assert.NotEqual(*dResp.Version, "")
_assert.EqualValues(string(d1), string(data[i]))
Expand Down Expand Up @@ -398,7 +398,7 @@ func (s *azblobTestSuite) TestCreateAndDownloadBlobSpecialCharactersWithVID() {
//
// downloadResp, err := destBlob.BlobURL.Download(ctx, 0, CountToEnd, BlobAccessConditions{}, false, ClientProvidedKeyOptions{})
// _assert.Nil(err)
// destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
// destData, err := ioutil.ReadAll(downloadResp.Body(nil))
// _assert.Nil(err)
// _assert(destData, chk.DeepEquals, sourceData)
// _assert(downloadResp.Response().Header.Get("x-ms-version-id"), chk.NotNil)
Expand Down Expand Up @@ -502,7 +502,7 @@ func (s *azblobTestSuite) TestPutBlockListReturnsVID() {

contentResp, err := bbClient.Download(ctx, nil)
_assert.Nil(err)
contentData, err := ioutil.ReadAll(contentResp.Body(RetryReaderOptions{}))
contentData, err := ioutil.ReadAll(contentResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(contentData, []uint8(strings.Join(data, "")))
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azblob/zt_block_blob_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *azblobUnrecordedTestSuite) TestStageBlockFromURL() {
// Check data integrity through downloading.
downloadResp, err := destBlob.BlobClient.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, content)
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *azblobUnrecordedTestSuite) TestCopyBlockBlobFromURL() {
// Check data integrity through downloading.
downloadResp, err := destBlob.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, content)

Expand Down Expand Up @@ -1306,7 +1306,7 @@ func (s *azblobUnrecordedTestSuite) TestSetTierOnStageBlockFromURL() {
// Check data integrity through downloading.
downloadResp, err := destBlob.BlobClient.Download(ctx, nil)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, content)

Expand Down
30 changes: 15 additions & 15 deletions sdk/storage/azblob/zt_client_provided_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *azblobTestSuite) TestPutBlockAndPutBlockListWithCPK() {
getResp, err := bbClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)
b := bytes.Buffer{}
reader := getResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue})
reader := getResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue})
_, _ = b.ReadFrom(reader)
_ = reader.Close()
_assert.Equal(b.String(), "AAA BBB CCC ")
Expand Down Expand Up @@ -150,7 +150,7 @@ func (s *azblobTestSuite) TestPutBlockAndPutBlockListWithCPKByScope() {
getResp, err := bbClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)
b := bytes.Buffer{}
reader := getResp.Body(RetryReaderOptions{})
reader := getResp.Body(nil)
_, err = b.ReadFrom(reader)
_assert.Nil(err)
_ = reader.Close() // The client must close the response body when finished with it
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *azblobUnrecordedTestSuite) TestPutBlockFromURLAndCommitWithCPK() {
}
downloadResp, err := destBlob.BlobClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, content)
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)
Expand Down Expand Up @@ -387,7 +387,7 @@ func (s *azblobUnrecordedTestSuite) TestPutBlockFromURLAndCommitWithCPKWithScope
}
downloadResp, err := destBlob.BlobClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, content)
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)
Expand Down Expand Up @@ -433,7 +433,7 @@ func (s *azblobUnrecordedTestSuite) TestUploadBlobWithMD5WithCPK() {
})
_assert.Nil(err)
_assert.EqualValues(downloadResp.ContentMD5, md5Val[:])
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
_assert.EqualValues(downloadResp.EncryptionKeySHA256, testCPKByValue.EncryptionKeySHA256)
Expand Down Expand Up @@ -471,7 +471,7 @@ func (s *azblobTestSuite) TestUploadBlobWithMD5WithCPKScope() {
downloadResp, err := bbClient.BlobClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)
_assert.EqualValues(downloadResp.ContentMD5, md5Val[:])
destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)
Expand Down Expand Up @@ -530,7 +530,7 @@ func (s *azblobTestSuite) TestAppendBlockWithCPK() {
downloadResp, err := abClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)

data, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
data, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(string(data), "AAA BBB CCC ")
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)
Expand Down Expand Up @@ -585,7 +585,7 @@ func (s *azblobTestSuite) TestAppendBlockWithCPKScope() {
downloadResp, err := abClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)

data, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
data, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(string(data), "AAA BBB CCC ")
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)
Expand Down Expand Up @@ -696,7 +696,7 @@ func (s *azblobUnrecordedTestSuite) TestAppendBlockFromURLWithCPK() {
_assert.Equal(*downloadResp.IsServerEncrypted, true)
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
}
Expand Down Expand Up @@ -793,7 +793,7 @@ func (s *azblobUnrecordedTestSuite) TestAppendBlockFromURLWithCPKScope() {
_assert.Equal(*downloadResp.IsServerEncrypted, true)
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
}
Expand Down Expand Up @@ -849,7 +849,7 @@ func (s *azblobUnrecordedTestSuite) TestPageBlockWithCPK() {
downloadResp, err := pbClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)
Expand Down Expand Up @@ -897,7 +897,7 @@ func (s *azblobUnrecordedTestSuite) TestPageBlockWithCPKScope() {
downloadResp, err := pbClient.Download(ctx, &downloadBlobOptions)
_assert.Nil(err)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{}))
destData, err := ioutil.ReadAll(downloadResp.Body(nil))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)
Expand Down Expand Up @@ -983,7 +983,7 @@ func (s *azblobUnrecordedTestSuite) TestPageBlockFromURLWithCPK() {
_assert.Nil(err)
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func (s *azblobUnrecordedTestSuite) TestPageBlockFromURLWithCPKScope() {
_assert.Nil(err)
_assert.EqualValues(*downloadResp.EncryptionScope, *testCPKByScope.EncryptionScope)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ func (s *azblobUnrecordedTestSuite) TestUploadPagesFromURLWithMD5WithCPK() {
_assert.Nil(err)
_assert.EqualValues(*downloadResp.EncryptionKeySHA256, *testCPKByValue.EncryptionKeySHA256)

destData, err := ioutil.ReadAll(downloadResp.Body(RetryReaderOptions{CpkInfo: &testCPKByValue}))
destData, err := ioutil.ReadAll(downloadResp.Body(&RetryReaderOptions{CpkInfo: &testCPKByValue}))
_assert.Nil(err)
_assert.EqualValues(destData, srcData)

Expand Down
18 changes: 9 additions & 9 deletions sdk/storage/azblob/zt_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Example() {

// Open a buffer, reader, and then download!
downloadedData := &bytes.Buffer{}
reader := get.Body(RetryReaderOptions{}) // RetryReaderOptions has a lot of in-depth tuning abilities, but for the sake of simplicity, we'll omit those here.
reader := get.Body(nil) // RetryReaderOptions has a lot of in-depth tuning abilities, but for the sake of simplicity, we'll omit those here.
_, err = downloadedData.ReadFrom(reader)
if err != nil {
return
Expand Down Expand Up @@ -438,7 +438,7 @@ func ExampleBlobAccessConditions() {
fmt.Print("Failure: " + stgErr.Error() + "\n")
}
} else {
err := response.Body(RetryReaderOptions{}).Close()
err := response.Body(nil).Close()
if err != nil {
return
} // The client must close the response body when finished with it
Expand Down Expand Up @@ -732,7 +732,7 @@ func ExampleBlockBlobClient() {
log.Fatal(err)
}
blobData := &bytes.Buffer{}
reader := get.Body(RetryReaderOptions{})
reader := get.Body(nil)
_, err = blobData.ReadFrom(reader)
if err != nil {
return
Expand Down Expand Up @@ -781,7 +781,7 @@ func ExampleAppendBlobClient() {
log.Fatal(err)
}
b := bytes.Buffer{}
reader := get.Body(RetryReaderOptions{})
reader := get.Body(nil)
_, err = b.ReadFrom(reader)
if err != nil {
return
Expand Down Expand Up @@ -856,7 +856,7 @@ func ExamplePageBlobClient() {
log.Fatal(err)
}
blobData := &bytes.Buffer{}
reader := get.Body(RetryReaderOptions{})
reader := get.Body(nil)
_, err = blobData.ReadFrom(reader)
if err != nil {
return
Expand Down Expand Up @@ -914,7 +914,7 @@ func Example_blobSnapshots() {
log.Fatal(err)
}
b := bytes.Buffer{}
reader := get.Body(RetryReaderOptions{})
reader := get.Body(nil)
_, err = b.ReadFrom(reader)
if err != nil {
return
Expand All @@ -932,7 +932,7 @@ func Example_blobSnapshots() {
log.Fatal(err)
}
b.Reset()
reader = get.Body(RetryReaderOptions{})
reader = get.Body(nil)
_, err = b.ReadFrom(reader)
if err != nil {
return
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func Example_progressUploadDownload() {
}

// Wrap the response body in a ResponseBodyProgress and pass a callback function for progress reporting.
responseBody := streaming.NewResponseProgress(get.Body(RetryReaderOptions{}),
responseBody := streaming.NewResponseProgress(get.Body(nil),
func(bytesTransferred int64) {
fmt.Printf("Read %d of %d bytes.", bytesTransferred, *get.ContentLength)
})
Expand Down Expand Up @@ -1173,7 +1173,7 @@ func ExampleBlobClient_Download() {
if err != nil {
log.Fatal(err)
}
rs := dr.Body(RetryReaderOptions{})
rs := dr.Body(nil)

// NewResponseBodyProgress wraps the GetRetryStream with progress reporting; it returns an io.ReadCloser.
stream := streaming.NewResponseProgress(rs,
Expand Down
Loading