diff --git a/pkg/skaffold/docker/auth.go b/pkg/skaffold/docker/auth.go index 83972ece76f..898a4ea96e9 100644 --- a/pkg/skaffold/docker/auth.go +++ b/pkg/skaffold/docker/auth.go @@ -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" @@ -64,7 +63,7 @@ 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") } @@ -72,7 +71,7 @@ func (credsHelper) GetAuthConfig(registry string) (types.AuthConfig, error) { } 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") } @@ -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 -} diff --git a/pkg/skaffold/docker/auth_test.go b/pkg/skaffold/docker/auth_test.go index e881b0f2161..67b1c27f0e9 100644 --- a/pkg/skaffold/docker/auth_test.go +++ b/pkg/skaffold/docker/auth_test.go @@ -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