Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making defaultPath evaluation lazy #8

Closed
xxzefgh opened this issue Nov 17, 2020 · 5 comments · Fixed by #9
Closed

Making defaultPath evaluation lazy #8

xxzefgh opened this issue Nov 17, 2020 · 5 comments · Fixed by #9

Comments

@xxzefgh
Copy link

xxzefgh commented Nov 17, 2020

Would you consider wrapping defaultPath in a function? The issue is on Windows environments HOME is not set by default. Simple solution would be setting it manually when the program starts:

os.Setenv("HOME", os.Getenv("USERPROFILE"))

but it doesn't get recognized by goph since it is evaluated beforehand.

@xxzefgh
Copy link
Author

xxzefgh commented Nov 17, 2020

I am using this workaround now:

func getConnection(target DeploymentTarget) (*goph.Client, error) {
	callback, err := goph.KnownHosts(os.ExpandEnv("$HOME/.ssh/known_hosts"))
	if err == nil {
		client, err := goph.NewConn(&goph.Config{
			User:     target.Config.User,
			Addr:     target.Config.Address,
			Port:     22,
			Auth:     goph.Password(target.Config.Password),
			Timeout:  goph.DefaultTimeout,
			Callback: callback,
		})

		if err == nil {
			return client, nil
		}
	}

	return nil, err
}

@melbahja
Copy link
Owner

hi, thanks for your report.
can you check the pull request fix ?

@xxzefgh
Copy link
Author

xxzefgh commented Nov 17, 2020

that would probably work but os/user prevents cross-compilation, UserHomeDir is better option but it's fairly new

@melbahja
Copy link
Owner

melbahja commented Nov 17, 2020

changed to os UserHomeDir
Thanks :)

@xxzefgh
Copy link
Author

xxzefgh commented Nov 18, 2020

@melbahja thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants