Skip to content

Commit dfda9b8

Browse files
committed
extraFiles: add basic validation of data fields
1 parent 84b75b6 commit dfda9b8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

jupyterhub/templates/_helpers.tpl

+20
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ true
332332
*/}}
333333
{{- define "jupyterhub.extraFiles.data.withNewLineSuffix" -}}
334334
{{- range $file_key, $file_details := . }}
335+
{{- include "jupyterhub.extraFiles.validate-file" (list $file_key $file_details) }}
335336
{{- if $file_details.binaryData }}
336337
{{- $file_key | quote }}: {{ $file_details.binaryData | trimSuffix "\n" | quote }}{{ println }}
337338
{{- end }}
@@ -348,6 +349,7 @@ true
348349
*/}}
349350
{{- define "jupyterhub.extraFiles.stringData.withNewLineSuffix" -}}
350351
{{- range $file_key, $file_details := . }}
352+
{{- include "jupyterhub.extraFiles.validate-file" (list $file_key $file_details) }}
351353
{{- $file_name := $file_details.name | default $file_key }}
352354
{{- if $file_details.stringData }}
353355
{{- $file_key | quote }}: |
@@ -370,3 +372,21 @@ true
370372
{{- define "jupyterhub.extraFiles.stringData" -}}
371373
{{- include "jupyterhub.extraFiles.stringData.withNewLineSuffix" . | trimSuffix "\n" }}
372374
{{- end }}
375+
376+
{{- define "jupyterhub.extraFiles.validate-file" -}}
377+
{{- $file_key := index . 0 }}
378+
{{- $file_details := index . 1 }}
379+
{{- $field_count := 0 }}
380+
{{- if $file_details.data }}
381+
{{- $field_count = add1 $field_count }}
382+
{{- end }}
383+
{{- if $file_details.stringData }}
384+
{{- $field_count = add1 $field_count }}
385+
{{- end }}
386+
{{- if $file_details.binaryData }}
387+
{{- $field_count = add1 $field_count }}
388+
{{- end }}
389+
{{- if ne $field_count 1 }}
390+
{{- print "\n\nextraFiles entries (" $file_key ") must only contain one of the fields: data, stringData, and binaryData." | fail }}
391+
{{- end }}
392+
{{- end }}

0 commit comments

Comments
 (0)