Skip to content

Exposing x-ms-resource-type response header #22425

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

Merged
merged 1 commit into from
Feb 26, 2024
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/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Exposing x-ms-resource-type response header in GetProperties API for file and directory.

### Other Changes

Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azdatalake/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2765,7 +2765,7 @@ func (s *RecordedTestSuite) TestDirGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxDir) // validate that the respFromCtx is actually populated
_require.Equal("directory", respFromCtxDir.Header.Get("x-ms-resource-type"))
_require.Equal("directory", *resp2.ResourceType)

// This tests filesystem.NewClient
dirClient = fsClient.NewDirectoryClient(dirName)
Expand All @@ -2775,7 +2775,7 @@ func (s *RecordedTestSuite) TestDirGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxFs) // validate that the respFromCtx is actually populated
_require.Equal("directory", respFromCtxFs.Header.Get("x-ms-resource-type"))
_require.Equal("directory", *resp2.ResourceType)

// This tests service.NewClient
serviceClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDatalake, nil)
Expand All @@ -2788,7 +2788,7 @@ func (s *RecordedTestSuite) TestDirGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxService) // validate that the respFromCtx is actually populated
_require.Equal("directory", respFromCtxService.Header.Get("x-ms-resource-type"))
_require.Equal("directory", *resp2.ResourceType)
}

func (s *RecordedTestSuite) TestDirGetPropertiesWithCPK() {
Expand Down
16 changes: 9 additions & 7 deletions sdk/storage/azdatalake/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
"crypto/md5"
"encoding/binary"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/service"
"hash/crc64"
"io"
"math/rand"
Expand All @@ -25,6 +22,10 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/service"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
Expand Down Expand Up @@ -3180,6 +3181,7 @@ func (s *RecordedTestSuite) TestTinyFileUploadFile() {
gResp2, err := fClient.GetProperties(context.Background(), nil)
_require.NoError(err)
_require.Equal(*gResp2.ContentLength, fileSize)
_require.Equal(*gResp2.ResourceType, "file")

dResp, err := fClient.DownloadStream(context.Background(), nil)
_require.NoError(err)
Expand Down Expand Up @@ -4867,7 +4869,7 @@ func (s *RecordedTestSuite) TestFileGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxFile) // validate that the respFromCtx is actually populated
_require.Equal("file", respFromCtxFile.Header.Get("x-ms-resource-type"))
_require.Equal("file", *resp2.ResourceType)

// This tests filesystem.NewClient
fClient = fsClient.NewFileClient(dirName + "/" + fileName)
Expand All @@ -4877,7 +4879,7 @@ func (s *RecordedTestSuite) TestFileGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxFs) // validate that the respFromCtx is actually populated
_require.Equal("file", respFromCtxFs.Header.Get("x-ms-resource-type"))
_require.Equal("file", *resp2.ResourceType)

// This tests service.NewClient
serviceClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDatalake, nil)
Expand All @@ -4892,7 +4894,7 @@ func (s *RecordedTestSuite) TestFileGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxService) // validate that the respFromCtx is actually populated
_require.Equal("file", respFromCtxService.Header.Get("x-ms-resource-type"))
_require.Equal("file", *resp2.ResourceType)

// This tests directory.NewClient
var respFromCtxDir *http.Response
Expand All @@ -4905,7 +4907,7 @@ func (s *RecordedTestSuite) TestFileGetPropertiesResponseCapture() {
_require.NoError(err)
_require.NotNil(resp2)
_require.NotNil(respFromCtxDir) // validate that the respFromCtx is actually populated
_require.Equal("file", respFromCtxDir.Header.Get("x-ms-resource-type"))
_require.Equal("file", *resp2.ResourceType)
}

func (s *RecordedTestSuite) TestFileGetPropertiesWithCPK() {
Expand Down
11 changes: 9 additions & 2 deletions sdk/storage/azdatalake/internal/path/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
package path

import (
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/generated"
"net/http"
"time"
)

// SetAccessControlResponse contains the response fields for the SetAccessControl operation.
Expand Down Expand Up @@ -227,6 +228,9 @@ type GetPropertiesResponse struct {

// Permissions contains the information returned from the x-ms-permissions header response.
Permissions *string

// ResourceType contains the information returned from the x-ms-resource-type header response.
ResourceType *string
}

func FormatGetPropertiesResponse(r *blob.GetPropertiesResponse, rawResponse *http.Response) GetPropertiesResponse {
Expand Down Expand Up @@ -286,6 +290,9 @@ func FormatGetPropertiesResponse(r *blob.GetPropertiesResponse, rawResponse *htt
if val := rawResponse.Header.Get("x-ms-permissions"); val != "" {
newResp.Permissions = &val
}
if val := rawResponse.Header.Get("x-ms-resource-type"); val != "" {
newResp.ResourceType = &val
}
return newResp
}

Expand Down