{{- if and .Values.global.secret.create .Values.server.secret.create -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "chart.fullname" . }}-server
  labels:
    {{- include "chart.labels" . | nindent 4 }}
type: Opaque
data:
  TIMEBASE_SERIAL: {{ .Values.server.serial | b64enc | quote }}
  {{- if or .Values.server.user .Values.server.password }}
  TIMEBASE_USERNAME: {{ .Values.server.user | b64enc | quote }}
  TIMEBASE_PASSWORD: {{ .Values.server.password | b64enc | quote }}
  {{- end }}
  {{- if or .Values.server.url }}
  TIMEBASE_URL: {{ .Values.server.url | b64enc | quote }}
    {{- else if or .Values.server.user .Values.server.password }}
  TIMEBASE_URL: {{ printf "dxtick://%s:%s@%s:8011" .Values.server.user .Values.server.password (include "chart.fullname" .) | b64enc | quote }}
    {{- else }}
  TIMEBASE_URL: {{ printf "dxtick://%s:8011" (include "chart.fullname" .) | b64enc | quote }}
  {{- end }}

  {{- range $key, $value := .Values.server.secret.records }}
  {{ $key }}: {{ $value | b64enc | quote }}
  {{- end }}
{{- end -}}