func (repo ManifestDiskRepository) readAllYAMLFiles(path string) (mergedMap generic.Map, err error) { file, err := os.Open(filepath.Clean(path)) if err != nil { return } defer file.Close() mapp, err := parseManifest(file) if err != nil { return } if !mapp.Has("inherit") { mergedMap = mapp return } inheritedPath, ok := mapp.Get("inherit").(string) if !ok { err = errors.New("invalid inherit path in manifest") return } if !filepath.IsAbs(inheritedPath) { inheritedPath = filepath.Join(filepath.Dir(path), inheritedPath) } inheritedMap, err := repo.readAllYAMLFiles(inheritedPath) if err != nil { return } mergedMap = generic.DeepMerge(inheritedMap, mapp) return }
func mapToAppSet(basePath string, data generic.Map) (appSet []models.AppParams, errs ManifestErrors) { if data.Has("applications") { appMaps, ok := data.Get("applications").([]interface{}) if !ok { errs = append(errs, errors.New("Expected applications to be a list")) return } // we delete applications so that we may merge top level app params into each app data.Delete("applications") for _, appData := range appMaps { if !generic.IsMappable(appData) { errs = append(errs, errors.New("Expected application to be a dictionary")) continue } appMap := generic.DeepMerge(data, generic.NewMap(appData)) appParams, appErrs := mapToAppParams(basePath, appMap) if !appErrs.Empty() { errs = append(errs, appErrs) continue } appSet = append(appSet, appParams) } } return }
func (m Manifest) getAppMaps(data generic.Map) (apps []generic.Map, errs []error) { globalProperties := data.Except([]interface{}{"applications"}) if data.Has("applications") { appMaps, ok := data.Get("applications").([]interface{}) if !ok { errs = append(errs, errors.New("Expected applications to be a list")) return } for _, appData := range appMaps { if !generic.IsMappable(appData) { errs = append(errs, errors.New(fmt.Sprintf("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'%s'", appData))) continue } appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData)) apps = append(apps, appMap) } } else { apps = append(apps, globalProperties) } return }