Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,34 +158,32 @@ func (p Plugin) Exec() error {
os.MkdirAll(dockerHome, 0600)

path := filepath.Join(dockerHome, "config.json")
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
err := os.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writing config.json: %s", err)
}
err = os.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writing config.json: %s", err)
}
file.Close()
}

// add base image docker credentials to the existing config file, else create new
// instead of writing to config file directly, using docker's login func
// is better to integrate with various credential helpers,
// it also handles different registry specific logic in a better way,
// as opposed to config write where different registries need to be addressed differently.
// It handles any changes in the authentication process across different Docker versions.

if p.BaseImagePassword != "" {
json, err := setDockerAuth(p.Login.Username, p.Login.Password, p.Login.Registry,
p.BaseImageUsername, p.BaseImagePassword, p.BaseImageRegistry)
if err != nil {
return fmt.Errorf("Failed to set authentication in docker config %s", err)
}
os.MkdirAll(dockerHome, 0600)
path := filepath.Join(dockerHome, "config.json")
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return fmt.Errorf("Error opening config.json: %s", err)
}
defer file.Close()
_, err = file.Write(json)
var baseConnectorLogin Login
baseConnectorLogin.Registry = p.BaseImageRegistry
baseConnectorLogin.Username = p.BaseImageUsername
baseConnectorLogin.Password = p.BaseImagePassword

cmd := commandLogin(baseConnectorLogin)

raw, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Error writing config.json: %s", err)
out := string(raw)
out = strings.Replace(out, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.", "", -1)
fmt.Println(out)
return fmt.Errorf("Error authenticating base connector: exit status 1")
}
}

Expand Down