|
34 | 34 | {{- $condition_struct := dict "name" $condition.name "root_path" $condition_path "paths" list "keys" list "config" $condition -}} |
35 | 35 |
|
36 | 36 | {{/* Add Condition Keys */}} |
37 | | - {{- $key := (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $.ctx "path" (default "" $condition.key) "required" false))).res }} |
| 37 | + {{- $key := "" -}} |
| 38 | + {{- if $condition.key -}} |
| 39 | + {{- $key = (fromYaml (include "lib.utils.dicts.lookup" (dict "data" $.ctx "path" $condition.key "required" false))).res -}} |
| 40 | + {{- end -}} |
38 | 41 | {{- if and $condition.key (and (not $key) ($condition.required)) -}} |
39 | 42 | {{- include "inventory.helpers.fail" (printf "A Value for %s is required but not set" $condition.key) -}} |
40 | 43 | {{- else if not $key -}} |
|
48 | 51 | {{- $condition_keys = append $condition_keys $key -}} |
49 | 52 | {{- end -}} |
50 | 53 | {{- end -}} |
51 | | - |
52 | | - {{/* Add groups as possible keys */}} |
53 | | - {{- if not $condition.groups_disabled -}} |
54 | | - {{- if $.roles -}} |
55 | | - {{- $condition_keys = concat $.roles $condition_keys -}} |
| 54 | + |
| 55 | + {{/* Validate Type */}} |
| 56 | + {{- if $key -}} |
| 57 | + {{- $type_error := 1 -}} |
| 58 | + {{- if $condition.key_types -}} |
| 59 | + {{- range $condition.key_types -}} |
| 60 | + {{- if (kindIs . $key) -}} |
| 61 | + {{- $type_error = 0 -}} |
| 62 | + {{- end -}} |
| 63 | + {{- end -}} |
| 64 | + {{- else -}} |
| 65 | + {{- $type_error = 0 -}} |
56 | 66 | {{- end -}} |
57 | | - {{- end -}} |
| 67 | + {{- if $type_error -}} |
| 68 | + {{- $_ := set $return "errors" (concat $return.errors (list (dict "condition" $condition.name "error" (printf "Value for condition must be %s but is %s" ($condition.key_types| join ", ") (kindOf $key))))) -}} |
| 69 | + {{- end -}} |
| 70 | + {{- end -}} |
58 | 71 |
|
59 | 72 | {{/* Apply a filter to all results */}} |
60 | 73 | {{- if $condition.filter -}} |
61 | 74 | {{- $filtered_list := $condition_keys -}} |
62 | | - {{- if $condition.reverseFilter -}} |
| 75 | + {{- if $condition.reverse_filter -}} |
63 | 76 | {{- $filtered_list = list -}} |
64 | 77 | {{- end -}} |
65 | 78 | {{- if (kindIs "string" $condition.filter) -}} |
|
69 | 82 | {{- $con := . -}} |
70 | 83 | {{- range $condition.filter -}} |
71 | 84 | {{- if (regexMatch . $con) -}} |
72 | | - {{- if $condition.reverseFilter -}} |
| 85 | + {{- if $condition.reverse_filter -}} |
73 | 86 | {{- $filtered_list = append $filtered_list $con -}} |
74 | 87 | {{- else -}} |
75 | 88 | {{- $filtered_list = without $filtered_list $con -}} |
|
79 | 92 | {{- end -}} |
80 | 93 | {{- $condition_keys = $filtered_list -}} |
81 | 94 | {{- end -}} |
| 95 | + |
| 96 | + {{/* Add Base */}} |
| 97 | + {{- if $condition.allow_root -}} |
| 98 | + {{- $condition_keys = prepend $condition_keys "/" -}} |
| 99 | + {{- end -}} |
| 100 | + |
82 | 101 |
|
83 | 102 | {{/* Create Path for each Condition Key */}} |
84 | 103 | {{- $condition_keys = $condition_keys | uniq -}} |
|
0 commit comments