{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.development }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "chainloop.dex.fullname" . }}-config
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: dex
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
stringData:
  config.yaml: |
    issuer: http://{{ include "chainloop.dex" . }}:{{ .Values.dex.containerPorts.http }}/dex

    storage:
      type: memory

    web:
      http: 0.0.0.0:{{ .Values.dex.containerPorts.http }}

    staticClients:
      - id: chainloop-dev
        name: "Chainloop Dev"
        secret: ZXhhbXBsZS1hcHAtc2VjcmV0
        redirectURIs:
          - "http://0.0.0.0:8000/auth/callback"
          - "http://localhost:8000/auth/callback"
          {{ $controlPlaneUrl := include "chainloop.controlplane.external_url" . }}
          {{- if not (eq $controlPlaneUrl "null") -}}
          - "{{ $controlPlaneUrl }}/auth/callback"
          {{- end -}}

    # required to enable static passwords
    enablePasswordDB: true

    staticPasswords: {{- include "common.tplvalues.render" ( dict "value" .Values.dex.staticUsers "context" $ ) | nindent 6 }}
{{- end }}
