_utils.tpl 601 B

12345678910111213141516171819
  1. {{/*
  2. Checks if a list of keys are present in a dictionary
  3. */}}
  4. {{- define "common.schema.validateKeys" -}}
  5. {{- $values := . -}}
  6. {{- if and (hasKey $values "values") (hasKey $values "checkKeys") -}}
  7. {{- $missingKeys := list -}}
  8. {{- range $values.checkKeys -}}
  9. {{- if eq (hasKey $values.values . ) false -}}
  10. {{- $missingKeys = mustAppend $missingKeys . -}}
  11. {{- end -}}
  12. {{- end -}}
  13. {{- if $missingKeys -}}
  14. {{- fail (printf "Missing %s from dictionary" ($missingKeys | join ", ")) -}}
  15. {{- end -}}
  16. {{- else -}}
  17. {{- fail "A dictionary and list of keys to check must be provided" -}}
  18. {{- end -}}
  19. {{- end -}}