k8s-csi-s3/pkg/s3/s3fs.go

44 lines
970 B
Go
Raw Normal View History

2018-07-14 08:48:22 +00:00
package s3
import (
"fmt"
"os"
"os/exec"
)
2018-07-16 18:24:54 +00:00
func s3fsMount(bucket string, cfg *Config, targetPath string) error {
if err := writes3fsPass(cfg); err != nil {
2018-07-14 08:48:22 +00:00
return err
}
args := []string{
fmt.Sprintf("%s", bucket),
fmt.Sprintf("%s", targetPath),
"-o", "sigv2",
"-o", "use_path_request_style",
2018-07-16 18:24:54 +00:00
"-o", fmt.Sprintf("url=%s", cfg.Endpoint),
"-o", fmt.Sprintf("endpoint=%s", cfg.Region),
2018-07-14 08:48:22 +00:00
"-o", "allow_other",
"-o", "mp_umask=000",
}
cmd := exec.Command("s3fs", args...)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Error mounting using s3fs, output: %s", out)
}
return nil
}
2018-07-16 18:24:54 +00:00
func writes3fsPass(cfg *Config) error {
2018-07-14 08:48:22 +00:00
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
2018-07-16 18:24:54 +00:00
_, err = pwFile.WriteString(cfg.AccessKeyID + ":" + cfg.SecretAccessKey)
2018-07-14 08:48:22 +00:00
if err != nil {
return err
}
pwFile.Close()
return nil
}