Skip to content

Commit

Permalink
resource-type added (#22425)
Browse files Browse the repository at this point in the history
* Exposing x-ms-resource-type response header in GetProperties API for file and directory
  • Loading branch information
ashruti-msft authored Feb 26, 2024
1 parent bac2559 commit b78f783
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
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.

* Re-enabled `SharedKeyCredential` authentication mode for non TLS protected endpoints.

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

0 comments on commit b78f783

Please sign in to comment.