kind: ConfigMap
apiVersion: v1
metadata:
  name: omero-web-config
data:

  # Override https://github.com/ome/omero-web-docker/blob/master/standalone/01-default-webapps.omero
  01-default-webapps.omero: |
    config append -- omero.web.middleware '{"index": 0, "class": "whitenoise.middleware.WhiteNoiseMiddleware"}'

    config append -- omero.web.apps '"omero_iviewer"'
    config set -- omero.web.viewer.view omero_iviewer.views.index
    config append -- omero.web.open_with '["omero_iviewer", "omero_iviewer_index", {"supported_objects":["images", "dataset", "well"], "script_url": "omero_iviewer/openwith.js", "label": "OMERO.iviewer"}]'

    config append -- omero.web.apps '"omero_parade"'
    config append -- omero.web.ui.center_plugins '["Parade", "omero_parade/init.js.html", "omero_parade"]'

  web.omero: |
    config append -- omero.web.django_additional_settings '["LOGGING", {"version": 1, "disable_existing_loggers": false, "formatters": {"standard": {"format": "%(asctime)s %(levelname)5.5s [%(name)40.40s] (proc.%(process)5.5d) %(funcName)s():%(lineno)d %(message)s"}}, "handlers": {"console": {"level": "DEBUG", "class": "logging.StreamHandler", "formatter": "standard"}}, "loggers": {"": {"handlers": ["console"], "level": "DEBUG", "propagate": true}}}]'
    config set -- omero.web.secure true
    config set -- omero.web.server_list '{{ .Values.serverList | toJson }}'

    config set -- omero.web.prefix {{ .Values.prefix | trimSuffix "/" }}
    config set -- omero.web.static_url {{ .Values.prefix | trimSuffix "/" }}/static

    {{- if .Values.redis.enabled }}
    config set -- omero.web.session_engine django.contrib.sessions.backends.cache
    config set -- omero.web.caches '{ "default": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": "redis://:{{ .Values.redis.password }}@{{ .Release.Name }}-redis-master:6379/0" } }'

    {{- end }}

    {{- range $key, $value := .Values.config.set }}
    config set -- {{ $key }} {{ $value }}
    {{- end }}

    {{- range $keyvalues := .Values.config.append }}
    {{- range $key, $value := $keyvalues }}
    config append -- {{ $key }} {{ $value }}
    {{- end }}
    {{- end }}

    {{- range $keyvalues := .Values.config.appendJson }}
    {{- range $key, $value := $keyvalues }}
    config append -- {{ $key }} '{{ $value | toJson }}'
    {{- end }}
    {{- end }}
