0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-09-20 01:12:47 +02:00
wp-git-action/plugin/util.go

29 lines
524 B
Go
Raw Normal View History

package plugin
import (
2024-05-06 20:29:57 +02:00
"fmt"
"os"
"path/filepath"
)
2024-05-06 20:29:57 +02:00
const (
netrcFile = `machine %s
login %s
password %s
`
)
const strictFilePerm = 0o600
2024-05-06 20:29:57 +02:00
// WriteNetrc writes the netrc file.
func WriteNetrc(path, machine, login, password string) error {
netrcPath := filepath.Join(path, ".netrc")
netrcContent := fmt.Sprintf(netrcFile, machine, login, password)
2024-05-06 20:29:57 +02:00
if err := os.WriteFile(netrcPath, []byte(netrcContent), strictFilePerm); err != nil {
return fmt.Errorf("failed to create .netrc file: %w", err)
}
2024-05-06 20:29:57 +02:00
return nil
}