2021-04-03 10:40:58 +00:00
|
|
|
package mounter
|
2018-07-21 11:35:31 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2021-04-03 10:40:58 +00:00
|
|
|
"github.com/ctrox/csi-s3/pkg/s3"
|
2018-07-21 11:35:31 +00:00
|
|
|
)
|
|
|
|
|
2018-07-22 20:08:48 +00:00
|
|
|
const (
|
|
|
|
goofysCmd = "goofys"
|
|
|
|
defaultRegion = "us-east-1"
|
|
|
|
)
|
2018-07-21 11:35:31 +00:00
|
|
|
|
|
|
|
// Implements Mounter
|
|
|
|
type goofysMounter struct {
|
2021-04-05 13:07:16 +00:00
|
|
|
meta *s3.FSMeta
|
2018-07-21 11:35:31 +00:00
|
|
|
endpoint string
|
|
|
|
region string
|
|
|
|
accessKeyID string
|
|
|
|
secretAccessKey string
|
|
|
|
}
|
|
|
|
|
2021-04-05 13:07:16 +00:00
|
|
|
func newGoofysMounter(meta *s3.FSMeta, cfg *s3.Config) (Mounter, error) {
|
2018-07-21 11:35:31 +00:00
|
|
|
region := cfg.Region
|
|
|
|
// if endpoint is set we need a default region
|
|
|
|
if region == "" && cfg.Endpoint != "" {
|
|
|
|
region = defaultRegion
|
|
|
|
}
|
|
|
|
return &goofysMounter{
|
2021-04-05 13:07:16 +00:00
|
|
|
meta: meta,
|
2018-07-21 11:35:31 +00:00
|
|
|
endpoint: cfg.Endpoint,
|
|
|
|
region: region,
|
|
|
|
accessKeyID: cfg.AccessKeyID,
|
|
|
|
secretAccessKey: cfg.SecretAccessKey,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:43:51 +00:00
|
|
|
func (goofys *goofysMounter) Stage(stageTarget string) error {
|
2018-07-21 11:35:31 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:43:51 +00:00
|
|
|
func (goofys *goofysMounter) Unstage(stageTarget string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (goofys *goofysMounter) Mount(source string, target string) error {
|
2021-07-16 13:33:13 +00:00
|
|
|
fullPath := fmt.Sprintf("%s:%s", goofys.meta.BucketName, goofys.meta.Prefix)
|
2021-07-19 14:17:51 +00:00
|
|
|
// FIXME Add memory limits
|
2021-07-16 13:29:44 +00:00
|
|
|
args := []string{
|
|
|
|
"--endpoint", goofys.endpoint,
|
|
|
|
"--region", goofys.region,
|
|
|
|
"-o", "allow_other",
|
|
|
|
fullPath, target,
|
2018-07-21 11:35:31 +00:00
|
|
|
}
|
2021-07-16 13:29:44 +00:00
|
|
|
args = append(args, goofys.meta.MountOptions...)
|
2018-07-21 11:35:31 +00:00
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", goofys.accessKeyID)
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", goofys.secretAccessKey)
|
2021-07-16 13:29:44 +00:00
|
|
|
return fuseMount(target, goofysCmd, args)
|
2018-07-21 11:35:31 +00:00
|
|
|
}
|