Skip to content

Commit

Permalink
Merge pull request #454 from dgageot/read-config
Browse files Browse the repository at this point in the history
Use docker CLI code to read the config
  • Loading branch information
r2d4 authored Apr 27, 2018
2 parents 2d08841 + ce6bdb7 commit 2ed4b03
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 68 deletions.
19 changes: 2 additions & 17 deletions pkg/skaffold/docker/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"path/filepath"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -64,15 +63,15 @@ type credsHelper struct {
}

func (credsHelper) GetAuthConfig(registry string) (types.AuthConfig, error) {
cf, err := load()
cf, err := config.Load(configDir)
if err != nil {
return types.AuthConfig{}, errors.Wrap(err, "docker config")
}
return cf.GetAuthConfig(registry)
}

func (credsHelper) GetAllAuthConfigs() (map[string]types.AuthConfig, error) {
cf, err := load()
cf, err := config.Load(configDir)
if err != nil {
return nil, errors.Wrap(err, "docker config")
}
Expand Down Expand Up @@ -126,17 +125,3 @@ func officialRegistry(ctx context.Context, cli DockerAPIClient) string {

return serverAddress
}

func load() (*configfile.ConfigFile, error) {
filename := filepath.Join(configDir, config.ConfigFileName)
f, err := util.Fs.Open(filename)
if err != nil {
return nil, errors.Wrap(err, "opening docker config")
}
defer f.Close()
cf := configfile.New("")
if err := cf.LoadFromReader(f); err != nil {
return nil, errors.Wrap(err, "loading docker config file")
}
return cf, nil
}
51 changes: 0 additions & 51 deletions pkg/skaffold/docker/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,12 @@ package docker
import (
"context"
"fmt"
"io/ioutil"
"path/filepath"
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
"github.com/docker/cli/cli/config"
"github.com/docker/docker/api/types"
)

const dockerCfg = `{
"auths": {
"https://appengine.gcr.io": {},
"https://asia.gcr.io": {},
"https://b.gcr.io": {},
"https://beta.gcr.io": {},
"https://bucket.gcr.io": {},
"https://eu.gcr.io": {},
"https://gcr.io": {},
"https://gcr.kubernetes.io": {},
"https://us.gcr.io": {}
},
"credsStore": "gcr",
"credHelpers": {
"appengine.gcr.io": "gcr",
"asia.gcr.io": "gcr",
"eu.gcr.io": "gcr",
"gcr.io": "gcr",
"gcr.kubernetes.io": "gcr",
"us.gcr.io": "gcr"
}
}`

func TestLoad(t *testing.T) {
tempDir, cleanup := testutil.TempDir(t)
defer cleanup()

defer func(d string) { configDir = d }(configDir)
configDir = tempDir

ioutil.WriteFile(filepath.Join(configDir, config.ConfigFileName), []byte(dockerCfg), 0650)

_, err := load()
if err != nil {
t.Errorf("Couldn't load docker config: %s", err)
}
}

func TestLoadNotARealPath(t *testing.T) {
defer func(d string) { configDir = d }(configDir)
configDir = "not a real path"

cf, err := load()
if err == nil {
t.Errorf("Expected error loading from bad path, but got none: %+v", cf)
}
}

type testAuthHelper struct {
getAuthConfigErr error
getAllAuthConfigsErr error
Expand Down

0 comments on commit 2ed4b03

Please sign in to comment.