apiVersion: v1
kind: ConfigMap
metadata:
  name: ckan
  annotations:
      description: |-
        Holds both key/value pairs that will be injected as environment variables in the running container
        and the ckan.ini configuration file for ckan

        If in template form (use of $VAR in content), it will be processed on deployment start and the $VARs
        will be changed with values from the equivalent values from the environment
        In this case the keys can be used inside the ckan.ini file.

        If in raw form the content will be used as is

        The switch between template/raw type of processing is done via setting the CKAN_USE_CONF_TEMPLATE variable
         - "true" -> ckan.ini will be processed as template
         - empty or other value("false") -> ckan.ini will be copied and used as is

        Note: This separate config file is similar in structure to the one inside the template.
        It is provided as a convenient way to edit and load the configuration settings herein.
  labels:
    ckan.component: ckan
data:
  CKAN_USE_CONF_TEMPLATE: "true"
  CKAN_DO_DB_INIT: "false"
  CKAN__PLUGINS: "stats text_view image_view recline_view datastore datapusher"
  POSTGRES_HOST: ckan-persist-postgresql.pub-ckan.svc.cluster.local
  REDIS_HOST: ckan-persist-redis.pub-ckan.svc.cluster.local
  REDIS_PORT: '6379'
  REDIS_DB: '1'
  SOLR_HOST: ckan-solr.pub-ckan.svc.cluster.local
  SOLR_PORT: '8983'
  DATAPUSHER_HOST: ckan-datapusher.pub-ckan.svc.cluster.local
  DATAPUSHER_PORT: '8800'
  CKAN_SITE_ID: okd
  CKAN_SITE_URL: http://ckan.apps.oshift-pinfold.intra
  CKAN_STORAGE_PATH: /opt/app-root/storage
  CKAN_MAX_UPLOAD_SIZE_MB: "30"
  CKAN_SMTP_MAIL_FROM: ckan@lab-okd.net
  CKAN_SMTP_PASSWORD: some_password
  CKAN_SMTP_SERVER: smtp.office365.com:587
  CKAN_SMTP_STARTTLS: "True"
  CKAN_SMTP_USER: account@hotmail.com
  CKAN_APP_UUID: 2d5631c6-7e1e-ac65-873b-513d31368343
  CKAN_BEAKER_SECRET: 6my3od66QhPbbacNuLodqdEgR
  ckan.ini: |-
    #
    # CKAN - Pylons configuration
    #
    # These are some of the configuration options available for your CKAN
    # instance. Check the documentation in 'doc/configuration.rst' or at the
    # following URL for a description of what they do and the full list of
    # available options:
    #
    # http://docs.ckan.org/en/latest/maintaining/configuration.html
    #
    # The %(here)s variable will be replaced with the parent directory of this file
    #

    [DEFAULT]

    # WARNING: *THIS SETTING MUST BE SET TO FALSE ON A PRODUCTION ENVIRONMENT*
    debug = false

    [server:main]
    use = egg:Paste#http
    host = 0.0.0.0
    port = 5000

    [app:main]
    use = egg:ckan
    full_stack = true
    cache_dir = /tmp/%(ckan.site_id)s/
    beaker.session.key = ckan

    # This is the secret token that the beaker library uses to hash the cookie sent
    # to the client. `paster make-config` generates a unique value for this each
    # time it generates a config file.
    beaker.session.secret = $CKAN_BEAKER_SECRET

    # `paster make-config` generates a unique value for this each time it generates
    # a config file.
    app_instance_uuid = $CKAN_APP_UUID

    # repoze.who config
    who.config_file = %(here)s/who.ini
    who.log_level = warning
    who.log_file = %(cache_dir)s/who_log.ini
    # Session timeout (user logged out after period of inactivity, in seconds).
    # Inactive by default, so the session doesn't expire.
    # who.timeout = 86400

    ## Database Settings
    sqlalchemy.url = postgresql://$PG_USER:$PG_PASSWORD@$POSTGRES_HOST/$PG_DATABASE

    ckan.datastore.write_url = postgresql://$PG_USER:$PG_PASSWORD@$POSTGRES_HOST/$PG_DATASTORE_DB
    ckan.datastore.read_url = postgresql://$PG_DATASTORE_RO_USER:$PG_DATASTORE_RO_PASS@$POSTGRES_HOST/$PG_DATASTORE_DB

    # PostgreSQL' full-text search parameters
    ckan.datastore.default_fts_lang = english
    ckan.datastore.default_fts_index_method = gist


    ## Site Settings

    ckan.site_url = $CKAN_SITE_URL
    #ckan.use_pylons_response_cleanup_middleware = true

    ## Authorization Settings

    ckan.auth.anon_create_dataset = false
    ckan.auth.create_unowned_dataset = false
    ckan.auth.create_dataset_if_not_in_organization = false
    ckan.auth.user_create_groups = false
    ckan.auth.user_create_organizations = false
    ckan.auth.user_delete_groups = true
    ckan.auth.user_delete_organizations = true
    ckan.auth.create_user_via_api = false
    ckan.auth.create_user_via_web = true
    ckan.auth.roles_that_cascade_to_sub_groups = admin


    ## Search Settings

    ckan.site_id = $CKAN_SITE_ID
    solr_url = http://$SOLR_HOST:$SOLR_PORT/solr/ckan


    ## Redis Settings

    # URL to your Redis instance, including the database to be used.
    ckan.redis.url = redis://$REDIS_HOST:$REDIS_PORT/$REDIS_DB


    ## CORS Settings

    # If cors.origin_allow_all is true, all origins are allowed.
    # If false, the cors.origin_whitelist is used.
    # ckan.cors.origin_allow_all = true
    # cors.origin_whitelist is a space separated list of allowed domains.
    # ckan.cors.origin_whitelist = http://example1.com http://example2.com


    ## Plugins Settings

    # Note: Add ``datastore`` to enable the CKAN DataStore
    #       Add ``datapusher`` to enable DataPusher
    #		Add ``resource_proxy`` to enable resorce proxying and get around the
    #		same origin policy
    ckan.plugins = $CKAN__PLUGINS

    # Define which views should be created by default
    # (plugins must be loaded in ckan.plugins)
    ckan.views.default_views = image_view text_view recline_view

    # Customize which text formats the text_view plugin will show
    #ckan.preview.json_formats = json
    #ckan.preview.xml_formats = xml rdf rdf+xml owl+xml atom rss
    #ckan.preview.text_formats = text plain text/plain

    # Customize which image formats the image_view plugin will show
    #ckan.preview.image_formats = png jpeg jpg gif

    ## Front-End Settings

    # Uncomment following configuration to enable using of Bootstrap 2
    #ckan.base_public_folder = public-bs2
    #ckan.base_templates_folder = templates-bs2

    ckan.site_title = CKAN
    ckan.site_logo = /base/images/ckan-logo.png
    ckan.site_description =
    ckan.favicon = /base/images/ckan.ico
    ckan.gravatar_default = identicon
    ckan.preview.direct = png jpg gif
    ckan.preview.loadable = html htm rdf+xml owl+xml xml n3 n-triples turtle plain atom csv tsv rss txt json
    ckan.display_timezone = server

    # package_hide_extras = for_search_index_only
    #package_edit_return_url = http://another.frontend/dataset/<NAME>
    #package_new_return_url = http://another.frontend/dataset/<NAME>
    #ckan.recaptcha.publickey =
    #ckan.recaptcha.privatekey =
    #licenses_group_url = http://licenses.opendefinition.org/licenses/groups/ckan.json
    # ckan.template_footer_end =


    ## Internationalisation Settings
    ckan.locale_default = en
    ckan.locale_order = en pt_BR ja it cs_CZ ca es fr el sv sr sr@latin no sk fi ru de pl nl bg ko_KR hu sa sl lv
    ckan.locales_offered =
    ckan.locales_filtered_out = en_GB

    ## Feeds Settings

    ckan.feeds.authority_name =
    ckan.feeds.date =
    ckan.feeds.author_name =
    ckan.feeds.author_link =

    ## Storage Settings

    ckan.storage_path = $CKAN_STORAGE_PATH
    ckan.max_resource_size = $CKAN_MAX_UPLOAD_SIZE_MB
    #ckan.max_image_size = 2

    ## Datapusher settings

    # Make sure you have set up the DataStore

    #ckan.datapusher.formats = csv xls xlsx tsv application/csv application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    ckan.datapusher.url = http://$DATAPUSHER_HOST:$DATAPUSHER_PORT
    #ckan.datapusher.assume_task_stale_after = 3600

    # Resource Proxy settings
    # Preview size limit, default: 1MB
    #ckan.resource_proxy.max_file_size = 1048576
    # Size of chunks to read/write.
    #ckan.resource_proxy.chunk_size = 4096

    ## Activity Streams Settings

    #ckan.activity_streams_enabled = true
    #ckan.activity_list_limit = 31
    #ckan.activity_streams_email_notifications = true
    #ckan.email_notifications_since = 2 days
    ckan.hide_activity_from_users = %(ckan.site_id)s


    ## Email settings

    #email_to = errors@example.com
    #error_email_from = ckan-errors@example.com
    smtp.server = $CKAN_SMTP_SERVER
    smtp.starttls = $CKAN_SMTP_STARTTLS
    smtp.user = $CKAN_SMTP_USER
    smtp.password = $CKAN_SMTP_PASSWORD
    smtp.mail_from = $CKAN_SMTP_MAIL_FROM

    ## Logging configuration
    [loggers]
    keys = root, ckan, ckanext

    [handlers]
    keys = console

    [formatters]
    keys = generic

    [logger_root]
    level = WARNING
    handlers = console

    [logger_ckan]
    level = INFO
    handlers = console
    qualname = ckan
    propagate = 0

    [logger_ckanext]
    level = DEBUG
    handlers = console
    qualname = ckanext
    propagate = 0

    [handler_console]
    class = StreamHandler
    args = (sys.stderr,)
    level = NOTSET
    formatter = generic

    [formatter_generic]
    format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s
