Skip to content

Commit

Permalink
Do not return error when /Users/biancamoreira is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
biazmoreira committed Apr 2, 2024
1 parent 473e9a4 commit 5ae956b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -84,12 +85,9 @@ type TestingHCPTokenHelper struct {
}

func (h TestingHCPTokenHelper) GetHCPToken() (*HCPToken, error) {
userHome, err := os.UserHomeDir()
if err != nil {
return nil, err
}
userHome := getHomeFolder()
credentialDir := filepath.Join(userHome, testDirectory)
err = os.RemoveAll(credentialDir)
err := os.RemoveAll(credentialDir)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -198,10 +196,7 @@ func eraseConfig() error {
// getCredentialPaths returns the complete credential path and directory.
func getConfigPaths() (configPath string, configDirectory string, err error) {
// Get the user's home directory.
userHome, err := os.UserHomeDir()
if err != nil {
return "", "", fmt.Errorf("failed to retrieve user's home directory path: %v", err)
}
userHome := getHomeFolder()

directoryName := defaultDirectory
// If in test mode, use test directory.
Expand All @@ -217,3 +212,16 @@ func getConfigPaths() (configPath string, configDirectory string, err error) {

return configPath, configDirectory, nil
}

func getHomeFolder() string {
current, e := user.Current()
if e != nil {
// Give up and try to return something sensible
home, err := os.UserHomeDir()
if err != nil {
return ""
}
return home
}
return current.HomeDir
}

0 comments on commit 5ae956b

Please sign in to comment.