Skip to content

Commit 03b6dfa

Browse files
committed
address review: use getValueInMap, fix log message, add unit test
1 parent 423fb53 commit 03b6dfa

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pkg/azurefile/azurefile.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -881,20 +881,12 @@ func (d *Driver) GetAccountInfo(ctx context.Context, volumeID string, secrets, r
881881
if protocol == nfs && fileShareName != "" {
882882
// nfs protocol does not need account key, return directly
883883
// unless createFolderIfNotExist is set with a folderName, which requires account key for data plane API
884-
var needAccountKey bool
885-
var hasFolder bool
886-
for k, v := range reqContext {
887-
switch strings.ToLower(k) {
888-
case createFolderIfNotExistField:
889-
needAccountKey = strings.EqualFold(v, trueValue)
890-
case folderNameField:
891-
hasFolder = v != ""
892-
}
893-
}
884+
needAccountKey := strings.EqualFold(getValueInMap(reqContext, createFolderIfNotExistField), trueValue)
885+
hasFolder := getValueInMap(reqContext, folderNameField) != ""
894886
if !needAccountKey || !hasFolder {
895887
return rgName, accountName, accountKey, fileShareName, diskName, subsID, tenantID, tokenFilePath, err
896888
}
897-
klog.V(2).Infof("NFS protocol with createFolderIfNotExist, fetching account key for data plane API")
889+
klog.V(2).Infof("NFS protocol with createFolderIfNotExist may require an account key for data plane API access")
898890
}
899891

900892
if secretNamespace == "" {

pkg/azurefile/azurefile_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,24 @@ func TestGetAccountInfo(t *testing.T) {
810810
expectFileShareName: "test_sharename",
811811
expectDiskName: "",
812812
},
813+
{
814+
volumeID: "uniqe-volumeid-nfs-createfolder",
815+
rgName: "vol_nfs",
816+
secrets: emptySecret,
817+
reqContext: map[string]string{
818+
resourceGroupField: "vol_nfs",
819+
storageAccountField: "test_accountname",
820+
shareNameField: "test_sharename",
821+
protocolField: "nfs",
822+
createFolderIfNotExistField: "true",
823+
folderNameField: "testfolder",
824+
},
825+
expectErr: false,
826+
err: nil,
827+
expectAccountName: "test_accountname",
828+
expectFileShareName: "test_sharename",
829+
expectDiskName: "",
830+
},
813831
{
814832
volumeID: "invalid_getLatestAccountKey_value##",
815833
rgName: "vol_2",

0 commit comments

Comments
 (0)