Skip to content

Commit

Permalink
return empty auth config if no config.json found
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Oct 29, 2024
1 parent 1b83250 commit 31ecf0f
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -35,13 +36,16 @@ func loadDockerAuth() (RegistryAuthConfig, error) {
}

file, err := os.ReadFile(configFilePath)
if err != nil {
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error reading Docker config file")
if errors.Is(err, os.ErrNotExist) {
// If the auth config doesn't exist, return an empty auth config
return RegistryAuthConfig{}, nil
} else if err != nil {
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error reading Docker config file at '%s'", configFilePath)
}

var authConfig RegistryAuthConfig
if err := json.Unmarshal(file, &authConfig); err != nil {
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error unmarshalling Docker config file")
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error unmarshalling Docker config file at '%s'", configFilePath)
}

return authConfig, nil
Expand Down

0 comments on commit 31ecf0f

Please sign in to comment.