0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-06-02 18:29:42 +02:00
wp-git-clone/git/utils.go

48 lines
569 B
Go
Raw Normal View History

2023-12-23 00:59:23 +01:00
package git
import (
"fmt"
"os"
"os/user"
"path/filepath"
)
const (
netrcFile = `
machine %s
login %s
password %s
`
)
const (
strictFilePerm = 0o600
)
// WriteNetrc writes the netrc file.
func WriteNetrc(machine, login, password string) error {
netrcContent := fmt.Sprintf(
netrcFile,
machine,
login,
password,
)
home := "/root"
if currentUser, err := user.Current(); err == nil {
home = currentUser.HomeDir
}
netpath := filepath.Join(
home,
".netrc",
)
return os.WriteFile(
netpath,
[]byte(netrcContent),
strictFilePerm,
)
}