opentofu/command/cliconfig/config_unix.go
Martin Atkins 1e2da4f776 command/cliconfig: New CredentialsSource implementation
This new implementation is not yet used, but should eventually replace the
technique of composing together various types from the svchost/auth
package, since our requirements are now complex enough that they're more
straightforward to express in direct code within a single type than as
a composition of the building blocks in the svchost/auth package.
2019-08-23 11:57:11 -07:00

58 lines
1.2 KiB
Go

// +build !windows
package cliconfig
import (
"errors"
"os"
"os/user"
"path/filepath"
)
func configFile() (string, error) {
dir, err := homeDir()
if err != nil {
return "", err
}
return filepath.Join(dir, ".terraformrc"), nil
}
func configDir() (string, error) {
dir, err := homeDir()
if err != nil {
return "", err
}
return filepath.Join(dir, ".terraform.d"), nil
}
func homeDir() (string, error) {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); home != "" {
// FIXME: homeDir gets called from globalPluginDirs during init, before
// the logging is setup. We should move meta initializtion outside of
// init, but in the meantime we just need to silence this output.
//log.Printf("[DEBUG] Detected home directory from env var: %s", home)
return home, nil
}
// If that fails, try build-in module
user, err := user.Current()
if err != nil {
return "", err
}
if user.HomeDir == "" {
return "", errors.New("blank output")
}
return user.HomeDir, nil
}
func replaceFileAtomic(source, destination string) error {
// On Unix systems, a rename is sufficiently atomic.
return os.Rename(source, destination)
}