2018-07-14 08:48:22 +00:00
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
goofys "github.com/kahing/goofys/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultRegion = "us-east-1"
|
|
|
|
|
2018-07-16 18:24:54 +00:00
|
|
|
func goofysMount(bucket string, cfg *Config, targetPath string) error {
|
|
|
|
goofysCfg := &goofys.Config{
|
2018-07-14 08:48:22 +00:00
|
|
|
MountPoint: targetPath,
|
2018-07-16 18:24:54 +00:00
|
|
|
Endpoint: cfg.Endpoint,
|
|
|
|
Region: cfg.Region,
|
2018-07-14 08:48:22 +00:00
|
|
|
DirMode: 0755,
|
|
|
|
FileMode: 0644,
|
|
|
|
MountOptions: map[string]string{
|
|
|
|
"allow_other": "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if cfg.Endpoint != "" {
|
|
|
|
cfg.Region = defaultRegion
|
|
|
|
}
|
2018-07-16 18:24:54 +00:00
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", cfg.AccessKeyID)
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", cfg.SecretAccessKey)
|
2018-07-14 08:48:22 +00:00
|
|
|
|
2018-07-16 18:24:54 +00:00
|
|
|
_, _, err := goofys.Mount(context.Background(), bucket, goofysCfg)
|
2018-07-14 08:48:22 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error mounting via goofys: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|