apiVersion: v1
kind: Secret
metadata:
  name: {{ template "drone.fullname" . }}
  labels:
    app: {{ template "drone.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
type: Opaque
data:
  {{ if .Values.sharedSecret }}
  secret: "{{ .Values.sharedSecret | b64enc }}"
  {{ else }}
  secret: "{{ randAlphaNum 24 | b64enc }}"
  {{ end }}
---
{{ if not .Values.sourceControl.secret -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "drone.sourceControlSecret" . }}
  labels:
    app: {{ template "drone.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
type: Opaque
data:
  {{if .Values.sourceControl.provider}}
  {{ if eq .Values.sourceControl.provider "github" }}
  {{ .Values.sourceControl.github.clientSecretKey }}: {{ .Values.sourceControl.github.clientSecretValue | b64enc | quote }}
  {{- else if  eq .Values.sourceControl.provider "gitlab" -}}
  {{ .Values.sourceControl.gitlab.clientSecretKey }}: {{ .Values.sourceControl.gitlab.clientSecretValue | b64enc | quote }}
  {{- else if  eq .Values.sourceControl.provider "gitea" -}}
  {{ .Values.sourceControl.gitea.clientSecretKey }}: {{ .Values.sourceControl.gitea.clientSecretValue | b64enc | quote }}
  {{- else if eq .Values.sourceControl.provider "bitbucketCloud" -}}
  {{ .Values.sourceControl.bitbucketCloud.clientSecretKey }}: {{ .Values.sourceControl.bitbucketCloud.clientSecretValue | b64enc | quote }}
  {{ end }}
  {{ end }}
{{- end }}
---
{{- if and (not .Values.licenseKeySecret) .Values.licenseKey -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "drone.licenseKeySecret" }}
  labels:
    app: {{ template "drone.name" }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
type: Opaque
data:
  license-key: {{ .Values.licenseKey | b64enc | quote }}
{{- end }}
