Skip to content
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

azfile: upgrade to STG 87 #20871

Merged
merged 13 commits into from
Jun 15, 2023
14 changes: 14 additions & 0 deletions sdk/storage/azfile/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Release History

## 0.2.0 (Unreleased)

### Features Added

* Updated service version to STG 87(2022-11-02).

### Breaking Changes

### Bugs Fixed

### Other Changes

* Updated version of azcore to 1.6.1 and azidentity to 1.3.0.

## 0.1.1 (Unreleased)

### Features Added
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azfile/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/azfile",
"Tag": "go/storage/azfile_600a15563c"
"Tag": "go/storage/azfile_fd8affe5ad"
}
54 changes: 42 additions & 12 deletions sdk/storage/azfile/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ package directory

import (
"context"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/internal/log"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/base"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/exported"
Expand All @@ -32,9 +34,15 @@ type Client base.Client[generated.DirectoryClient]
// - options - client options; pass nil to accept the default values
func NewClientWithNoCredential(directoryURL string, options *ClientOptions) (*Client, error) {
conOptions := shared.GetClientOptions(options)
pl := runtime.NewPipeline(exported.ModuleName, exported.ModuleVersion, runtime.PipelineOptions{}, &conOptions.ClientOptions)
plOpts := runtime.PipelineOptions{}
base.SetPipelineOptions((*base.ClientOptions)(conOptions), &plOpts)

return (*Client)(base.NewDirectoryClient(directoryURL, pl, nil)), nil
azClient, err := azcore.NewClient(shared.DirectoryClient, exported.ModuleVersion, plOpts, &conOptions.ClientOptions)
if err != nil {
return nil, err
}

return (*Client)(base.NewDirectoryClient(directoryURL, azClient, nil, (*base.ClientOptions)(conOptions))), nil
}

// NewClientWithSharedKeyCredential creates an instance of Client with the specified values.
Expand All @@ -44,10 +52,17 @@ func NewClientWithNoCredential(directoryURL string, options *ClientOptions) (*Cl
func NewClientWithSharedKeyCredential(directoryURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error) {
authPolicy := exported.NewSharedKeyCredPolicy(cred)
conOptions := shared.GetClientOptions(options)
conOptions.PerRetryPolicies = append(conOptions.PerRetryPolicies, authPolicy)
pl := runtime.NewPipeline(exported.ModuleName, exported.ModuleVersion, runtime.PipelineOptions{}, &conOptions.ClientOptions)
plOpts := runtime.PipelineOptions{
PerRetry: []policy.Policy{authPolicy},
}
base.SetPipelineOptions((*base.ClientOptions)(conOptions), &plOpts)

azClient, err := azcore.NewClient(shared.DirectoryClient, exported.ModuleVersion, plOpts, &conOptions.ClientOptions)
if err != nil {
return nil, err
}

return (*Client)(base.NewDirectoryClient(directoryURL, pl, cred)), nil
return (*Client)(base.NewDirectoryClient(directoryURL, azClient, cred, (*base.ClientOptions)(conOptions))), nil
}

// NewClientFromConnectionString creates an instance of Client with the specified values.
Expand Down Expand Up @@ -83,6 +98,10 @@ func (d *Client) sharedKey() *SharedKeyCredential {
return base.SharedKey((*base.Client[generated.DirectoryClient])(d))
}

func (d *Client) getClientOptions() *base.ClientOptions {
return base.GetClientOptions((*base.Client[generated.DirectoryClient])(d))
}

// URL returns the URL endpoint used by the Client object.
func (d *Client) URL() string {
return d.generated().Endpoint()
Expand All @@ -93,23 +112,34 @@ func (d *Client) URL() string {
func (d *Client) NewSubdirectoryClient(subDirectoryName string) *Client {
subDirectoryName = url.PathEscape(strings.TrimRight(subDirectoryName, "/"))
subDirectoryURL := runtime.JoinPaths(d.URL(), subDirectoryName)
return (*Client)(base.NewDirectoryClient(subDirectoryURL, d.generated().Pipeline(), d.sharedKey()))
return (*Client)(base.NewDirectoryClient(subDirectoryURL, d.generated().InternalClient(), d.sharedKey(), d.getClientOptions()))
}

// NewFileClient creates a new file.Client object by concatenating fileName to the end of this Client's URL.
// The new file.Client uses the same request policy pipeline as the Client.
func (d *Client) NewFileClient(fileName string) *file.Client {
fileName = url.PathEscape(fileName)
fileURL := runtime.JoinPaths(d.URL(), fileName)
return (*file.Client)(base.NewFileClient(fileURL, d.generated().Pipeline(), d.sharedKey()))

// TODO: remove new azcore.Client creation after the API for shallow copying with new client name is implemented
clOpts := d.getClientOptions()
azClient, err := azcore.NewClient(shared.FileClient, exported.ModuleVersion, *(base.GetPipelineOptions(clOpts)), &(clOpts.ClientOptions))
if err != nil {
if log.Should(exported.EventError) {
log.Writef(exported.EventError, err.Error())
}
return nil
}

return (*file.Client)(base.NewFileClient(fileURL, azClient, d.sharedKey(), clOpts))
}

// Create operation creates a new directory under the specified share or parent directory.
// file.ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes.
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/create-directory.
func (d *Client) Create(ctx context.Context, options *CreateOptions) (CreateResponse, error) {
fileAttributes, fileCreationTime, fileLastWriteTime, opts := options.format()
resp, err := d.generated().Create(ctx, fileAttributes, fileCreationTime, fileLastWriteTime, opts)
fileAttributes, opts := options.format()
resp, err := d.generated().Create(ctx, fileAttributes, opts)
return resp, err
}

Expand All @@ -135,8 +165,8 @@ func (d *Client) GetProperties(ctx context.Context, options *GetPropertiesOption
// file.ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes.
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-directory-properties.
func (d *Client) SetProperties(ctx context.Context, options *SetPropertiesOptions) (SetPropertiesResponse, error) {
fileAttributes, fileCreationTime, fileLastWriteTime, opts := options.format()
resp, err := d.generated().SetProperties(ctx, fileAttributes, fileCreationTime, fileLastWriteTime, opts)
fileAttributes, opts := options.format()
resp, err := d.generated().SetProperties(ctx, fileAttributes, opts)
return resp, err
}

Expand Down Expand Up @@ -195,7 +225,7 @@ func (d *Client) NewListFilesAndDirectoriesPager(options *ListFilesAndDirectorie
if err != nil {
return ListFilesAndDirectoriesResponse{}, err
}
resp, err := d.generated().Pipeline().Do(req)
resp, err := d.generated().InternalClient().Pipeline().Do(req)
if err != nil {
return ListFilesAndDirectoriesResponse{}, err
}
Expand Down
6 changes: 6 additions & 0 deletions sdk/storage/azfile/directory/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ func (d *DirectoryRecordedTestsSuite) TestDirListFilesAndDirsDefault() {
fileCtr += len(resp.Segment.Files)
for _, dir := range resp.Segment.Directories {
_require.NotNil(dir.Name)
_require.Greater(len(*dir.Name), 0)
_require.NotNil(dir.ID)
_require.Nil(dir.Attributes)
_require.Nil(dir.PermissionKey)
Expand All @@ -788,6 +789,7 @@ func (d *DirectoryRecordedTestsSuite) TestDirListFilesAndDirsDefault() {
}
for _, f := range resp.Segment.Files {
_require.NotNil(f.Name)
_require.Greater(len(*f.Name), 0)
_require.NotNil(f.ID)
_require.Nil(f.Attributes)
_require.Nil(f.PermissionKey)
Expand Down Expand Up @@ -934,12 +936,16 @@ func (d *DirectoryRecordedTestsSuite) TestDirListFilesAndDirsWithPrefix() {
_require.NoError(err)
dirCtr += len(resp.Segment.Directories)
fileCtr += len(resp.Segment.Files)
_require.NotNil(resp.Prefix)
_require.Equal(*resp.Prefix, "1")
if len(resp.Segment.Directories) > 0 {
_require.NotNil(resp.Segment.Directories[0].Name)
_require.Greater(len(*resp.Segment.Directories[0].Name), 0)
_require.Equal(*resp.Segment.Directories[0].Name, "1"+dirName)
}
if len(resp.Segment.Files) > 0 {
_require.NotNil(resp.Segment.Files[0].Name)
_require.Greater(len(*resp.Segment.Files[0].Name), 0)
_require.Equal(*resp.Segment.Files[0].Name, "1"+fileName)
}
}
Expand Down
12 changes: 12 additions & 0 deletions sdk/storage/azfile/directory/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ const (
func PossibleListFilesIncludeTypeValues() []ListFilesIncludeType {
return generated.PossibleListFilesIncludeTypeValues()
}

// ShareTokenIntent defines values for ShareTokenIntent
type ShareTokenIntent = generated.ShareTokenIntent

const (
ShareTokenIntentBackup ShareTokenIntent = generated.ShareTokenIntentBackup
)

// PossibleShareTokenIntentValues returns the possible values for the ShareTokenIntent const type.
func PossibleShareTokenIntentValues() []ShareTokenIntent {
return generated.PossibleShareTokenIntentValues()
}
35 changes: 18 additions & 17 deletions sdk/storage/azfile/directory/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package directory

import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/exported"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
Expand Down Expand Up @@ -36,24 +35,25 @@ type CreateOptions struct {
Metadata map[string]*string
}

func (o *CreateOptions) format() (fileAttributes string, fileCreationTime string, fileLastWriteTime string, createOptions *generated.DirectoryClientCreateOptions) {
func (o *CreateOptions) format() (string, *generated.DirectoryClientCreateOptions) {
if o == nil {
return shared.FileAttributesDirectory, shared.DefaultCurrentTimeString, shared.DefaultCurrentTimeString, &generated.DirectoryClientCreateOptions{
FilePermission: to.Ptr(shared.DefaultFilePermissionString),
}
return shared.FileAttributesDirectory, nil
}

fileAttributes, fileCreationTime, fileLastWriteTime = o.FileSMBProperties.Format(true, shared.FileAttributesDirectory, shared.DefaultCurrentTimeString)
fileAttributes, fileCreationTime, fileLastWriteTime, fileChangeTime := o.FileSMBProperties.Format(true, shared.FileAttributesDirectory)

permission, permissionKey := o.FilePermissions.Format(shared.DefaultFilePermissionString)
permission, permissionKey := o.FilePermissions.Format()

createOptions = &generated.DirectoryClientCreateOptions{
createOptions := &generated.DirectoryClientCreateOptions{
FileChangeTime: fileChangeTime,
FileCreationTime: fileCreationTime,
FileLastWriteTime: fileLastWriteTime,
FilePermission: permission,
FilePermissionKey: permissionKey,
Metadata: o.Metadata,
}

return
return fileAttributes, createOptions
}

// ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -95,22 +95,23 @@ type SetPropertiesOptions struct {
FilePermissions *file.Permissions
}

func (o *SetPropertiesOptions) format() (fileAttributes string, fileCreationTime string, fileLastWriteTime string, setPropertiesOptions *generated.DirectoryClientSetPropertiesOptions) {
func (o *SetPropertiesOptions) format() (string, *generated.DirectoryClientSetPropertiesOptions) {
if o == nil {
return shared.DefaultPreserveString, shared.DefaultPreserveString, shared.DefaultPreserveString, &generated.DirectoryClientSetPropertiesOptions{
FilePermission: to.Ptr(shared.DefaultPreserveString),
}
return shared.DefaultPreserveString, nil
}

fileAttributes, fileCreationTime, fileLastWriteTime = o.FileSMBProperties.Format(true, shared.DefaultPreserveString, shared.DefaultPreserveString)
fileAttributes, fileCreationTime, fileLastWriteTime, fileChangeTime := o.FileSMBProperties.Format(true, shared.DefaultPreserveString)

permission, permissionKey := o.FilePermissions.Format(shared.DefaultPreserveString)
permission, permissionKey := o.FilePermissions.Format()

setPropertiesOptions = &generated.DirectoryClientSetPropertiesOptions{
setPropertiesOptions := &generated.DirectoryClientSetPropertiesOptions{
FileChangeTime: fileChangeTime,
FileCreationTime: fileCreationTime,
FileLastWriteTime: fileLastWriteTime,
FilePermission: permission,
FilePermissionKey: permissionKey,
}
return
return fileAttributes, setPropertiesOptions
}

// ---------------------------------------------------------------------------------------------------------------------
Expand Down
37 changes: 26 additions & 11 deletions sdk/storage/azfile/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"bytes"
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"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/internal/log"
Expand Down Expand Up @@ -40,9 +42,15 @@ type Client base.Client[generated.FileClient]
// The directoryPath is optional in the fileURL. If omitted, it points to file within the specified share.
func NewClientWithNoCredential(fileURL string, options *ClientOptions) (*Client, error) {
conOptions := shared.GetClientOptions(options)
pl := runtime.NewPipeline(exported.ModuleName, exported.ModuleVersion, runtime.PipelineOptions{}, &conOptions.ClientOptions)
plOpts := runtime.PipelineOptions{}
base.SetPipelineOptions((*base.ClientOptions)(conOptions), &plOpts)

return (*Client)(base.NewFileClient(fileURL, pl, nil)), nil
azClient, err := azcore.NewClient(shared.FileClient, exported.ModuleVersion, plOpts, &conOptions.ClientOptions)
if err != nil {
return nil, err
}

return (*Client)(base.NewFileClient(fileURL, azClient, nil, (*base.ClientOptions)(conOptions))), nil
}

// NewClientWithSharedKeyCredential creates an instance of Client with the specified values.
Expand All @@ -54,10 +62,17 @@ func NewClientWithNoCredential(fileURL string, options *ClientOptions) (*Client,
func NewClientWithSharedKeyCredential(fileURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error) {
authPolicy := exported.NewSharedKeyCredPolicy(cred)
conOptions := shared.GetClientOptions(options)
conOptions.PerRetryPolicies = append(conOptions.PerRetryPolicies, authPolicy)
pl := runtime.NewPipeline(exported.ModuleName, exported.ModuleVersion, runtime.PipelineOptions{}, &conOptions.ClientOptions)
plOpts := runtime.PipelineOptions{
PerRetry: []policy.Policy{authPolicy},
}
base.SetPipelineOptions((*base.ClientOptions)(conOptions), &plOpts)

azClient, err := azcore.NewClient(shared.FileClient, exported.ModuleVersion, plOpts, &conOptions.ClientOptions)
if err != nil {
return nil, err
}

return (*Client)(base.NewFileClient(fileURL, pl, cred)), nil
return (*Client)(base.NewFileClient(fileURL, azClient, cred, (*base.ClientOptions)(conOptions))), nil
}

// NewClientFromConnectionString creates an instance of Client with the specified values.
Expand Down Expand Up @@ -104,8 +119,8 @@ func (f *Client) URL() string {
// ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes.
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/create-file.
func (f *Client) Create(ctx context.Context, fileContentLength int64, options *CreateOptions) (CreateResponse, error) {
fileAttributes, fileCreationTime, fileLastWriteTime, fileCreateOptions, fileHTTPHeaders, leaseAccessConditions := options.format()
resp, err := f.generated().Create(ctx, fileContentLength, fileAttributes, fileCreationTime, fileLastWriteTime, fileCreateOptions, fileHTTPHeaders, leaseAccessConditions)
fileAttributes, fileCreateOptions, fileHTTPHeaders, leaseAccessConditions := options.format()
resp, err := f.generated().Create(ctx, fileContentLength, fileAttributes, fileCreateOptions, fileHTTPHeaders, leaseAccessConditions)
return resp, err
}

Expand All @@ -130,8 +145,8 @@ func (f *Client) GetProperties(ctx context.Context, options *GetPropertiesOption
// ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes.
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties.
func (f *Client) SetHTTPHeaders(ctx context.Context, options *SetHTTPHeadersOptions) (SetHTTPHeadersResponse, error) {
fileAttributes, fileCreationTime, fileLastWriteTime, opts, fileHTTPHeaders, leaseAccessConditions := options.format()
resp, err := f.generated().SetHTTPHeaders(ctx, fileAttributes, fileCreationTime, fileLastWriteTime, opts, fileHTTPHeaders, leaseAccessConditions)
fileAttributes, opts, fileHTTPHeaders, leaseAccessConditions := options.format()
resp, err := f.generated().SetHTTPHeaders(ctx, fileAttributes, opts, fileHTTPHeaders, leaseAccessConditions)
return resp, err
}

Expand Down Expand Up @@ -166,8 +181,8 @@ func (f *Client) AbortCopy(ctx context.Context, copyID string, options *AbortCop
// Resize operation resizes the file to the specified size.
// For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties.
func (f *Client) Resize(ctx context.Context, size int64, options *ResizeOptions) (ResizeResponse, error) {
fileAttributes, fileCreationTime, fileLastWriteTime, opts, leaseAccessConditions := options.format(size)
resp, err := f.generated().SetHTTPHeaders(ctx, fileAttributes, fileCreationTime, fileLastWriteTime, opts, nil, leaseAccessConditions)
fileAttributes, opts, leaseAccessConditions := options.format(size)
resp, err := f.generated().SetHTTPHeaders(ctx, fileAttributes, opts, nil, leaseAccessConditions)
return resp, err
}

Expand Down
12 changes: 12 additions & 0 deletions sdk/storage/azfile/file/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ type TransferValidationType = exported.TransferValidationType

// TransferValidationTypeMD5 is a TransferValidationType used to provide a precomputed MD5.
type TransferValidationTypeMD5 = exported.TransferValidationTypeMD5

// ShareTokenIntent defines values for ShareTokenIntent
type ShareTokenIntent = generated.ShareTokenIntent

const (
ShareTokenIntentBackup ShareTokenIntent = generated.ShareTokenIntentBackup
)

// PossibleShareTokenIntentValues returns the possible values for the ShareTokenIntent const type.
func PossibleShareTokenIntentValues() []ShareTokenIntent {
return generated.PossibleShareTokenIntentValues()
}
Loading