sources:
  {{- with .Values.config.objectStorage.data }}
  {{- $type := ( .type | lower ) }}
  - type: {{ $type }}
    name: name # TODO
    kwargs:
    {{- if eq $type "swift" }}
      username: {{ .username }}
      password: {{ .password }}
      tenant_name: {{ .tenant_name }}
      tenant_id: {{ .tenant_id }}
      region_name: {{ .region_name }}
      auth_url: {{ .auth_url }}
      auth_version: {{ .auth_version }}
      user_domain_name: {{ .user_domain_name }}
    {{- else if eq $type "s3" }}
      bucket_name: {{ .bucket | default "null" }}
      endpoint_url: {{ .endpoint_url }}
      access_key_id: {{ .access_key_id }}
      secret_access_key: {{ .secret_access_key }}
      validate_bucket_name: {{ if hasKey . "validate_bucket_name" }}{{ .validate_bucket_name }}{{ else }}true{{ end }}
      # TODO: 'client_kwargs'
      # region: {{ .region }}
    {{- end }}
    {{- end }}

schemes:
  {{- range .Values.config.registrar.schemes | default list }}
  - {{ toYaml . }}
  {{- end }}

backends:
  - type: eoxserver
    filter:
    kwargs:
      instance_base_path: /var/www/pvs/dev
      instance_name: pvs_instance
      mapping:
        {{- if .Values.config.registrar.mapping }}
        {{- toYaml .Values.config.registrar.mapping | nindent 10}}
        {{- else }}
        {{- $product_levels := list }}
        {{- range $product_type_name, $product_type := .Values.config.products.types }}
        {{- range $_, $collection_def := $.Values.config.collections }}
        {{- if has $product_type_name $collection_def.product_types }}
        {{ $product_levels = concat $product_levels ( get $collection_def "product_levels" | default list ) }}
        {{- end }}
        {{- end }}
        {{ $product_type_name }}:
          {{- range $level := $product_levels | uniq }}
          {{ $level }}:
            product_type_name: {{ $product_type_name | quote }}
            collections:
              {{- range $collection_name, $collection_conf := $.Values.config.collections }}
              {{- if and (has $product_type_name $collection_conf.product_types) (has $level $collection_conf.product_levels) }}
              - {{ $collection_name }}
              {{- end }}
              {{- end }}
            coverages:
              {{- toYaml $product_type.coverages | nindent 16 }}
            browses:
              {{- if hasKey $product_type "default_browse_locator" }}
              {{ $product_type.default_browse_locator }}: null
              {{- end }}
              {{- range $browse_name, $browse_config := $product_type.browses }}
              {{- if hasKey $browse_config "locator" }}
              {{ $browse_config.locator }}: {{ $browse_name }}
              {{- end }}
              {{- end }}
            masks:
              {{- range $mask_name, $_ := $product_type.masks }}
              {{ $mask_name }}: {{ $mask_name }}
              {{- end }}
          {{- end }}
        {{- end }}
        {{- end }}
  {{- range .Values.config.registrar.backends | default list }}
  -{{ toYaml . | nindent 6 }}
  {{- end }}
