Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
datalake cpk
  • Loading branch information
tanyasethi-msft committed Dec 19, 2023
commit f0a41d42c1a1a6daf20f59eb42deafb794fa1560
2 changes: 2 additions & 0 deletions sdk/storage/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 1.0.1 (Unreleased)

### Features Added
* Encryption Scope For SAS
* CPK for Datalake

### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azdatalake/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azdatalake",
"Tag": "go/storage/azdatalake_7c0fb050cb"
"Tag": "go/storage/azdatalake_d78e1df2e9"
}
4 changes: 2 additions & 2 deletions sdk/storage/azdatalake/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (d *Client) Rename(ctx context.Context, destinationPath string, options *Re
newPathURL = strings.Split(newPathURL, "?")[0] + "?" + newDestQuery
}
newBlobURL, _ := shared.GetURLs(newPathURL)
lac, mac, smac, createOpts := path.FormatRenameOptions(options, newSrcPath)
lac, mac, smac, createOpts, cpkOpts := path.FormatRenameOptions(options, newSrcPath)

if d.identityCredential() != nil {
newBlobClient, err = blockblob.NewClient(newBlobURL, *d.identityCredential(), nil)
Expand All @@ -310,7 +310,7 @@ func (d *Client) Rename(ctx context.Context, destinationPath string, options *Re
return RenameResponse{}, exported.ConvertToDFSError(err)
}
newDirClient := (*Client)(base.NewPathClient(newPathURL, newBlobURL, newBlobClient, d.generatedDirClientWithDFS().InternalClient().WithClientName(shared.DirectoryClient), d.sharedKey(), d.identityCredential(), d.getClientOptions()))
resp, err := newDirClient.generatedDirClientWithDFS().Create(ctx, createOpts, nil, lac, mac, smac, nil)
resp, err := newDirClient.generatedDirClientWithDFS().Create(ctx, createOpts, nil, lac, mac, smac, cpkOpts)
//return RenameResponse{
// Response: resp,
// NewDirectoryClient: newDirClient,
Expand Down
115 changes: 115 additions & 0 deletions sdk/storage/azdatalake/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ func (s *RecordedTestSuite) TestCreateDirAndDelete() {
_require.NotNil(resp)
}

func (s *RecordedTestSuite) TestCreateDirUsingCPK() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

dirName := testcommon.GenerateDirName(testName)
dirClient, err := testcommon.GetDirClient(filesystemName, dirName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

dirOpts := &directory.CreateOptions{CPKInfo: &testcommon.TestCPKByValue}
resp, err := dirClient.Create(context.Background(), dirOpts)
_require.NoError(err)
_require.NotNil(resp)

_require.Equal(true, *(resp.IsServerEncrypted))
_require.Equal(testcommon.TestCPKByValue.EncryptionKeySHA256, resp.EncryptionKeySHA256)
}

func (s *RecordedTestSuite) TestGetAndCreateFileClient() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down Expand Up @@ -1912,6 +1937,35 @@ func (s *RecordedTestSuite) TestDirSetMetadataWithAccessConditions() {
_require.NoError(err)
}

func (s *RecordedTestSuite) TestDirSetMetadataWithCPK() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

dirName := testcommon.GenerateDirName(testName)
dirClient, err := testcommon.GetDirClient(filesystemName, dirName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

defer testcommon.DeleteDir(context.Background(), _require, dirClient)

resp, err := dirClient.Create(context.Background(), &directory.CreateOptions{CPKInfo: &testcommon.TestCPKByValue})
_require.NoError(err)
_require.NotNil(resp)

opts := &directory.SetMetadataOptions{
CPKInfo: &testcommon.TestCPKByValue,
}
_, err = dirClient.SetMetadata(context.Background(), testcommon.BasicMetadata, opts)
_require.NoError(err)
}

func validatePropertiesSet(_require *require.Assertions, dirClient *directory.Client, disposition string) {
resp, err := dirClient.GetProperties(context.Background(), nil)
_require.NoError(err)
Expand Down Expand Up @@ -2243,6 +2297,38 @@ func (s *RecordedTestSuite) TestDirRenameNoOptions() {
//_require.Contains(resp1.NewDirectoryClient.DFSURL(), "newName")
}

func (s *RecordedTestSuite) TestDirRenameRequestWithCPK() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

dirName := testcommon.GenerateDirName(testName)
dirClient, err := testcommon.GetDirClient(filesystemName, dirName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

createOpts := &directory.CreateOptions{
CPKInfo: &testcommon.TestCPKByValue,
}

resp, err := dirClient.Create(context.Background(), createOpts)
_require.NoError(err)
_require.NotNil(resp)

renameFileOpts := &directory.RenameOptions{
CPKInfo: &testcommon.TestCPKByValue,
}

_, err = dirClient.Rename(context.Background(), "newName", renameFileOpts)
_require.NoError(err)
}

func (s *RecordedTestSuite) TestRenameDirWithNilAccessConditions() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down Expand Up @@ -2548,6 +2634,35 @@ func (s *RecordedTestSuite) TestDirGetPropertiesResponseCapture() {
_require.Equal("directory", respFromCtxService.Header.Get("x-ms-resource-type"))
}

func (s *RecordedTestSuite) TestDirGetPropertiesWithCPK() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

dirName := testcommon.GenerateDirName(testName)
dirClient, err := testcommon.GetDirClient(filesystemName, dirName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

dirOpts := &directory.CreateOptions{CPKInfo: &testcommon.TestCPKByValue}
resp, err := dirClient.Create(context.Background(), dirOpts)
_require.NoError(err)
_require.NotNil(resp)

getPropertiesOpts := &directory.GetPropertiesOptions{CPKInfo: &testcommon.TestCPKByValue}
response, err := dirClient.GetProperties(context.Background(), getPropertiesOpts)
_require.NoError(err)
_require.NotNil(response)
_require.Equal(*(resp.IsServerEncrypted), true)
_require.Equal(resp.EncryptionKeySHA256, testcommon.TestCPKByValue.EncryptionKeySHA256)
}

func (s *UnrecordedTestSuite) TestDirCreateDeleteUsingOAuth() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azdatalake/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (f *Client) Rename(ctx context.Context, destinationPath string, options *Re
newPathURL = strings.Split(newPathURL, "?")[0] + "?" + newDestQuery
}
newBlobURL, _ := shared.GetURLs(newPathURL)
lac, mac, smac, createOpts := path.FormatRenameOptions(options, newSrcPath)
lac, mac, smac, createOpts, cpkOpts := path.FormatRenameOptions(options, newSrcPath)

if f.identityCredential() != nil {
newBlobClient, err = blockblob.NewClient(newBlobURL, *f.identityCredential(), nil)
Expand All @@ -293,7 +293,7 @@ func (f *Client) Rename(ctx context.Context, destinationPath string, options *Re
return RenameResponse{}, exported.ConvertToDFSError(err)
}
newFileClient := (*Client)(base.NewPathClient(newPathURL, newBlobURL, newBlobClient, f.generatedFileClientWithDFS().InternalClient().WithClientName(shared.FileClient), f.sharedKey(), f.identityCredential(), f.getClientOptions()))
resp, err := newFileClient.generatedFileClientWithDFS().Create(ctx, createOpts, nil, lac, mac, smac, nil)
resp, err := newFileClient.generatedFileClientWithDFS().Create(ctx, createOpts, nil, lac, mac, smac, cpkOpts)

//return RenameResponse{
// Response: resp,
Expand Down
Loading