check properly for username on different platforms

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-01-27 10:28:55 -05:00
parent d5a4f2f1c4
commit 720c4edfd2
No known key found for this signature in database
GPG Key ID: A519480096146526
2 changed files with 15 additions and 11 deletions

View File

@ -11,16 +11,12 @@ import (
)
func before(c *cli.Context) error {
caCertPath := c.GlobalString("tls-ca-cert")
caKeyPath := c.GlobalString("tls-ca-key")
clientCertPath := c.GlobalString("tls-client-cert")
clientKeyPath := c.GlobalString("tls-client-key")
org, err := utils.GetUsername()
if err != nil {
return err
}
org := utils.GetUsername()
bits := 2048
if _, err := os.Stat(utils.GetMachineDir()); err != nil {

View File

@ -3,7 +3,6 @@ package utils
import (
"io"
"os"
"os/user"
"path/filepath"
"runtime"
)
@ -27,13 +26,22 @@ func GetMachineClientCertDir() string {
return filepath.Join(GetMachineDir(), ".client")
}
func GetUsername() (string, error) {
u, err := user.Current()
if err != nil {
return "", err
func GetUsername() string {
u := "unknown"
osUser := ""
switch runtime.GOOS {
case "darwin", "linux":
osUser = os.Getenv("USER")
case "windows":
osUser = os.Getenv("USERNAME")
}
return u.Username, nil
if osUser != "" {
u = osUser
}
return u
}
func CopyFile(src, dst string) error {