@@ -851,24 +851,13 @@ func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, sto
851
851
klog .Warningf ("failed to authorize azcopy with identity, error: %v" , err )
852
852
} else {
853
853
if len (authAzcopyEnv ) > 0 {
854
- // search in cache first
855
- cache , err := d .azcopySasTokenCache .Get (accountName , azcache .CacheReadTypeDefault )
856
- if err != nil {
857
- return "" , nil , fmt .Errorf ("get(%s) from azcopySasTokenCache failed with error: %v" , accountName , err )
854
+ out , testErr := d .azcopy .TestListJobs (accountName , storageEndpointSuffix , authAzcopyEnv )
855
+ if testErr != nil {
856
+ return "" , nil , fmt .Errorf ("azcopy list command failed with error(%v): %v" , testErr , out )
858
857
}
859
- if cache != nil {
860
- klog .V ( 2 ). Infof ( "use sas token for account(%s) since this account is found in azcopySasTokenCache" , accountName )
858
+ if strings . Contains ( out , authorizationPermissionMismatch ) {
859
+ klog .Warningf ( "azcopy list failed with AuthorizationPermissionMismatch error, should assign \" Storage Blob Data Contributor \" role to controller identity, fall back to use sas token, original output: %v" , out )
861
860
useSasToken = true
862
- } else {
863
- out , testErr := d .azcopy .TestListJobs (accountName , storageEndpointSuffix , authAzcopyEnv )
864
- if testErr != nil {
865
- return "" , nil , fmt .Errorf ("azcopy list command failed with error(%v): %v" , testErr , out )
866
- }
867
- if strings .Contains (out , authorizationPermissionMismatch ) {
868
- klog .Warningf ("azcopy list failed with AuthorizationPermissionMismatch error, should assign \" Storage Blob Data Contributor\" role to controller identity, fall back to use sas token, original output: %v" , out )
869
- d .azcopySasTokenCache .Set (accountName , "" )
870
- useSasToken = true
871
- }
872
861
}
873
862
}
874
863
}
@@ -882,7 +871,7 @@ func (d *Driver) getAzcopyAuth(ctx context.Context, accountName, accountKey, sto
882
871
}
883
872
}
884
873
klog .V (2 ).Infof ("generate sas token for account(%s)" , accountName )
885
- sasToken , err := generateSASToken (accountName , accountKey , storageEndpointSuffix , d .sasTokenExpirationMinutes )
874
+ sasToken , err := d . generateSASToken (accountName , accountKey , storageEndpointSuffix , d .sasTokenExpirationMinutes )
886
875
return sasToken , nil , err
887
876
}
888
877
return "" , authAzcopyEnv , nil
@@ -914,7 +903,17 @@ func parseDays(dayStr string) (int32, error) {
914
903
}
915
904
916
905
// generateSASToken generate a sas token for storage account
917
- func generateSASToken (accountName , accountKey , storageEndpointSuffix string , expiryTime int ) (string , error ) {
906
+ func (d * Driver ) generateSASToken (accountName , accountKey , storageEndpointSuffix string , expiryTime int ) (string , error ) {
907
+ // search in cache first
908
+ cache , err := d .azcopySasTokenCache .Get (accountName , azcache .CacheReadTypeDefault )
909
+ if err != nil {
910
+ return "" , fmt .Errorf ("get(%s) from azcopySasTokenCache failed with error: %v" , accountName , err )
911
+ }
912
+ if cache != nil {
913
+ klog .V (2 ).Infof ("use sas token for account(%s) since this account is found in azcopySasTokenCache" , accountName )
914
+ return cache .(string ), nil
915
+ }
916
+
918
917
credential , err := azblob .NewSharedKeyCredential (accountName , accountKey )
919
918
if err != nil {
920
919
return "" , status .Errorf (codes .Internal , fmt .Sprintf ("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s" , accountName , err .Error ()))
@@ -936,5 +935,7 @@ func generateSASToken(accountName, accountKey, storageEndpointSuffix string, exp
936
935
if err != nil {
937
936
return "" , err
938
937
}
939
- return "?" + u .RawQuery , nil
938
+ sasToken := "?" + u .RawQuery
939
+ d .azcopySasTokenCache .Set (accountName , sasToken )
940
+ return sasToken , nil
940
941
}
0 commit comments