Skip to content

Commit

Permalink
Fix Filter Blob API encoding issue (#23800)
Browse files Browse the repository at this point in the history
* Prep for stg 95 GA release

* Update CHANGELOG.md

format for changelog

* Fix FilterBlob API

* Fix FilterBlob API

* Add url encoding to azdatalake

* change regex globally - azblob

* add blob tag back

* Add url encoding to azdatalake

* add new test for blob

* remove all changes other than storage

* remove other than storage changes

* global regex to azdatalake generated blob

* remove container client from transform
  • Loading branch information
tanyasethi-msft authored Dec 13, 2024
1 parent 5e623a4 commit 00595ab
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 68 deletions.
1 change: 1 addition & 0 deletions sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Fix FilterBlob API if Query contains a space character. Fixes [#23546](https://github.com/Azure/azure-sdk-for-go/issues/23546)

### Other Changes

Expand Down
53 changes: 51 additions & 2 deletions sdk/storage/azblob/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ func (s *ContainerUnrecordedTestsSuite) TestSASContainerClient() {
_require.NoError(err)
}

func (s *ContainerUnrecordedTestsSuite) TestFilterBlobsByTags() {
func (s *ContainerUnrecordedTestsSuite) TestFilterBlobsByBasicTags() {
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
Expand Down Expand Up @@ -2483,11 +2483,60 @@ func (s *ContainerUnrecordedTestsSuite) TestFilterBlobsByTags() {
opts := container.FilterBlobsOptions{MaxResults: to.Ptr(int32(10)), Marker: to.Ptr("")}
lResp, err := containerSasClient.FilterBlobs(context.Background(), where, &opts)
_require.NoError(err)
_require.Len(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet, 1)
_require.Equal(*lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0].Key, "azure")
_require.Equal(*lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0].Value, "blob")
}

func (s *ContainerUnrecordedTestsSuite) TestFilterBlobsBySpecialCharTags() {
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

containerClient := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName), svcClient)
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

// Adding SAS and options
permissions := sas.ContainerPermissions{
Read: true,
Add: true,
Write: true,
Create: true,
Delete: true,
Tag: true,
FilterByTags: true,
}
expiry := time.Now().Add(time.Hour)

// ContainerSASURL is created with GetSASURL
sasUrl, err := containerClient.GetSASURL(permissions, expiry, nil)
_require.NoError(err)

// Create container client with sasUrl
containerSasClient, err := container.NewClientWithNoCredential(sasUrl, nil)
_require.NoError(err)

abClient := containerSasClient.NewAppendBlobClient(testcommon.GenerateBlobName(testName))

createAppendBlobOptions := appendblob.CreateOptions{
Tags: testcommon.SpecialCharBlobTagsMap,
}
createResp, err := abClient.Create(context.Background(), &createAppendBlobOptions)
_require.NoError(err)
_require.NotNil(createResp.VersionID)
time.Sleep(10 * time.Second)

// Use container client to filter blobs by tag

where := "\"go\"='written in golang'"
opts := container.FilterBlobsOptions{MaxResults: to.Ptr(int32(10))}
lResp, err := containerSasClient.FilterBlobs(context.Background(), where, &opts)
_require.NoError(err)
_require.Len(lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet, 1)
_require.Equal(*lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0].Key, "go")
_require.Equal(*lResp.FilterBlobSegment.Blobs[0].Tags.BlobTagSet[0].Value, "written in golang")
}

func (s *ContainerUnrecordedTestsSuite) TestFilterBlobsByTagsNegative() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down
12 changes: 7 additions & 5 deletions sdk/storage/azblob/internal/generated/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,13 @@ directive:
``` yaml
directive:
- from: zz_service_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`)
- from:
- zz_service_client.go
- zz_container_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/g, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`);
```
### Change `where` parameter in blob filtering to be required
Expand Down
36 changes: 18 additions & 18 deletions sdk/storage/azblob/internal/generated/zz_container_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions sdk/storage/azblob/internal/generated/zz_service_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/storage/azblob/internal/testcommon/clients_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var SpecialCharBlobTagsMap = map[string]string{
"Microsoft Azure": "Azure Storage",
"Storage+SDK": "SDK/GO",
"GO ": ".Net",
"go": "written in golang",
}

func SetClientOptions(t *testing.T, opts *azcore.ClientOptions) {
Expand Down
1 change: 0 additions & 1 deletion sdk/storage/azblob/pageblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4225,7 +4225,6 @@ func (s *PageBlobUnrecordedTestsSuite) TestPageBlobSetBlobTagForSnapshot() {

blobGetTagsResponse, err := pbClient.GetTags(context.Background(), nil)
_require.NoError(err)
// _require.Equal(blobGetTagsResponse.RawResponse.StatusCode, 200)
blobTagsSet := blobGetTagsResponse.BlobTagSet
_require.NotNil(blobTagsSet)
_require.Len(blobTagsSet, len(testcommon.SpecialCharBlobTagsMap))
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Fix FilterBlob API if Query contains a space character. Fixes [#23546](https://github.com/Azure/azure-sdk-for-go/issues/23546)

### Other Changes

Expand Down
10 changes: 5 additions & 5 deletions sdk/storage/azdatalake/internal/generated/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ directive:
``` yaml
directive:
- from: zz_service_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`)
- from: zz_service_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`);
```
### Change `Duration` parameter in leases to be required
Expand Down
12 changes: 7 additions & 5 deletions sdk/storage/azdatalake/internal/generated_blob/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ directive:
``` yaml
directive:
- from: zz_service_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`)
- from:
- zz_service_client.go
- zz_container_client.go
where: $
transform: >-
return $.
replace(/req.Raw\(\).URL.RawQuery \= reqQP.Encode\(\)/g, `req.Raw().URL.RawQuery = strings.Replace(reqQP.Encode(), "+", "%20", -1)`);
```
### Change `where` parameter in blob filtering to be required
Expand Down
Loading

0 comments on commit 00595ab

Please sign in to comment.