mirror of
https://github.com/truenas/charts.git
synced 2026-04-05 11:48:55 +08:00
* Add some validation in webdav * add validation in resources * formatting * Update error message * remove extra `\` * negate logic * bump
41 lines
1.7 KiB
Smarty
41 lines
1.7 KiB
Smarty
{{- define "webdav.validation" -}}
|
|
|
|
{{- $authTypes := (list "none" "basic") -}}
|
|
{{- if not (mustHas .Values.webdavConfig.authType $authTypes) -}}
|
|
{{- fail (printf "WebDAV - Expected [Auth Type] to be one of [%v], but got [%v]" (join ", " $authTypes) .Values.webdavConfig.authType) -}}
|
|
{{- end -}}
|
|
|
|
{{- if eq .Values.webdavConfig.authType "basic" -}}
|
|
{{- if not .Values.webdavConfig.username -}}
|
|
{{- fail "WebDAV - Expected [Username] to be configured when [Auth Type] is set to [Basic Auth]" -}}
|
|
{{- end -}}
|
|
{{- if not .Values.webdavConfig.password -}}
|
|
{{- fail "WebDAV - Expected [Password] to be configured when [Auth Type] is set to [Basic Auth]" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- if and (not .Values.webdavNetwork.http) (not .Values.webdavNetwork.https) -}}
|
|
{{- fail "WebDAV - Expected at least one protocol [HTTP, HTTPS] to be enabled" -}}
|
|
{{- end -}}
|
|
|
|
{{- if and .Values.webdavNetwork.https (not .Values.webdavNetwork.certificateID) -}}
|
|
{{- fail "WebDAV - Expected a certificate to be configured when HTTPS is enabled" -}}
|
|
{{- end -}}
|
|
|
|
{{- if not .Values.webdavStorage.shares -}}
|
|
{{- fail "WebDAV - Expected at least 1 [Share] to be configured" -}}
|
|
{{- end -}}
|
|
|
|
{{- $names := list -}}
|
|
{{- range .Values.webdavStorage.shares -}}
|
|
{{- $names = mustAppend $names .name -}}
|
|
{{- if not (mustRegexMatch "^[a-zA-Z0-9_-]+$" .name) -}}
|
|
{{- fail "WebDAV - Expected [Share] name to only consist of [Letters(a-z, A-Z), Numbers(0-9), Underscores(_), Dashes(-)]" -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- if not (deepEqual $names (uniq $names)) -}}
|
|
{{- fail (printf "WebDAV - Expected Share names to be unique, but got [%v]" (join ", " $names)) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|