Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #413 from ehazlett/proper-check-for-username
Browse files Browse the repository at this point in the history
check properly for username on different platforms
  • Loading branch information
ehazlett committed Jan 27, 2015
2 parents d5a4f2f + 720c4ed commit c209704
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 1 addition & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 14 additions & 6 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"io"
"os"
"os/user"
"path/filepath"
"runtime"
)
Expand All @@ -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")
}

if osUser != "" {
u = osUser
}

return u.Username, nil
return u
}

func CopyFile(src, dst string) error {
Expand Down

0 comments on commit c209704

Please sign in to comment.