Skip to content

Commit

Permalink
feat: Support basic auth settins in docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Feb 23, 2022
1 parent c52fdf8 commit 63715e0
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions skopeo/skopeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/base64"
"encoding/json"
"fmt"
"os"
Expand Down Expand Up @@ -299,16 +300,35 @@ func (r *Runner) AttemptToLoginToRegistry(
err,
)
}
if authConfig.Username != "" && authConfig.Password != "" {
username := authConfig.Username
password := authConfig.Password

if authConfig.Auth != "" {
c, err := base64.StdEncoding.DecodeString(authConfig.Auth)
if err != nil {
return getLoginStdout, getLoginStderr, fmt.Errorf(
"failed to read credentials from Docker config file: %w",
err,
)
}
cs := string(c)
s := strings.IndexByte(cs, ':')
if s >= 0 {
username = cs[:s]
password = cs[s+1:]
}
}

if username != "" && password != "" {
loginStdout, loginStderr, err := r.run(
ctx,
[]string{
"login",
registryName,
"--username",
authConfig.Username,
username,
"--password",
authConfig.Password,
password,
},
skopeoOpts...,
)
Expand Down

0 comments on commit 63715e0

Please sign in to comment.