Merge pull request #57 from zjx20/fix-env

Don't call os.Setenv()
This commit is contained in:
Vitaliy Filippov 2023-06-05 18:49:19 +03:00 committed by GitHub
commit 519c4f0bd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View file

@ -75,9 +75,11 @@ func (geesefs *geesefsMounter) MountDirect(target string, args []string) error {
"-o", "allow_other", "-o", "allow_other",
"--log-file", "/dev/stderr", "--log-file", "/dev/stderr",
}, args...) }, args...)
os.Setenv("AWS_ACCESS_KEY_ID", geesefs.accessKeyID) envs := []string{
os.Setenv("AWS_SECRET_ACCESS_KEY", geesefs.secretAccessKey) "AWS_ACCESS_KEY_ID=" + geesefs.accessKeyID,
return fuseMount(target, geesefsCmd, args) "AWS_SECRET_ACCESS_KEY=" + geesefs.secretAccessKey,
}
return fuseMount(target, geesefsCmd, args, envs)
} }
type execCmd struct { type execCmd struct {

View file

@ -57,9 +57,11 @@ func New(meta *s3.FSMeta, cfg *s3.Config) (Mounter, error) {
} }
} }
func fuseMount(path string, command string, args []string) error { func fuseMount(path string, command string, args []string, envs []string) error {
cmd := exec.Command(command, args...) cmd := exec.Command(command, args...)
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
// cmd.Environ() returns envs inherited from the current process
cmd.Env = append(cmd.Environ(), envs...)
glog.V(3).Infof("Mounting fuse with command: %s and args: %s", command, args) glog.V(3).Infof("Mounting fuse with command: %s and args: %s", command, args)
out, err := cmd.Output() out, err := cmd.Output()

View file

@ -47,7 +47,9 @@ func (rclone *rcloneMounter) Mount(target, volumeID string) error {
args = append(args, fmt.Sprintf("--s3-region=%s", rclone.region)) args = append(args, fmt.Sprintf("--s3-region=%s", rclone.region))
} }
args = append(args, rclone.meta.MountOptions...) args = append(args, rclone.meta.MountOptions...)
os.Setenv("AWS_ACCESS_KEY_ID", rclone.accessKeyID) envs := []string{
os.Setenv("AWS_SECRET_ACCESS_KEY", rclone.secretAccessKey) "AWS_ACCESS_KEY_ID=" + rclone.accessKeyID,
return fuseMount(target, rcloneCmd, args) "AWS_SECRET_ACCESS_KEY=" + rclone.secretAccessKey,
}
return fuseMount(target, rcloneCmd, args, envs)
} }

View file

@ -44,7 +44,7 @@ func (s3fs *s3fsMounter) Mount(target, volumeID string) error {
args = append(args, "-o", fmt.Sprintf("endpoint=%s", s3fs.region)) args = append(args, "-o", fmt.Sprintf("endpoint=%s", s3fs.region))
} }
args = append(args, s3fs.meta.MountOptions...) args = append(args, s3fs.meta.MountOptions...)
return fuseMount(target, s3fsCmd, args) return fuseMount(target, s3fsCmd, args, nil)
} }
func writes3fsPass(pwFileContent string) error { func writes3fsPass(pwFileContent string) error {