Skip to content

Commit 56c7173

Browse files
Update autorest version to Preview.45 (Azure#19834)
* updating autorest version * updating clients/models with updated metadata and ors * updating structs in container * updating changelog.md * Updating tests and recordings * updating sas example * updating service tests * updating azblob examples * Fixing test * fixing test
1 parent 07d8804 commit 56c7173

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1046
-954
lines changed

sdk/storage/azblob/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
### Bugs Fixed
1414
* Fixed encoding issues seen in FilterBlobs. Fixes [#17421](https://github.com/Azure/azure-sdk-for-go/issues/17421).
15+
* Fixing inconsistency seen with Metadata and ORS response. Fixes [#19688](https://github.com/Azure/azure-sdk-for-go/issues/19688).
1516

1617
### Other Changes
1718

sdk/storage/azblob/appendblob/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (ab *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders blob.HTTPHeade
290290

291291
// SetMetadata changes a blob's metadata.
292292
// https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata.
293-
func (ab *Client) SetMetadata(ctx context.Context, metadata map[string]string, o *blob.SetMetadataOptions) (blob.SetMetadataResponse, error) {
293+
func (ab *Client) SetMetadata(ctx context.Context, metadata map[string]*string, o *blob.SetMetadataOptions) (blob.SetMetadataResponse, error) {
294294
return ab.BlobClient().SetMetadata(ctx, metadata, o)
295295
}
296296

sdk/storage/azblob/appendblob/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func (s *AppendBlobRecordedTestsSuite) TestBlobCreateAppendMetadataEmpty() {
444444
abClient := getAppendBlobClient(abName, containerClient)
445445

446446
createAppendBlobOptions := appendblob.CreateOptions{
447-
Metadata: map[string]string{},
447+
Metadata: map[string]*string{},
448448
}
449449
_, err = abClient.Create(context.Background(), &createAppendBlobOptions)
450450
_require.Nil(err)
@@ -468,7 +468,7 @@ func (s *AppendBlobRecordedTestsSuite) TestBlobCreateAppendMetadataInvalid() {
468468
abClient := getAppendBlobClient(abName, containerClient)
469469

470470
createAppendBlobOptions := appendblob.CreateOptions{
471-
Metadata: map[string]string{"In valid!": "bar"},
471+
Metadata: map[string]*string{"In valid!": to.Ptr("bar")},
472472
}
473473
_, err = abClient.Create(context.Background(), &createAppendBlobOptions)
474474
_require.NotNil(err)
@@ -1610,7 +1610,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestSetBlobMetadataReturnsVID() {
16101610
bbName := testcommon.GenerateName(testName)
16111611
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, bbName, containerClient)
16121612

1613-
metadata := map[string]string{"test_key_1": "test_value_1", "test_key_2": "2019"}
1613+
metadata := map[string]*string{"test_key_1": to.Ptr("test_value_1"), "test_key_2": to.Ptr("2019")}
16141614
resp, err := bbClient.SetMetadata(context.Background(), metadata, nil)
16151615
_require.Nil(err)
16161616
_require.NotNil(resp.VersionID)

sdk/storage/azblob/appendblob/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type CreateOptions struct {
4949
// are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source
5050
// blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.
5151
// See Naming and Referencing Containers, Blobs, and Metadata for more information.
52-
Metadata map[string]string
52+
Metadata map[string]*string
5353
}
5454

5555
func (o *CreateOptions) format() (*generated.AppendBlobClientCreateOptions, *generated.BlobHTTPHeaders, *generated.LeaseAccessConditions, *generated.CpkInfo, *generated.CpkScopeInfo, *generated.ModifiedAccessConditions) {

sdk/storage/azblob/blob/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (b *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders HTTPHeaders, o
176176

177177
// SetMetadata changes a blob's metadata.
178178
// https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata.
179-
func (b *Client) SetMetadata(ctx context.Context, metadata map[string]string, o *SetMetadataOptions) (SetMetadataResponse, error) {
179+
func (b *Client) SetMetadata(ctx context.Context, metadata map[string]*string, o *SetMetadataOptions) (SetMetadataResponse, error) {
180180
basics := generated.BlobClientSetMetadataOptions{Metadata: metadata}
181181
leaseAccessConditions, cpkInfo, cpkScope, modifiedAccessConditions := o.format()
182182
resp, err := b.generated().SetMetadata(ctx, &basics, leaseAccessConditions, cpkInfo, cpkScope, modifiedAccessConditions)

sdk/storage/azblob/blob/client_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,15 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyMetadata() {
243243
anotherBlobName := "copy" + blobName
244244
copyBlobClient := testcommon.GetBlockBlobClient(anotherBlobName, containerClient)
245245

246-
var metadata = map[string]string{"Bla": "foo"}
247246
resp, err := copyBlobClient.StartCopyFromURL(context.Background(), bbClient.URL(), &blob.StartCopyFromURLOptions{
248-
Metadata: metadata,
247+
Metadata: testcommon.BasicMetadata,
249248
})
250249
_require.Nil(err)
251250
waitForCopy(_require, copyBlobClient, resp)
252251

253252
resp2, err := copyBlobClient.GetProperties(context.Background(), nil)
254253
_require.Nil(err)
255-
_require.EqualValues(resp2.Metadata, metadata)
254+
_require.EqualValues(resp2.Metadata, testcommon.BasicMetadata)
256255
}
257256

258257
func (s *BlobRecordedTestsSuite) TestBlobStartCopyMetadataNil() {
@@ -305,7 +304,7 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyMetadataEmpty() {
305304
_, err = copyBlobClient.Upload(context.Background(), streaming.NopCloser(bytes.NewReader([]byte("data"))), nil)
306305
_require.Nil(err)
307306

308-
metadata := make(map[string]string)
307+
metadata := make(map[string]*string)
309308
options := blob.StartCopyFromURLOptions{
310309
Metadata: metadata,
311310
}
@@ -335,8 +334,8 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyMetadataInvalidField() {
335334
anotherBlobName := "copy" + testcommon.GenerateBlobName(testName)
336335
copyBlobClient := testcommon.GetBlockBlobClient(anotherBlobName, containerClient)
337336

338-
metadata := make(map[string]string)
339-
metadata["I nvalid."] = "foo"
337+
metadata := make(map[string]*string)
338+
metadata["I nvalid."] = to.Ptr("foo")
340339
options := blob.StartCopyFromURLOptions{
341340
Metadata: metadata,
342341
}
@@ -924,8 +923,8 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopyDestIfMatchFalse() {
924923
},
925924
},
926925
}
927-
metadata := make(map[string]string)
928-
metadata["bla"] = "bla"
926+
metadata := make(map[string]*string)
927+
metadata["bla"] = to.Ptr("bla")
929928
_, err = destBlobClient.SetMetadata(context.Background(), metadata, nil)
930929
_require.Nil(err)
931930

@@ -1167,7 +1166,7 @@ func (s *BlobRecordedTestsSuite) TestBlobSnapshotMetadataInvalid() {
11671166
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
11681167

11691168
createBlobSnapshotOptions := blob.CreateSnapshotOptions{
1170-
Metadata: map[string]string{"Invalid Field!": "value"},
1169+
Metadata: map[string]*string{"Invalid Field!": to.Ptr("value")},
11711170
}
11721171
_, err = bbClient.CreateSnapshot(context.Background(), &createBlobSnapshotOptions)
11731172
_require.NotNil(err)
@@ -2729,7 +2728,7 @@ func (s *BlobRecordedTestsSuite) TestBlobSetMetadataNil() {
27292728
blockBlobName := testcommon.GenerateBlobName(testName)
27302729
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
27312730

2732-
_, err = bbClient.SetMetadata(context.Background(), map[string]string{"not": "nil"}, nil)
2731+
_, err = bbClient.SetMetadata(context.Background(), map[string]*string{"not": to.Ptr("nil")}, nil)
27332732
_require.Nil(err)
27342733

27352734
_, err = bbClient.SetMetadata(context.Background(), nil, nil)
@@ -2753,10 +2752,10 @@ func (s *BlobRecordedTestsSuite) TestBlobSetMetadataEmpty() {
27532752
blockBlobName := testcommon.GenerateBlobName(testName)
27542753
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
27552754

2756-
_, err = bbClient.SetMetadata(context.Background(), map[string]string{"not": "nil"}, nil)
2755+
_, err = bbClient.SetMetadata(context.Background(), map[string]*string{"not": to.Ptr("nil")}, nil)
27572756
_require.Nil(err)
27582757

2759-
_, err = bbClient.SetMetadata(context.Background(), map[string]string{}, nil)
2758+
_, err = bbClient.SetMetadata(context.Background(), map[string]*string{}, nil)
27602759
_require.Nil(err)
27612760

27622761
resp, err := bbClient.GetProperties(context.Background(), nil)
@@ -2777,7 +2776,7 @@ func (s *BlobRecordedTestsSuite) TestBlobSetMetadataInvalidField() {
27772776
blockBlobName := testcommon.GenerateBlobName(testName)
27782777
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
27792778

2780-
_, err = bbClient.SetMetadata(context.Background(), map[string]string{"Invalid field!": "value"}, nil)
2779+
_, err = bbClient.SetMetadata(context.Background(), map[string]*string{"Invalid field!": to.Ptr("value")}, nil)
27812780
_require.NotNil(err)
27822781
_require.Contains(err.Error(), testcommon.InvalidHeaderErrorSubstring)
27832782
//_require.Equal(strings.Contains(err.Error(), testcommon.InvalidHeaderErrorSubstring), true)

sdk/storage/azblob/blob/examples_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Example_blob_Client_SetMetadata() {
8686
_, err = blobClient.Upload(
8787
context.TODO(),
8888
streaming.NopCloser(strings.NewReader("Some text")),
89-
&blockblob.UploadOptions{Metadata: map[string]string{"author": "Jeffrey", "app": creatingApp}},
89+
&blockblob.UploadOptions{Metadata: map[string]*string{"author": to.Ptr("Jeffrey"), "app": to.Ptr(creatingApp)}},
9090
)
9191
handleError(err)
9292

@@ -103,11 +103,11 @@ func Example_blob_Client_SetMetadata() {
103103
}
104104

105105
for k, v := range get.Metadata {
106-
fmt.Print(k + "=" + v + "\n")
106+
fmt.Print(k + "=" + *v + "\n")
107107
}
108108

109109
// Update the blob's metadata and write it back to the blob
110-
get.Metadata["editor"] = "Grant"
110+
get.Metadata["editor"] = to.Ptr("Grant")
111111
_, err = blobClient.SetMetadata(context.TODO(), get.Metadata, nil)
112112
handleError(err)
113113
}

sdk/storage/azblob/blob/models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (o *SetMetadataOptions) format() (*generated.LeaseAccessConditions, *CpkInf
305305

306306
// CreateSnapshotOptions contains the optional parameters for the Client.CreateSnapshot method.
307307
type CreateSnapshotOptions struct {
308-
Metadata map[string]string
308+
Metadata map[string]*string
309309
AccessConditions *AccessConditions
310310
CpkInfo *CpkInfo
311311
CpkScopeInfo *CpkScopeInfo
@@ -341,7 +341,7 @@ type StartCopyFromURLOptions struct {
341341
// are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source
342342
// blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.
343343
// See Naming and Referencing Containers, Blobs, and Metadata for more information.
344-
Metadata map[string]string
344+
Metadata map[string]*string
345345
// Optional: Indicates the priority with which to rehydrate an archived blob.
346346
RehydratePriority *RehydratePriority
347347
// Overrides the sealed state of the destination blob. Service version 2019-12-12 and newer.
@@ -531,7 +531,7 @@ type CopyFromURLOptions struct {
531531
// is not copied from the source blob or file. Note that beginning with
532532
// version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers,
533533
// Blobs, and Metadata for more information.
534-
Metadata map[string]string
534+
Metadata map[string]*string
535535
// Specify the md5 calculated for the range of bytes that must be read from the copy source.
536536
SourceContentMD5 []byte
537537
// Optional. Indicates the tier to be set on the blob.

sdk/storage/azblob/blob/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ type ObjectReplicationPolicy struct {
2525
}
2626

2727
// deserializeORSPolicies is utility function to deserialize ORS Policies
28-
func deserializeORSPolicies(policies map[string]string) (objectReplicationPolicies []ObjectReplicationPolicy) {
28+
func deserializeORSPolicies(policies map[string]*string) (objectReplicationPolicies []ObjectReplicationPolicy) {
2929
if policies == nil {
3030
return nil
3131
}
3232
// For source blobs (blobs that have policy ids and rule ids applied to them),
3333
// the header will be formatted as "x-ms-or-<policy_id>_<rule_id>: {Complete, Failed}".
3434
// The value of this header is the status of the replication.
35-
orPolicyStatusHeader := make(map[string]string)
35+
orPolicyStatusHeader := make(map[string]*string)
3636
for key, value := range policies {
3737
if strings.Contains(key, "or-") && key != "x-ms-or-policy-id" {
3838
orPolicyStatusHeader[key] = value
@@ -44,7 +44,7 @@ func deserializeORSPolicies(policies map[string]string) (objectReplicationPolici
4444
policyAndRuleIDs := strings.Split(strings.Split(key, "or-")[1], "_")
4545
policyId, ruleId := policyAndRuleIDs[0], policyAndRuleIDs[1]
4646

47-
parsedResult[policyId] = append(parsedResult[policyId], ObjectReplicationRules{RuleId: ruleId, Status: value})
47+
parsedResult[policyId] = append(parsedResult[policyId], ObjectReplicationRules{RuleId: ruleId, Status: *value})
4848
}
4949

5050
for policyId, rules := range parsedResult {

sdk/storage/azblob/blob/utils_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
package blob
88

99
import (
10+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1011
"testing"
1112

1213
"github.com/stretchr/testify/require"
1314
)
1415

1516
func TestDeserializeORSPolicies(t *testing.T) {
1617

17-
headers := map[string]string{
18-
"x-ms-or-111_111": "Completed",
19-
"x-ms-or-111_222": "Failed",
20-
"x-ms-or-222_111": "Completed",
21-
"x-ms-or-222_222": "Failed",
22-
"x-ms-or-policy-id": "333", // to be ignored
23-
"x-ms-not-related": "garbage", // to be ignored
18+
headers := map[string]*string{
19+
"x-ms-or-111_111": to.Ptr("Completed"),
20+
"x-ms-or-111_222": to.Ptr("Failed"),
21+
"x-ms-or-222_111": to.Ptr("Completed"),
22+
"x-ms-or-222_222": to.Ptr("Failed"),
23+
"x-ms-or-policy-id": to.Ptr("333"), // to be ignored
24+
"x-ms-not-related": to.Ptr("garbage"), // to be ignored
2425
}
2526

2627
result := deserializeORSPolicies(headers)

0 commit comments

Comments
 (0)