예제 #1
0
파일: manifest.go 프로젝트: jasonkeene/cli
func (m Manifest) getAppMaps(data generic.Map) ([]generic.Map, error) {
	globalProperties := data.Except([]interface{}{"applications"})

	var apps []generic.Map
	var errs []error
	if data.Has("applications") {
		appMaps, ok := data.Get("applications").([]interface{})
		if !ok {
			return []generic.Map{}, errors.New(T("Expected applications to be a list"))
		}

		for _, appData := range appMaps {
			if !generic.IsMappable(appData) {
				errs = append(errs, fmt.Errorf(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'",
					map[string]interface{}{"YmlSnippet": appData})))
				continue
			}

			appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
			apps = append(apps, appMap)
		}
	} else {
		apps = append(apps, globalProperties)
	}

	if len(errs) > 0 {
		message := ""
		for i := range errs {
			message = message + fmt.Sprintf("%s\n", errs[i].Error())
		}
		return []generic.Map{}, errors.New(message)
	}

	return apps, nil
}
예제 #2
0
파일: manifest.go 프로젝트: jasonkeene/cli
func parseRoutes(input generic.Map, errs *[]error) []models.ManifestRoute {
	if !input.Has("routes") {
		return nil
	}

	genericRoutes, ok := input.Get("routes").([]interface{})
	if !ok {
		*errs = append(*errs, fmt.Errorf(T("'routes' should be a list")))
		return nil
	}

	manifestRoutes := []models.ManifestRoute{}
	for _, genericRoute := range genericRoutes {
		route, ok := genericRoute.(map[interface{}]interface{})
		if !ok {
			*errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property")))
			continue
		}

		if routeVal, exist := route["route"]; exist {
			manifestRoutes = append(manifestRoutes, models.ManifestRoute{
				Route: routeVal.(string),
			})
		} else {
			*errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property")))
		}
	}

	return manifestRoutes
}
예제 #3
0
파일: manifest.go 프로젝트: jasonkeene/cli
func sliceOrNil(yamlMap generic.Map, key string, errs *[]error) []string {
	if !yamlMap.Has(key) {
		return nil
	}

	var err error
	stringSlice := []string{}

	sliceErr := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of strings.", map[string]interface{}{"PropertyName": key}))

	switch input := yamlMap.Get(key).(type) {
	case []interface{}:
		for _, value := range input {
			stringValue, ok := value.(string)
			if !ok {
				err = sliceErr
				break
			}
			stringSlice = append(stringSlice, stringValue)
		}
	default:
		err = sliceErr
	}

	if err != nil {
		*errs = append(*errs, err)
		return []string{}
	}

	return stringSlice
}
예제 #4
0
파일: manifest.go 프로젝트: jasonkeene/cli
func intSliceVal(yamlMap generic.Map, key string, errs *[]error) *[]int {
	if !yamlMap.Has(key) {
		return nil
	}

	err := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of integers.", map[string]interface{}{"PropertyName": key}))

	s, ok := yamlMap.Get(key).([]interface{})

	if !ok {
		*errs = append(*errs, err)
		return nil
	}

	var intSlice []int

	for _, el := range s {
		intValue, ok := el.(int)

		if !ok {
			*errs = append(*errs, err)
			return nil
		}

		intSlice = append(intSlice, intValue)
	}

	return &intSlice
}
예제 #5
0
파일: manifest.go 프로젝트: jasonkeene/cli
func stringValOrDefault(yamlMap generic.Map, key string, errs *[]error) *string {
	if !yamlMap.Has(key) {
		return nil
	}
	empty := ""
	switch val := yamlMap.Get(key).(type) {
	case string:
		if val == "default" {
			return &empty
		}
		return &val
	case nil:
		return &empty
	default:
		*errs = append(*errs, fmt.Errorf(T("{{.PropertyName}} must be a string or null value", map[string]interface{}{"PropertyName": key})))
		return nil
	}
}