Skip to content
Merged
25 changes: 16 additions & 9 deletions api/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,26 @@ func FullProfilePath(dir string) string {

// defaultProfilePath retrieves the default path of the TSH profile.
func defaultProfilePath() string {
// start with UserHomeDir, which is the fastest option as it
// relies only on environment variables and does not perform
// a user lookup (which can be very slow on large AD environments)
home, err := os.UserHomeDir()
if err == nil && home != "" {
return filepath.Join(home, profileDir)
home, ok := UserHomeDir()
if !ok {
home = os.TempDir()
}
return filepath.Join(home, profileDir)
}

home = os.TempDir()
// UserHomeDir returns the current user's home directory if it can be found.
func UserHomeDir() (string, bool) {
// Start with os.UserHomeDir, which is the fastest option as it relies only
// on environment variables and does not perform a user lookup (which can be
// very slow on large AD environments).
if home, err := os.UserHomeDir(); err == nil && home != "" {
return home, true
}
// Fall back to the user lookup.
if u, err := user.Current(); err == nil && u.HomeDir != "" {
home = u.HomeDir
return u.HomeDir, true
}
return filepath.Join(home, profileDir)
return "", false
}

// FromDir reads the user profile from a given directory. If dir is empty,
Expand Down
6 changes: 3 additions & 3 deletions api/utils/keypaths/keypaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ const (
// vnetKnownHosts is the file name of the known_hosts file trusted by
// third-party SSH clients connecting to VNet SSH.
vnetKnownHosts = "vnet_known_hosts"
// vnetSSHConfig is the file name of the generated OpenSSH-compatible config
// VNetSSHConfig is the file name of the generated OpenSSH-compatible config
// file to be used by third-party SSH clients connecting to VNet SSH.
vnetSSHConfig = "vnet_ssh_config"
VNetSSHConfig = "vnet_ssh_config"
)

// Here's the file layout of all these keypaths.
Expand Down Expand Up @@ -463,7 +463,7 @@ func VNetKnownHostsPath(baseDir string) string {
// VNetSSHConfigPath returns the path to VNet's generated OpenSSH-compatible
// config file.
func VNetSSHConfigPath(baseDir string) string {
return filepath.Join(baseDir, vnetSSHConfig)
return filepath.Join(baseDir, VNetSSHConfig)
}

// TrimKeyPathSuffix returns the given path with any key suffix/extension trimmed off.
Expand Down
164 changes: 139 additions & 25 deletions gen/proto/go/teleport/lib/vnet/diag/v1/diag.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading