ftp,sftp: fix docs for usernames

- factor env.CurrentUser out of backend/sftp
- Use env.CurrentUser in ftp and sftp
- fix docs to have correct username
This commit is contained in:
Nick Craig-Wood 2020-09-27 11:40:58 +01:00
parent 17acae2b00
commit 41ec712aa9
5 changed files with 34 additions and 23 deletions

20
lib/env/env.go vendored
View file

@ -3,6 +3,7 @@ package env
import (
"os"
"os/user"
homedir "github.com/mitchellh/go-homedir"
)
@ -24,3 +25,22 @@ func ShellExpand(s string) string {
}
return s
}
// CurrentUser finds the current user name or "" if not found
func CurrentUser() (userName string) {
userName = os.Getenv("USER")
// If we are making docs just use $USER
if userName == "$USER" {
return userName
}
// Try reading using the OS
usr, err := user.Current()
if err == nil {
return usr.Username
}
// Fall back to reading $USER then $LOGNAME
if userName != "" {
return userName
}
return os.Getenv("LOGNAME")
}