mirror of
https://github.com/truenas/charts.git
synced 2026-11-26 15:26:05 +00:00
Add method to validate if values has required keys
This commit is contained in:
1 parent
399f867f26
commit
4a895d6b63
1 file changed
+19
@@ -0,0 +1,19 @@
|
|||||||
|
{{/*
|
||||||
|
Checks if a list of keys are present in a dictionary
|
||||||
|
*/}}
|
||||||
|
{{- define "common.validateKeys" -}}
|
||||||
|
{{- $values := . -}}
|
||||||
|
{{- if and (hasKey $values "values") (hasKey $values "checkKeys") -}}
|
||||||
|
{{- $missingKeys := list -}}
|
||||||
|
{{- range $values.checkKeys -}}
|
||||||
|
{{- if eq (hasKey $values.values . ) false -}}
|
||||||
|
{{- $missingKeys = mustAppend $missingKeys . -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $missingKeys -}}
|
||||||
|
{{- fail (printf "Missing %s from dictionary" ($missingKeys | join ", ")) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- fail "A dictionary and list of keys to check must be provided" -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
Reference in new issue
Block a user