func toOldClaimConditions()

in lib/ga4gh/identity.go [288:330]


func toOldClaimConditions(conditions Conditions) (map[string]OldClaimCondition, error) {
	// Input is non-empty DNF: outer OR array with inner AND array.
	if len(conditions) > 1 {
		return nil, fmt.Errorf("unsupported visa condition: OR conditions are not supported")
	}
	out := make(map[string]OldClaimCondition)
	for _, cond := range conditions[0] {
		ctyp := string(cond.Type)
		oldCond, ok := out[ctyp]
		if ok {
			// Old format only allows one sub-condition per visa type, and this
			// sub-condition has already been populated, therefore the new
			// condition is not compatible with the old claim format.
			return nil, fmt.Errorf("unsupported visa condition: multiple conditions on the same visa type not supported")
		}
		if !ok {
			oldCond = OldClaimCondition{}
		}
		if len(cond.Value) > 0 {
			parts := strings.SplitN(string(cond.Value), ":", 2)
			if len(parts) != 2 || parts[0] != "const" {
				return nil, fmt.Errorf("unsupported visa condition: non-const condition on %q field", "value")
			}
			oldCond.Value = append(oldCond.Value, parts[1])
		}
		if len(cond.Source) > 0 {
			parts := strings.SplitN(string(cond.Source), ":", 2)
			if len(parts) != 2 || parts[0] != "const" {
				return nil, fmt.Errorf("unsupported visa condition: non-const condition on %q field", "source")
			}
			oldCond.Source = append(oldCond.Source, parts[1])
		}
		if len(cond.By) > 0 {
			parts := strings.SplitN(string(cond.By), ":", 2)
			if len(parts) != 2 || parts[0] != "const" {
				return nil, fmt.Errorf("unsupported visa condition: non-const condition on %q field", "by")
			}
			oldCond.By = append(oldCond.By, parts[1])
		}
		out[ctyp] = oldCond
	}
	return out, nil
}