func()

in pkg/tftarget/tftarget.go [46:75]


func (g *TFTarget) ToMatcher(constraint *unstructured.Unstructured) (constraints.Matcher, error) {
	match, ok, err := unstructured.NestedMap(constraint.Object, "spec", "match")
	if err != nil {
		return nil, fmt.Errorf("unable to get spec.match: %w", err)
	}
	if !ok {
		return &matcher{addresses: []string{"**"}, excludedAddresses: []string{}}, nil
	}

	include, ok, err := unstructured.NestedStringSlice(match, "addresses")
	if err != nil {
		return nil, fmt.Errorf("unable to get string slice from spec.match.addresses: %w", err)
	}
	if !ok {
		include = []string{"**"}
	}

	exclude, ok, err := unstructured.NestedStringSlice(match, "excludedAddresses")
	if err != nil {
		return nil, fmt.Errorf("unable to get string slice from spec.match.excludedAddresses: %w", err)
	}
	if !ok {
		exclude = []string{}
	}

	return &matcher{
		addresses:         include,
		excludedAddresses: exclude,
	}, nil
}