Exemplo n.º 1
0
func handleAddRemoveChange(mapContent map[string]interface{}, prefix string, key string, prop intf.Argument) error {
	val := mapContent[key]

	// ASSUMPTION: maps and lists are never empty in xld read
	switch t := val.(type) {
	case map[string]string:

		switch prefix {
		case "add", "change":
			for k, v := range prop.Map() {
				t[k] = v
			}
		case "remove":
			for _, el := range prop.Values() {
				delete(t, el)
			}

		}
	case []string:
		switch prefix {
		case "add", "change":
			for _, el := range prop.Values() {
				t = append(t, el)
			}
			mapContent[key] = t
		case "remove":
			newElements := make([]string, 0)
			for _, el := range t {
				found := false
				for _, cmdArg := range prop.Values() {
					if el == cmdArg {
						found = true
					}
				}
				if !found {
					newElements = append(newElements, el)
				}
			}
			mapContent[key] = newElements
		}
	default:
		return errors.New("Unexpected value type read from repository; does it exist?")
	}
	return nil

}
Exemplo n.º 2
0
func handleDefault(mapContent map[string]interface{}, key string, prop intf.Argument, ciType *metadata.CIType) error {
	kind := ciType.Prop(key).Kind

	switch kind {
	case "MAP_STRING_STRING":
		mapContent[key] = prop.Map()
	case "SET_OF_STRING", "LIST_OF_STRING", "SET_OF_CI", "LIST_OF_CI":
		mapContent[key] = prop.Values()
	case "BOOLEAN", "INTEGER", "STRING", "ENUM", "CI":
		mapContent[key] = prop.Value()
	default:
		return errors.New("Unexpected value type read from repository; does it exist?")
	}
	return nil
}
Exemplo n.º 3
0
func translateProp(ciType *metadata.CIType, prop intf.Argument) (result interface{}, err error) {
	key := prop.Name()
	kind := ciType.Prop(key).Kind

	if kind == "" {
		return "error", errors.New("Unknown property type " + ciType.Type + "->" + key)
	}

	switch kind {

	case "BOOLEAN", "INTEGER", "STRING", "ENUM":
		return prop.Value(), nil

	case "CI":
		return mapRef(prop.Value()), nil

	case "MAP_STRING_STRING":
		return mapStringString(prop.Map()), nil

	case "SET_OF_STRING", "LIST_OF_STRING":
		return mapSetOfStrings(prop.Values()), nil

	case "SET_OF_CI", "LIST_OF_CI":
		return mapSetOfCis(prop.Values()), nil

	default:
		return "error", errors.New("Unknown property kind " + kind + " --> XLD server newer than client?")

	}
}