write auth.json file

This commit is contained in:
Brad Rydzewski 2021-06-17 17:22:30 -04:00
parent 904449e95e
commit 494d08375c

View File

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -59,18 +60,21 @@ type (
func (p Plugin) Exec() error { func (p Plugin) Exec() error {
// Create Auth Config File // Create Auth Config File
if p.Login.Config != "" { if p.Login.Config != "" {
homeDir, err := os.UserHomeDir() user, err := user.Current()
if err != nil { if err != nil {
return fmt.Errorf("failed to find home directory: %s", err) return fmt.Errorf("Error getting the current user: %s", err)
}
root := fmt.Sprintf("/var/tmp/%s/containers/containers/", user.Uid)
if err := os.MkdirAll(root, 0777); err != nil {
return fmt.Errorf("Error writing runtime dir: %s", err)
} }
dockerHome := fmt.Sprintf("%s/.docker/config.json", homeDir)
os.MkdirAll(dockerHome, 0600)
path := filepath.Join(dockerHome, "config.json") path := filepath.Join(root, "auth.json")
err = ioutil.WriteFile(path, []byte(p.Login.Config), 0600) if err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600); err != nil {
if err != nil { return fmt.Errorf("Error writing auth.json: %s", err)
return fmt.Errorf("Error writing config.json: %s", err)
} }
fmt.Printf("Config written to %s\n", path)
} }
// login to the Docker registry // login to the Docker registry