Skip to content

Commit

Permalink
fix(s3fs): fix password file
Browse files Browse the repository at this point in the history
  • Loading branch information
yang.tong committed Jul 18, 2024
1 parent ddbd6fd commit f198272
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/mounter/s3fs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mounter

import (
"encoding/base64"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -38,7 +39,8 @@ func (s3fs *s3fsMounter) Unstage(stageTarget string) error {
}

func (s3fs *s3fsMounter) Mount(source string, target string) error {
if err := writes3fsPass(s3fs.pwFileContent); err != nil {
err, passwordFileName := writes3fsPass(s3fs.pwFileContent)
if err != nil {
return err
}
args := []string{
Expand All @@ -49,20 +51,22 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error {
"-o", fmt.Sprintf("endpoint=%s", s3fs.region),
"-o", "allow_other",
"-o", "mp_umask=000",
"-o", fmt.Sprintf("passwd_file=%s", passwordFileName),
}
return fuseMount(target, s3fsCmd, args)
}

func writes3fsPass(pwFileContent string) error {
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
func writes3fsPass(pwFileContent string) (error, string) {
passwdFileName := base64.StdEncoding.EncodeToString([]byte(pwFileContent))
pwFileName := fmt.Sprintf("%s/%s", os.Getenv("HOME"), passwdFileName)
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
return err, ""
}
_, err = pwFile.WriteString(pwFileContent)
if err != nil {
return err
return err, ""
}
pwFile.Close()
return nil
return nil, pwFileName
}

0 comments on commit f198272

Please sign in to comment.