apiVersion: v1
kind: ConfigMap
metadata:
  name: "{{ template "harbor.registry" . }}"
  labels:
{{ include "harbor.labels" . | indent 4 }}
data:
  config.yml: |+
    version: 0.1
    log:
      level: {{ .Values.logLevel }}
      fields:
        service: registry
    storage:
      {{- $storage := .Values.persistence.imageChartStorage }}
      {{- $type := $storage.type }}
      {{- if eq $type "filesystem" }}
      filesystem:
        rootdirectory: {{ $storage.filesystem.rootdirectory }}
        {{- if $storage.filesystem.maxthreads }}
        maxthreads: {{ $storage.filesystem.maxthreads }}
        {{- end }}
      {{- else if eq $type "azure" }}
      azure:
        accountname: {{ $storage.azure.accountname }}
        container: {{ $storage.azure.container }}
        {{- if $storage.azure.realm }}
        realm: {{ $storage.azure.realm }}
        {{- end }}
      {{- else if eq $type "gcs" }}
      gcs:
        bucket: {{ $storage.gcs.bucket }}
        keyfile: /etc/registry/gcs-key.json
        {{- if $storage.gcs.rootdirectory }}
        rootdirectory: {{ $storage.gcs.rootdirectory }}
        {{- end }}
        {{- if $storage.gcs.chunksize }}
        chunksize: {{ $storage.gcs.chunksize }}
        {{- end }}
      {{- else if eq $type "s3" }}
      s3:
        region: {{ $storage.s3.region }}
        bucket: {{ $storage.s3.bucket }}
        {{- if $storage.s3.regionendpoint }}
        regionendpoint: {{ $storage.s3.regionendpoint }}
        {{- end }}
        {{- if $storage.s3.encrypt }}
        encrypt: {{ $storage.s3.encrypt }}
        {{- end }}
        {{- if $storage.s3.secure }}
        secure: {{ $storage.s3.secure }}
        {{- end }}
        {{- if $storage.s3.v4auth }}
        v4auth: {{ $storage.s3.v4auth }}
        {{- end }}
        {{- if $storage.s3.chunksize }}
        chunksize: {{ $storage.s3.chunksize }}
        {{- end }}
        {{- if $storage.s3.rootdirectory }}
        rootdirectory: {{ $storage.s3.rootdirectory }}
        {{- end }}
        {{- if $storage.s3.storageclass }}
        storageclass: {{ $storage.s3.storageclass }}
        {{- end }}
      {{- else if eq $type "swift" }}
      swift:
        authurl: {{ $storage.swift.authurl }}
        username: {{ $storage.swift.username }}
        container: {{ $storage.swift.container }}
        {{- if $storage.swift.region }}
        region: {{ $storage.swift.region }}
        {{- end }}
        {{- if $storage.swift.tenant }}
        tenant: {{ $storage.swift.tenant }}
        {{- end }}
        {{- if $storage.swift.tenantid }}
        tenantid: {{ $storage.swift.tenantid }}
        {{- end }}
        {{- if $storage.swift.domain }}
        domain: {{ $storage.swift.domain }}
        {{- end }}
        {{- if $storage.swift.domainid }}
        domainid: {{ $storage.swift.domainid }}
        {{- end }}
        {{- if $storage.swift.trustid }}
        trustid: {{ $storage.swift.trustid }}
        {{- end }}
        {{- if $storage.swift.insecureskipverify }}
        insecureskipverify: {{ $storage.swift.insecureskipverify }}
        {{- end }}
        {{- if $storage.swift.chunksize }}
        chunksize: {{ $storage.swift.chunksize }}
        {{- end }}
        {{- if $storage.swift.prefix }}
        prefix: {{ $storage.swift.prefix }}
        {{- end }}
        {{- if $storage.swift.authversion }}
        authversion: {{ $storage.swift.authversion }}
        {{- end }}
        {{- if $storage.swift.endpointtype }}
        endpointtype: {{ $storage.swift.endpointtype }}
        {{- end }}
        {{- if $storage.swift.tempurlcontainerkey }}
        tempurlcontainerkey: {{ $storage.swift.tempurlcontainerkey }}
        {{- end }}
        {{- if $storage.swift.tempurlmethods }}
        tempurlmethods: {{ $storage.swift.tempurlmethods }}
        {{- end }}
      {{- else if eq $type "oss" }}
      oss:
        accesskeyid: {{ $storage.oss.accesskeyid }}
        region: {{ $storage.oss.region }}
        bucket: {{ $storage.oss.bucket }}
        {{- if $storage.oss.endpoint }}
        endpoint: {{ $storage.oss.endpoint }}
        {{- end }}
        {{- if $storage.oss.internal }}
        internal: {{ $storage.oss.internal }}
        {{- end }}
        {{- if $storage.oss.encrypt }}
        encrypt: {{ $storage.oss.encrypt }}
        {{- end }}
        {{- if $storage.oss.secure }}
        secure: {{ $storage.oss.secure }}
        {{- end }}
        {{- if $storage.oss.chunksize }}
        chunksize: {{ $storage.oss.chunksize }}
        {{- end }}
        {{- if $storage.oss.rootdirectory }}
        rootdirectory: {{ $storage.oss.rootdirectory }}
        {{- end }}
      {{- end }}
      cache:
        layerinfo: redis
      maintenance:
        uploadpurging:
          enabled: false
      delete:
        enabled: true
      redirect:
        disable: {{ $storage.disableredirect }}
    redis:
      addr: "{{ template "harbor.redis.host" . }}:{{ template "harbor.redis.port" . }}"
      db: {{ template "harbor.redis.registryDatabaseIndex" . }}
    http:
      relativeurls: {{ .Values.registry.relativeurls }}
      addr: :5000
      # set via environment variable
      # secret: placeholder
      debug:
        addr: localhost:5001
    auth:
      token:
        issuer: harbor-token-issuer
        realm: "{{ template "harbor.externalURL" . }}/service/token"
        rootcertbundle: /etc/registry/root.crt
        service: harbor-registry
    validation:
      disabled: true
    notifications:
      endpoints:
        - name: harbor
          disabled: false
          url: http://{{ template "harbor.core" . }}/service/notifications
          timeout: 3000ms
          threshold: 5
          backoff: 1s
    {{- if .Values.registry.middleware.enabled }}
    {{- $middleware := .Values.registry.middleware }}
    {{- $middlewareType := $middleware.type }}
    {{- if eq $middlewareType "cloudFront" }}
    middleware:
      storage:
        - name: cloudfront
          options:
            baseurl: {{ $middleware.cloudFront.baseurl }}
            privatekey: /etc/registry/pk.pem
            keypairid: {{ $middleware.cloudFront.keypairid }}
            duration: {{ $middleware.cloudFront.duration }}
            ipfilteredby: {{ $middleware.cloudFront.ipfilteredby }}
    {{- end }}
    {{- end }}
  ctl-config.yml: |+
    ---
    protocol: "http"
    port: 8080
    log_level: {{ .Values.logLevel }}
