func newConfigFile(auths map[string]types.AuthConfig) *cliconfig.ConfigFile { tmp, _ := ioutil.TempFile("", "docker-test") name := tmp.Name() tmp.Close() c := cliconfig.NewConfigFile(name) c.AuthConfigs = auths return c }
func setupTempConfigFile() (*cliconfig.ConfigFile, error) { root, err := ioutil.TempDir("", "docker-test-auth") if err != nil { return nil, err } root = filepath.Join(root, cliconfig.CONFIGFILE) configFile := cliconfig.NewConfigFile(root) for _, registry := range []string{"testIndex", INDEXSERVER} { configFile.AuthConfigs[registry] = cliconfig.AuthConfig{ Username: "******", Password: "******", Email: "*****@*****.**", } } return configFile, nil }
func CompatLoad() (*CompatConfigFile, error) { dockerCfg := cliconfig.NewConfigFile(filepath.Join(cliconfig.ConfigDir(), cliconfig.ConfigFileName)) configFile := CompatConfigFile{ dockerCfg, dockerCfg.Filename(), } // Try .docker/config.json first if _, err := os.Stat(configFile.filename); err == nil { file, err := os.Open(configFile.filename) if err != nil { return &configFile, err } defer file.Close() err = configFile.LoadFromReader(file) return &configFile, err } else if !os.IsNotExist(err) { return &configFile, err } // Try the old .dockercfg homeDir, _ := homedir.Dir() configFile.filename = filepath.Join(homeDir, ".dockercfg") if _, err := os.Stat(configFile.filename); err != nil { return &configFile, nil //missing file is not an error } file, err := os.Open(configFile.filename) if err != nil { return &configFile, err } defer file.Close() err = configFile.LegacyLoadFromReader(file) if err != nil { return &configFile, err } return &configFile, nil }