Skip to content

Commit bafc93c

Browse files
[Storage][Azfile] Fixed create File Api on passing permissionKey (Azure#24813)
* Fixed create File Api * fixed the logic according to the documentation * recording
1 parent 519ee51 commit bafc93c

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

sdk/storage/azfile/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
* Fixed bug where fileClient.Create API call was failing on passing permissionKey parameter. Fixes[#24632(https://github.com/Azure/azure-sdk-for-go/issues/24632)]
1011

1112
### Other Changes
1213

sdk/storage/azfile/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "go",
44
"TagPrefix": "go/storage/azfile",
5-
"Tag": "go/storage/azfile_8ed895c5cb"
5+
"Tag": "go/storage/azfile_ea4253f034"
66
}

sdk/storage/azfile/file/client_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,36 @@ func (f *FileRecordedTestsSuite) TestFileCreateNegativeMetadataInvalid() {
421421
_require.Error(err)
422422
}
423423

424+
func (f *FileRecordedTestsSuite) TestFileCreateWithPermissionKey() {
425+
_require := require.New(f.T())
426+
testName := f.T().Name()
427+
428+
svcClient, err := testcommon.GetServiceClient(f.T(), testcommon.TestAccountDefault, nil)
429+
_require.NoError(err)
430+
431+
shareName := testcommon.GenerateShareName(testName)
432+
shareClient := testcommon.CreateNewShare(context.Background(), _require, shareName, svcClient)
433+
defer testcommon.DeleteShare(context.Background(), _require, shareClient)
434+
435+
createResp, err := shareClient.CreatePermission(context.Background(), testcommon.SampleSDDL, nil)
436+
_require.NoError(err)
437+
_require.NotNil(createResp.FilePermissionKey)
438+
_require.NotEmpty(*createResp.FilePermissionKey)
439+
440+
fileName := testcommon.GenerateFileName(testName)
441+
fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
442+
_, err = fileClient.Create(context.Background(), 1024, &file.CreateOptions{
443+
Permissions: &file.Permissions{
444+
PermissionKey: createResp.FilePermissionKey,
445+
},
446+
})
447+
_require.NoError(err)
448+
449+
getResp, err := fileClient.GetProperties(context.Background(), nil)
450+
_require.NoError(err)
451+
_require.NotNil(getResp.FilePermissionKey)
452+
}
453+
424454
func (f *FileRecordedTestsSuite) TestCreateFileNFS() {
425455
_require := require.New(f.T())
426456
testName := f.T().Name()

sdk/storage/azfile/file/models.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,16 @@ func (o *CreateOptions) format() (*generated.FileClientCreateOptions, *generated
124124
FilePermissionKey: permissionKey,
125125
Metadata: o.Metadata,
126126
}
127-
128-
if permissionKey != nil && *permissionKey != shared.DefaultFilePermissionString {
129-
createOptions.FilePermissionFormat = to.Ptr(PermissionFormat(shared.DefaultFilePermissionFormat))
130-
} else if o.FilePermissionFormat != nil {
131-
createOptions.FilePermissionFormat = to.Ptr(PermissionFormat(*o.FilePermissionFormat))
127+
// Refer the documentation for details - https://learn.microsoft.com/en-us/rest/api/storageservices/create-file#smb-only-request-headers
128+
if permissionKey != nil {
129+
createOptions.FilePermissionKey = permissionKey
130+
} else if permission != nil {
131+
createOptions.FilePermission = permission
132+
if o.FilePermissionFormat != nil {
133+
createOptions.FilePermissionFormat = to.Ptr(*o.FilePermissionFormat)
134+
} else {
135+
createOptions.FilePermissionFormat = to.Ptr(FilePermissionFormatSddl) // optional, default
136+
}
132137
}
133138
}
134139
return createOptions, o.HTTPHeaders, o.LeaseAccessConditions

0 commit comments

Comments
 (0)