Skip to content

Commit

Permalink
Support for pulling maps from XDG config dir
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <josh@dolit.ski>
  • Loading branch information
jdolitsky committed Jul 29, 2021
1 parent a5cad1a commit 538d875
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/docker-credential-magic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"path/filepath"
"strings"

"github.com/adrg/xdg"
"gopkg.in/yaml.v2"

"github.com/docker-credential-magic/docker-credential-magic/pkg/types"
)


const (
anonymousTokenResponse = "{\"Username\":\"\",\"Secret\":\"\"}"
)
Expand Down Expand Up @@ -104,15 +104,19 @@ func parseDomain(s string) (string, error) {
}

func getHelperExecutable(domain string) (string, error) {
var mappingRootDirAbsPath string
mappingRootDir := os.Getenv("DOCKER_CREDENTIAL_MAGIC_CONFIG")
if mappingRootDir == "" {
// TODO: allow read from XDG
return "", mappingRootDirNotFound
mappingRootDir = filepath.Join(xdg.ConfigHome, "magic", "etc")
}
mappingRootDirAbsPath, err := filepath.Abs(mappingRootDir)
if err != nil {
return "", mappingRootDirNotFound
}
info, err := os.Stat(mappingRootDirAbsPath)
if err != nil || !info.IsDir() {
return "", fmt.Errorf("mappings directory does not exist: %s", mappingRootDirAbsPath)
}
filepaths, err := ioutil.ReadDir(mappingRootDirAbsPath)
if err != nil {
return "", mappingRootDirNotFound
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.16
replace github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d

require (
github.com/adrg/xdg v0.3.3
github.com/docker/distribution v2.7.1+incompatible
github.com/google/go-containerregistry v0.5.1
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/OJnIp5u0s1SbQ8dVfLCZJsnvazdBP5hS4iRs=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/adrg/xdg v0.3.3 h1:s/tV7MdqQnzB1nKY8aqHvAMD+uCiuEDzVB5HLRY849U=
github.com/adrg/xdg v0.3.3/go.mod h1:61xAR2VZcggl2St4O9ohF5qCKe08+JDmE4VNzPFQvOQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down

0 comments on commit 538d875

Please sign in to comment.