_validation.tpl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{- define "ddns.validation" -}}
  2. {{- include "ddns.validatePublicIpProviders" (dict "text" "Public IP DNS Providers"
  3. "list" .Values.ddnsConfig.publicIpDnsProviders
  4. "valid" (list "all" "cloudflare" "opendns")) -}}
  5. {{- include "ddns.validatePublicIpProviders" (dict "text" "Public IP HTTP Providers"
  6. "list" .Values.ddnsConfig.publicIpHttpProviders
  7. "valid" (list "all" "custom" "opendns" "ifconfig" "ipinfo" "ddnss")) -}}
  8. {{- include "ddns.validatePublicIpProviders" (dict "text" "Public IPv4 HTTP Providers"
  9. "list" .Values.ddnsConfig.publicIpv4HttpProviders
  10. "valid" (list "all" "custom" "ipify" "noip")) -}}
  11. {{- include "ddns.validatePublicIpProviders" (dict "text" "Public IPv6 HTTP Providers"
  12. "list" .Values.ddnsConfig.publicIpv6HttpProviders
  13. "valid" (list "all" "custom" "ipify" "noip")) -}}
  14. {{- include "ddns.validatePublicIpProviders" (dict "text" "Public IP Fetchers"
  15. "list" .Values.ddnsConfig.publicIpFetchers
  16. "valid" (list "all" "http" "dns")) -}}
  17. {{- end -}}
  18. {{- define "ddns.validatePublicIpProviders" -}}
  19. {{- $text := .text -}}
  20. {{- $list := .list -}}
  21. {{- $valid := .valid -}}
  22. {{- $type := .type -}}
  23. {{- if not $list -}}
  24. {{- fail (printf "DDNS Updater - Expected non-empty [%v]" $text) -}}
  25. {{- end -}}
  26. {{- $userProviders := list -}}
  27. {{- range $list -}}
  28. {{- if mustHas .provider $userProviders -}}
  29. {{- fail (printf "DDNS Updater - Expected unique values in [%v], but got [%v] more than once" $text .provider) -}}
  30. {{- end -}}
  31. {{- $userProviders = mustAppend $userProviders .provider -}}
  32. {{- if not (mustHas .provider $valid) -}}
  33. {{- fail (printf "DDNS Updater - [%v] valid values are [%v], but got [%v]" $text (join ", " $valid) .provider) -}}
  34. {{- end -}}
  35. {{- if eq .provider "all" -}}
  36. {{- if ne (len $list) 1 -}}
  37. {{- fail (printf "DDNS Updater - [%v] cannot contain other values when [all] is selected" $text) -}}
  38. {{- end -}}
  39. {{- end -}}
  40. {{- if eq .provider "custom" -}}
  41. {{- if not .custom -}}
  42. {{- fail (printf "DDNS Updater - [%v] expected non-empty [Custom Value]" $text) -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{- end -}}
  46. {{- end -}}