2018-07-21 11:35:31 +00:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
goofysApi "github.com/kahing/goofys/api"
|
|
|
|
)
|
|
|
|
|
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 {
|
2018-07-27 10:56:28 +00:00
|
|
|
bucket *bucket
|
2018-07-21 11:35:31 +00:00
|
|
|
endpoint string
|
|
|
|
region string
|
|
|
|
accessKeyID string
|
|
|
|
secretAccessKey string
|
|
|
|
}
|
|
|
|
|
2018-07-27 10:56:28 +00:00
|
|
|
func newGoofysMounter(b *bucket, cfg *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{
|
2018-07-27 10:56:28 +00:00
|
|
|
bucket: b,
|
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 {
|
2018-07-21 11:35:31 +00:00
|
|
|
goofysCfg := &goofysApi.Config{
|
2018-07-26 20:43:51 +00:00
|
|
|
MountPoint: target,
|
2018-07-21 11:35:31 +00:00
|
|
|
Endpoint: goofys.endpoint,
|
|
|
|
Region: goofys.region,
|
|
|
|
DirMode: 0755,
|
|
|
|
FileMode: 0644,
|
|
|
|
MountOptions: map[string]string{
|
|
|
|
"allow_other": "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", goofys.accessKeyID)
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", goofys.secretAccessKey)
|
2018-07-27 19:37:32 +00:00
|
|
|
fullPath := fmt.Sprintf("%s:%s", goofys.bucket.Name, goofys.bucket.FSPath)
|
2018-07-21 11:35:31 +00:00
|
|
|
|
2018-07-27 19:37:32 +00:00
|
|
|
_, _, err := goofysApi.Mount(context.Background(), fullPath, goofysCfg)
|
2018-07-21 11:35:31 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error mounting via goofys: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|