Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions sdk/storage/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
* HNS Encryption Context support
* Pagination Support for recursive directory deletion
* Bundle ability to set permission, owner, group, acl, lease, expiry time and umask along with FileSystem.CreateFile and FileSystem.CreateDirectory APIs.
* Added support for AAD Audience when OAuth is used.
* Updated service version to `2023-11-03`

### Breaking Changes

### Bugs Fixed

### Other Changes
* Updated azcore version to `1.11.1`

## 1.1.1 (2024-02-29)

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_36960f5092"
"Tag": "go/storage/azdatalake_5a2047f8e3"
}
3 changes: 2 additions & 1 deletion sdk/storage/azdatalake/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Client base.CompositeClient[generated.PathClient, generated_blob.BlobClient
func NewClient(directoryURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
blobURL, directoryURL := shared.GetURLs(directoryURL)

authPolicy := runtime.NewBearerTokenPolicy(cred, []string{shared.TokenScope}, nil)
audience := base.GetAudience((*base.ClientOptions)(options))
authPolicy := shared.NewStorageChallengePolicy(cred, audience)
conOptions := shared.GetClientOptions(options)
plOpts := runtime.PipelineOptions{
PerRetry: []policy.Policy{authPolicy},
Expand Down
67 changes: 67 additions & 0 deletions sdk/storage/azdatalake/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2922,3 +2922,70 @@ func (s *UnrecordedTestSuite) TestDirCreateDeleteUsingOAuth() {
_, err = dirClient.GetProperties(context.Background(), nil)
_require.NoError(err)
}

func (s *RecordedTestSuite) TestCreateDirectoryClientDefaultAudience() {
_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)

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

dirName := testcommon.GenerateDirName(testName)
dirURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName + "/" + dirName

dirClient, err := directory.NewClient(dirURL, cred, &directory.ClientOptions{Audience: "https://storage.azure.com/"})
_require.NoError(err)

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

_, err = dirClient.GetProperties(context.Background(), nil)
_require.NoError(err)

}

func (s *RecordedTestSuite) TestCreateDirectoryClientCustomAudience() {
_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)

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

dirName := testcommon.GenerateDirName(testName)
dirURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName + "/" + dirName

options := &directory.ClientOptions{Audience: "https://" + accountName + ".blob.core.windows.net"}
testcommon.SetClientOptions(s.T(), &options.ClientOptions)

dirClient, err := directory.NewClient(dirURL, cred, options)
_require.NoError(err)

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

_, err = dirClient.GetProperties(context.Background(), nil)
_require.NoError(err)

}
3 changes: 2 additions & 1 deletion sdk/storage/azdatalake/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type Client base.CompositeClient[generated.PathClient, generated_blob.BlobClient
// - options - client options; pass nil to accept the default values
func NewClient(fileURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
blobURL, fileURL := shared.GetURLs(fileURL)
authPolicy := runtime.NewBearerTokenPolicy(cred, []string{shared.TokenScope}, nil)
audience := base.GetAudience((*base.ClientOptions)(options))
authPolicy := shared.NewStorageChallengePolicy(cred, audience)
conOptions := shared.GetClientOptions(options)
plOpts := runtime.PipelineOptions{
PerRetry: []policy.Policy{authPolicy},
Expand Down
67 changes: 67 additions & 0 deletions sdk/storage/azdatalake/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5484,3 +5484,70 @@ func TestUploadSmallChunkSize(t *testing.T) {

_require.Equal(atomic.LoadUint64(&fbb.numChunks), numChunks)
}

func (s *RecordedTestSuite) TestFileClientCustomAudience() {
_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)

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

fileName := testcommon.GenerateFileName(testName)
fileURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName + "/" + fileName

options := &file.ClientOptions{Audience: "https://" + accountName + ".blob.core.windows.net"}
testcommon.SetClientOptions(s.T(), &options.ClientOptions)

fClient, err := file.NewClient(fileURL, cred, options)
_require.NoError(err)

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

_, err = fClient.GetProperties(context.Background(), nil)
_require.NoError(err)
}

func (s *RecordedTestSuite) TestFileClientDefaultAudience() {
_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)

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

fileName := testcommon.GenerateFileName(testName)
fileURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName + "/" + fileName

options := &file.ClientOptions{Audience: "https://storage.azure.com/"}

fClient, err := file.NewClient(fileURL, cred, options)
_require.NoError(err)

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

_, err = fClient.GetProperties(context.Background(), nil)
_require.NoError(err)
}
3 changes: 2 additions & 1 deletion sdk/storage/azdatalake/filesystem/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type Client base.CompositeClient[generated.FileSystemClient, generated.FileSyste
// - options - client options; pass nil to accept the default values
func NewClient(filesystemURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
containerURL, filesystemURL := shared.GetURLs(filesystemURL)
authPolicy := runtime.NewBearerTokenPolicy(cred, []string{shared.TokenScope}, nil)
audience := base.GetAudience((*base.ClientOptions)(options))
authPolicy := shared.NewStorageChallengePolicy(cred, audience)
conOptions := shared.GetClientOptions(options)
plOpts := runtime.PipelineOptions{
PerRetry: []policy.Policy{authPolicy},
Expand Down
54 changes: 54 additions & 0 deletions sdk/storage/azdatalake/filesystem/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2084,3 +2084,57 @@ func (s *RecordedTestSuite) TestCreateDirectoryInFileSystemSetOptions() {
_require.Equal(filesystem.StateTypeLeased, *response.LeaseState)

}

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

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

filesystemName := testcommon.GenerateFileSystemName(testName)
fsURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName

options := &filesystem.ClientOptions{Audience: "https://storage.azure.com/"}
testcommon.SetClientOptions(s.T(), &options.ClientOptions)
fsClient, err := filesystem.NewClient(fsURL, cred, options)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

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

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

}

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

cred, err := testcommon.GetGenericTokenCredential()
_require.NoError(err)

accountName, _ := testcommon.GetGenericAccountInfo(testcommon.TestAccountDatalake)
_require.Greater(len(accountName), 0)

filesystemName := testcommon.GenerateFileSystemName(testName)
fsURL := "https://" + accountName + ".dfs.core.windows.net/" + filesystemName

options := &filesystem.ClientOptions{Audience: "https://" + accountName + ".blob.core.windows.net"}
testcommon.SetClientOptions(s.T(), &options.ClientOptions)
fsClient, err := filesystem.NewClient(fsURL, cred, options)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

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

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

}
8 changes: 4 additions & 4 deletions sdk/storage/azdatalake/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake
go 1.18

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.1
Expand All @@ -19,9 +19,9 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions sdk/storage/azdatalake/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2 h1:c4k2FIYIh4xtwqrQwV0Ct1v5+ehlNXj5NI/MWVsiTkQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2/go.mod h1:5FDJtLEO/GxwNgUxbwrY3LP0pEoThTQJtk2oysdXHxM=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 h1:LqbJ/WzJUwBf8UiaSzgX7aMclParm9/5Vgp+TY51uBQ=
Expand All @@ -26,13 +26,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
14 changes: 14 additions & 0 deletions sdk/storage/azdatalake/internal/base/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/generated"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/generated_blob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/shared"
"strings"
)

// ClientOptions contains the optional parameters when creating a Client.
type ClientOptions struct {
azcore.ClientOptions
pipelineOptions *runtime.PipelineOptions
// Audience to use when requesting tokens for Azure Active Directory authentication.
// Only has an effect when credential is of type TokenCredential. The value could be
// https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
Comment thread
souravgupta-msft marked this conversation as resolved.
Audience string
}

func GetPipelineOptions(clOpts *ClientOptions) *runtime.PipelineOptions {
Expand Down Expand Up @@ -91,3 +97,11 @@ func NewPathClient(pathURL string, pathURLWithBlobEndpoint string, client *block
func GetCompositeClientOptions[T, K, U any](client *CompositeClient[T, K, U]) *ClientOptions {
return client.options
}

func GetAudience(clOpts *ClientOptions) string {
if clOpts == nil || len(strings.TrimSpace(clOpts.Audience)) == 0 {
return shared.TokenScope
} else {
return strings.TrimRight(clOpts.Audience, "/") + "/.default"
}
}
Loading