2018-07-21 11:35:31 +00:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Implements Mounter
|
|
|
|
type s3fsMounter struct {
|
2018-07-27 10:56:28 +00:00
|
|
|
bucket *bucket
|
2018-07-21 11:35:31 +00:00
|
|
|
url string
|
|
|
|
region string
|
|
|
|
pwFileContent string
|
|
|
|
}
|
|
|
|
|
2018-07-22 20:08:48 +00:00
|
|
|
const (
|
|
|
|
s3fsCmd = "s3fs"
|
|
|
|
)
|
|
|
|
|
2018-07-27 10:56:28 +00:00
|
|
|
func newS3fsMounter(b *bucket, cfg *Config) (Mounter, error) {
|
2018-07-21 11:35:31 +00:00
|
|
|
return &s3fsMounter{
|
2018-07-27 10:56:28 +00:00
|
|
|
bucket: b,
|
2018-07-21 11:35:31 +00:00
|
|
|
url: cfg.Endpoint,
|
|
|
|
region: cfg.Region,
|
|
|
|
pwFileContent: cfg.AccessKeyID + ":" + cfg.SecretAccessKey,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:43:51 +00:00
|
|
|
func (s3fs *s3fsMounter) Stage(stageTarget string) error {
|
2018-07-21 11:35:31 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:43:51 +00:00
|
|
|
func (s3fs *s3fsMounter) Unstage(stageTarget string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s3fs *s3fsMounter) Mount(source string, target string) error {
|
2018-07-21 11:35:31 +00:00
|
|
|
if err := writes3fsPass(s3fs.pwFileContent); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
args := []string{
|
2018-07-27 19:37:32 +00:00
|
|
|
fmt.Sprintf("%s:/%s", s3fs.bucket.Name, s3fs.bucket.FSPath),
|
2018-07-26 20:43:51 +00:00
|
|
|
fmt.Sprintf("%s", target),
|
2018-07-21 11:35:31 +00:00
|
|
|
"-o", "sigv2",
|
|
|
|
"-o", "use_path_request_style",
|
|
|
|
"-o", fmt.Sprintf("url=%s", s3fs.url),
|
|
|
|
"-o", fmt.Sprintf("endpoint=%s", s3fs.region),
|
|
|
|
"-o", "allow_other",
|
|
|
|
"-o", "mp_umask=000",
|
|
|
|
}
|
2018-07-26 20:43:51 +00:00
|
|
|
return fuseMount(target, s3fsCmd, args)
|
2018-07-21 11:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func writes3fsPass(pwFileContent string) error {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
_, err = pwFile.WriteString(pwFileContent)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pwFile.Close()
|
|
|
|
return nil
|
|
|
|
}
|