{{- define "imagePullSecret" }}

{{- if eq "_json_key" .Values.imageRegistry.username -}}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageRegistry.server (printf "%s:%s" .Values.imageRegistry.username (printf "%s" .Values.imageRegistry.password | b64dec) | b64enc) | b64enc }}
{{- else -}}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageRegistry.server (printf "%s:%s" .Values.imageRegistry.username .Values.imageRegistry.password | b64enc) | b64enc }}
{{- end -}}

{{- end }}

{{- define "serverImage" }}

{{- if hasKey .Values "serverImage" -}}
{{- printf .Values.serverImage }}
{{- else -}}
{{- printf "ftrack-server:%s" .Chart.AppVersion }}
{{- end -}}

{{- end }}

{{- define "database.host" }}
{{- if contains ":" .Values.database.host -}}
[{{ .Values.database.host }}]
{{- else -}}
{{ .Values.database.host }}
{{- end -}}
{{- end }}