@@ -12,12 +12,12 @@ import (
1212)
1313
1414// rotateTokenFiles rotates (or initializes) token files
15- func rotateTokenFiles (dir string , secrets map [string ]string ) (rotatedFiles map [ string ] string , err error ) {
15+ func rotateTokenFiles (dir string , secrets map [string ]string ) (rotated bool , err error ) {
1616 if secrets == nil {
17- return nil , nil
17+ return false , nil
1818 }
19- // token
20- rotatedFiles = make ( map [ string ] string )
19+ // tokem
20+ var fileUpdate bool
2121 tokenKey := []string {oss .KeyAccessKeyId , oss .KeyAccessKeySecret , oss .KeySecurityToken }
2222 for _ , key := range tokenKey {
2323 val := secrets [filepath .Join (utils .GetPasswdFileName ("ossfs2" ), key )]
@@ -26,12 +26,12 @@ func rotateTokenFiles(dir string, secrets map[string]string) (rotatedFiles map[s
2626 klog .Error (err )
2727 return
2828 }
29- err = os . WriteFile (filepath .Join (dir , key ), []byte (val ), 0o600 )
29+ fileUpdate , err = utils . WriteFileWithLock (filepath .Join (dir , key ), []byte (val ), 0o600 )
3030 if err != nil {
31- klog .Errorf ("writeFile %s failed %v" , key , err )
31+ klog .Errorf ("WriteFileWithLock %s failed %v" , key , err )
3232 return
3333 }
34- rotatedFiles [ key ] = filepath . Join ( dir , key )
34+ rotated = rotated || fileUpdate
3535 }
3636 return
3737}
@@ -51,7 +51,7 @@ func prepareCredentialFiles(target string, secrets map[string]string) (file, dir
5151 }
5252
5353 if passwd := secrets [utils .GetPasswdFileName ("ossfs2" )]; passwd != "" {
54- err = os . WriteFile (filepath .Join (hashDir , utils .GetPasswdFileName ("ossfs2" )), []byte (passwd ), 0o600 )
54+ _ , err = utils . WriteFileWithLock (filepath .Join (hashDir , utils .GetPasswdFileName ("ossfs2" )), []byte (passwd ), 0o600 )
5555 if err != nil {
5656 return
5757 }
@@ -60,13 +60,16 @@ func prepareCredentialFiles(target string, secrets map[string]string) (file, dir
6060 }
6161
6262 // token
63- tokenFiles , err := rotateTokenFiles (hashDir , secrets )
64- if len (tokenFiles ) != 0 {
63+ token , err := rotateTokenFiles (hashDir , secrets )
64+ if err != nil {
65+ return
66+ }
67+ if token {
6568 dir = hashDir
6669 options = append (options ,
67- fmt .Sprintf ("oss_sts_multi_conf_ak_file=%s" , tokenFiles [ oss .KeyAccessKeyId ] ),
68- fmt .Sprintf ("oss_sts_multi_conf_sk_file=%s" , tokenFiles [ oss .KeyAccessKeySecret ] ),
69- fmt .Sprintf ("oss_sts_multi_conf_token_file=%s" , tokenFiles [ oss .KeySecurityToken ] ),
70+ fmt .Sprintf ("oss_sts_multi_conf_ak_file=%s" , filepath . Join ( hashDir , oss .KeyAccessKeyId ) ),
71+ fmt .Sprintf ("oss_sts_multi_conf_sk_file=%s" , filepath . Join ( hashDir , oss .KeyAccessKeySecret ) ),
72+ fmt .Sprintf ("oss_sts_multi_conf_token_file=%s" , filepath . Join ( hashDir , oss .KeySecurityToken ) ),
7073 )
7174 return
7275 }
0 commit comments