docker/lookaside.go
func loadAndMergeConfig(dirPath string) (*registryConfiguration, error) {
	mergedConfig := registryConfiguration{Docker: map[string]registryNamespace{}}
	dockerDefaultMergedFrom := ""
	nsMergedFrom := map[string]string{}

	dir, err := os.Open(dirPath)
	if err != nil {
		if os.IsNotExist(err) {
			return &mergedConfig, nil
		}
		return nil, err
	}
	configNames, err := dir.Readdirnames(0)
	if err != nil {
		return nil, err
	}
	for _, configName := range configNames {
		if !strings.HasSuffix(configName, ".yaml") {
			continue
		}
		configPath := filepath.Join(dirPath, configName)
		configBytes, err := ioutil.ReadFile(configPath)
		if err != nil {
			return nil, err
		}

		var config registryConfiguration
		err = yaml.Unmarshal(configBytes, &config)
		if err != nil {
			return nil, errors.Wrapf(err, "Error parsing %s", configPath)
		}

		if config.DefaultDocker != nil {
			if mergedConfig.DefaultDocker != nil {
				return nil, errors.Errorf(`Error parsing signature storage configuration: "default-docker" defined both in "%s" and "%s"`,
					dockerDefaultMergedFrom, configPath)
			}
			mergedConfig.DefaultDocker = config.DefaultDocker
			dockerDefaultMergedFrom = configPath
		}

		for nsName, nsConfig := range config.Docker { // includes config.Docker == nil
			if _, ok := mergedConfig.Docker[nsName]; ok {
				return nil, errors.Errorf(`Error parsing signature storage configuration: "docker" namespace "%s" defined both in "%s" and "%s"`,
					nsName, nsMergedFrom[nsName], configPath)
			}
			mergedConfig.Docker[nsName] = nsConfig
			nsMergedFrom[nsName] = configPath
		}
	}

	return &mergedConfig, nil
}
func loadAndMergeConfig(dirPath string) (*registryConfiguration, error) {
	mergedConfig := registryConfiguration{Docker: map[string]registryNamespace{}}
	dockerDefaultMergedFrom := ""
	nsMergedFrom := map[string]string{}

	dir, err := os.Open(dirPath)
	if err != nil {
		if os.IsNotExist(err) {
			return &mergedConfig, nil
		}
		return nil, err
	}
	configNames, err := dir.Readdirnames(0)
	if err != nil {
		return nil, err
	}
	for _, configName := range configNames {
		if !strings.HasSuffix(configName, ".yaml") {
			continue
		}
		configPath := filepath.Join(dirPath, configName)
		configBytes, err := ioutil.ReadFile(configPath)
		if err != nil {
			return nil, err
		}

		var config registryConfiguration
		err = yaml.Unmarshal(configBytes, &config)
		if err != nil {
			return nil, errors.Wrapf(err, "Error parsing %s", configPath)
		}

		if config.DefaultDocker != nil {
			if mergedConfig.DefaultDocker != nil {
				return nil, errors.Errorf(`Error parsing signature storage configuration: "default-docker" defined both in "%s" and "%s"`,
					dockerDefaultMergedFrom, configPath)
			}
			mergedConfig.DefaultDocker = config.DefaultDocker
			dockerDefaultMergedFrom = configPath
		}

		for nsName, nsConfig := range config.Docker { // includes config.Docker == nil
			if _, ok := mergedConfig.Docker[nsName]; ok {
				return nil, errors.Errorf(`Error parsing signature storage configuration: "docker" namespace "%s" defined both in "%s" and "%s"`,
					nsName, nsMergedFrom[nsName], configPath)
			}
			mergedConfig.Docker[nsName] = nsConfig
			nsMergedFrom[nsName] = configPath
		}
	}

	return &mergedConfig, nil
}
func loadAndMergeConfig ( dirPath string ) ( * registryConfiguration , error ) { mergedConfig := registryConfiguration { Docker : map [ string ] registryNamespace { } } dockerDefaultMergedFrom := " " nsMergedFrom := map [ string ] string { } dir , err := os . Open ( dirPath ) if err != nil { if os . IsNotExist ( err ) { return & mergedConfig , nil } return nil , err } configNames , err := dir . Readdirnames ( 0 ) if err != nil { return nil , err } for _ , configName := range configNames { if ! strings . HasSuffix ( configName , " " ) { continue } configPath := filepath . Join ( dirPath , configName ) configBytes , err := ioutil . ReadFile ( configPath ) if err != nil { return nil , err } var config registryConfiguration err = yaml . Unmarshal ( configBytes , & config ) if err != nil { return nil , errors . Wrapf ( err , " " , configPath ) } if config . DefaultDocker != nil { if mergedConfig . DefaultDocker != nil { return nil , errors . Errorf ( `Error parsing signature storage configuration: "default-docker" defined both in "%s" and "%s"` , dockerDefaultMergedFrom , configPath ) } mergedConfig . DefaultDocker = config . DefaultDocker dockerDefaultMergedFrom = configPath } for nsName , nsConfig := range config . Docker { // includes config.Docker == nil if _ , ok := mergedConfig . Docker [ nsName ] ; ok { return nil , errors . Errorf ( `Error parsing signature storage configuration: "docker" namespace "%s" defined both in "%s" and "%s"` , nsName , nsMergedFrom [ nsName ] , configPath ) } mergedConfig . Docker [ nsName ] = nsConfig nsMergedFrom [ nsName ] = configPath } } return & mergedConfig , nil }
// loadAndMergeConfig loads configuration files in dirPath
loadAndMergeConfig loads configuration files in dirPath