###
# PGWUI_Server configuration
#
# Configuration changes require a (PGWUI) server restart!
#   yamllint /etc/pgwui.yaml
#   systemctl restart pgwui_server
#
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

app:

  #
  # PasteDeploy configuration
  #

  # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/paste.html#pastedeploy-entry-points
  use: 'egg:pgwui_server'

  #
  # PGWUI configuration
  #

  pgwui:
    # Postgres connection configuration.

    # Both pgwui.pg_host and pgwui.pg_port are optional;
    # they default to the Unix PG socket and the default Postgres port.
    # An empty string for host means use the unix socket.
    pg_host: ''
    pg_port: '5432'

    # The database to use by default.
    # Not having the setting is the same as "", the empty string.
    #
    # Babase altered, but actually not.  Let's just leave it blank.
    #default_db: 'babase'

    # The (PostgreSQL-named) encoding used for strings on the client-side.
    # The list of PostgreSQL encodings can be found at:
    # https://www.postgresql.org/docs/current/multibyte.html#MULTIBYTE-CHARSET-SUPPORTED
    # This setting defaults to "auto", the special PostgreSQL value which
    # sets the client_encoding based on the encoding of the client
    # system's locale.
    # Set this value to "", the empty string, to use the server's encoding
    # as the client encoding.  (client_encoding: '') (or just omit the
    # declaration)
    #client_encoding: 'auto'


    # How to link to the site's home page.  Useful when the home page is
    # not the PGWUI menu.
    #
    # This setting is a mapping (a dict).  The keys depend on the "type"
    # used.
    #
    #   type:
    #     URL    An URL.  This is the default.
    #     file   A file containing HTML, read from the file system.
    #     asset  A Pyramid asset specification.  Results in an URL
    #            which references a file which is part of a PGWUI
    #            component, or some other "static" file included in a Pyramid
    #            application.
    #     route  A Pyramid route name.  Results in an URL
    #            which references a page generated by a Pyramid application.
    #            "route_prefix" is not applied.
    #
    #
    #   When "type" is "URL", there are the following keys:
    #
    #   source:  (required)
    #
    #       The default is ``/``, when there is no home_page setting.
    #       Which produces an URL with no "path".
    #
    #       * A URI path beginning with ``/``.  E.g.: '/home'
    #
    #       * An URL without a protocol, so an URL beginning with ``//`` and
    #       followed by a domain.  E.g.: //www.example.com  The URL
    #       delivered to the browser contains the protocol used in the request.
    #
    #       * An URL with a protocol.  E.g.: https://www.example.com
    #
    #
    #  When "type" is "file", there are the following keys
    #
    #  source: (required)
    #       A fully-qualified file system path, so a path beginning with
    #       a ``/``.  E.g.  /var/www/html/index.html
    #       Served with a content encoding of ``text/html``.
    #
    #  url_path: (required)
    #      The "path" component of the URL used to retrieve the file.
    #      Must begin with a ``/``.  "route_prefix" is not applied.
    #
    #  When type is "asset", there are the following keys:
    #
    #  source: (required)
    #
    #      * A `Pyramid`_ `asset specification`_.  It must reference a
    #      `static asset`_, a file included in a `Pyramid`_ application.
    #      A file containing a page of HTML.
    #
    #
    #  When type is "route", there are the following keys:
    #
    #  source: (required)
    #
    #      * A `Pyramid`_ `route name`_.  Used to reach a page generated
    #      by a `Pyramid`_ application which uses `URL dispatch`_.
    #
    #
    # This is the default:
    #home_page:
    #  type: 'URL'
    #  source: '/'
    # Babase altered
    home_page:
      type: 'URL'
      source: '/babasewiki/ProgramLinks'

    # How to link to a menu of PGWUI components.  An alternative to using
    # the PGWUI_Menu component.
    # Configured as pgwui.home_page is configured, above.
    # The default is to have no menu.
    #
    # The following example uses the URL without a path (e.g.,
    # http://www.example.com/) as the menu page:
    #
    #       menu_page:
    #         type: 'URL'
    #         source: '/'
    #
    # The "menu_page" mapping overrides what is provided by the
    # PGWUI_Menu component.

    # Whether to auto-discover the pgwui component modules. (boolean, optional)
    # When false pgwui component names must be listed in
    # pyramid.includes: ...
    #autoconfigure: true

    # What PGWUI components and other pyramid modules to use.
    # (Required when pgwui.autoconfigure is false, or you want the
    # debug toolbar.)
    # sample that includes the PGUI logout and upload components,
    # in the block-style list format rather than the inline
    # list format as appears in the Pyramid configuration section, below:
    #pyramid.includes
    #  - 'pgwui_logout'
    #  - 'pgwui_upload'

    # Whether or not to change the db content.  (boolean, required)
    dry_run: false

    # routing

    # Routes are what call up specific pages.  They are usually the
    # part of the URL which comes after the http://example.com.
    #
    # All routes should probably begin with a "/" character but
    # if they do not a "/" will be automatically prepended.
    #
    # A full URL may be given as a route.  The is useful for redirecting
    # to other sites.
    #
    # For more information on route syntax see:
    # https://docs.pylonsproject.org/projects/pyramid/en/master/narr/urldispatch.html#route-pattern-syntax

    # A prefix for all routes.  (optional)  If the prefix is "/a/b/c" then
    # all URLs will begin with something like: http://example.com/a/b/c
    # The default is no prefix.
    #route_prefix: ''
    # Babase altered
    route_prefix: '/programs'

    # Overriding routes of specific PGWUI components

    # The syntax is name: "route", one per line.  The "name" is the
    # name of the PGWUI component.  "route" is the route to use to access
    # the component.  So to access the logout page at
    # http://example.com/logmeout the line would be:
    # pgwui_logout: '/logmeout'
    #
    # Overriding routes is optional.
    #
    # The default for some PGWUI components are:
    #routes:
    #  pgwui_copy: '/copy'
    #  pgwui_logout: '/logout'
    #  pgwui_upload: '/upload'

    # Overriding assets
    #
    # The visual presentation of a PGWUI component is controlled by its assets.
    # Overriding assets allows for extensive customization of presentation.
    #
    # A Pyramid asset is any file included in a Pyramid application that is
    # not a Python source code file.  So assets are image files, Mako template
    # files used to render pages, CSS files, JavaScript files, etc.
    #
    # See:
    # https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/assets.html
    #
    # By default no assets are overridden.  Override assets with:
    #
    # override_assets:
    #   asset: 'new'
    #
    # 'asset' is the asset to override, a Pyramid asset specification
    #
    # 'new' is the new value either a Pyramid asset specification
    #       or a file system path
    #
    # Example, altering the menu presented by PGWUI_Menu:
    #
    #     override_assets:
    #       'pgwui_menu:templates/menu.mak': '/tmp/mymenu.mak'

    # Settings validation

    # Whether or not to validate the Beaker session.secret
    # setting.  (boolean, optional)
    # session.secret must be valid to detect Cross-Site Request Forgery (CSRF)
    # vulnerabilties.  Validation is on by default.
    #validate_hmac: true


    # PGWUI Component Settings

    # Menu presentation

    # The PGWUI_Menu component automaticaly constructs a menu for the
    # PGWUI components in use.  The display value of the menu items can
    # be overridden using a "menu_label" setting for each component.
    # CAUTION: Do not uncomment the below, instead change the component's
    # "menu_label" setting.  E.g.:
    #pgwui_upload:
    #  menu_label: 'upload -- Upload File Into Database'

    # The order of the menu items can be manually specified based
    # PGWUI component name.  Omitted components come last.
    #pgwui_menu:
    #  order:
    #    - 'pgwui_upload'
    #    - 'pgwui_logout'

    # pgwui_upload

    # The default pgwui_upload settings are:
    #pgwui_upload:
    #  literal_column_headings: 'no-never'
    #  menu_label: 'upload -- Upload File Into Database'
    #  trim: 'choice-yes'
    #  null: 'choice-yes'
    #  file_format: 'csv'
    #
    # literal_column_headings
    # Take uploaded column headings literally?
    # The available choices are:
    #   yes-always    The file's column headings, as typed, are the table's
    #                 column names.
    #   choice-yes    Present a checkbox, default to "yes".
    #   choice-no     Present a checkbox, default to "no".
    #   no-never      The file's column headings are given to PostgreSQL as-is,
    #                 and so PostgreSQL normalizes them to lower case.
    # Optional setting.  The default is "no-never".
    #
    # Caution: Non-ASCII column names, particularly in the Turkish locale,
    # are not guaranteed to be case-insensitive.
    #
    # trim
    # Whether or not to remove leading and trailing whitespace from each
    # uploaded data element.  (From each "cell", each column of each row.)
    #
    # The available choices are:
    #   yes-always    Always trim.
    #   choice-yes    Present a checkbox, default to "yes, trim". (default)
    #   choice-no     Present a checkbox, default to "no, don't trim".
    #   no-never      Never trim.
    #
    # null
    # Whether or not some uploaded data elements should be inserted as NULL
    # values.
    #
    # The available choices are:
    #   yes-always    Always transform some data into NULL.
    #   choice-yes    Present a checkbox, default to "yes".
    #   choice-no     Present a checkbox, default to "no".
    #   no-never      Never transform data into NULL.
    #
    # file_format
    # The format of the uploaded file
    #
    # The available choices are:
    #   csv           The CSV format.
    #   tab           Tab separated values.
    pgwui_upload:
      file_format: "tab"

    # pgwui_bulk_upload

    # pgwui_bulk_upload:
    #   literal_column_headings: 'no-never'
    #   menu_label: 'bulk_upload -- Upload Many Files Into PostgreSQL'
    #   map_file: 'contents.yml'
    #   trim: 'choice-yes'
    #   null: 'choice-yes'
    #   file_format: 'csv'
    #
    # literal_column_headings: 'no-never'
    #   Take uploaded column headings literally?
    #   See pgwui_upload above for details.
    #
    # map_file
    #   Name of the file in the zip file that maps file names to table
    #   names.  The default name of the map file is `contents.yml`.
    #
    #   The map file is in YAML syntax, which for purposes of this document
    #   can be thought of as a superset of JSON.  It must contain a top-level
    #   tag, `map_list`, which itself contains a list of maps, each of which
    #   maps a file to a table or view.  The table (or view) names may,
    #   optionally, be schema qualified.  An example map file might be:
    #
    #   # This file is contents.yml
    #   map_list:
    #     # Load the foo.csv file into the foo_table table of the
    #     # default schema.
    #     - file_map:
    #         file: foo.csv
    #         relation: foo_table
    #     # Load the bar.csv file into the bar_view uploadable-view
    #     # of the default schema.
    #     - file_map:
    #         file: bar.csv
    #         relation: bar_view
    #     # Load the baz.csv file into the baz_table table of the meta schema.
    #     - file_map:
    #         file: baz.csv
    #         relation: meta.baz_table
    #         trim: false
    #
    #   The files within each directory are uploaded in the order in which
    #   they are listed in the map file.  The directories in the zip file are
    #   processed in alphabetical order.
    #
    #   The "trim:" key in the file_map map controls whether or not whitespace
    #   is removed from data values.  "trim:" takes a boolean value.  It
    #   defaults to true.  It overrides other choices in the GUI interface.
    #
    #   Top level tags, other than the `map_list` tag, are ignored.
    #
    #   It is recommended to enclose file names which contain spaces, or begin
    #   with a digit, in single quotes.  But any YAML syntax is valid.
    #
    # trim: 'choice-yes'
    #   Remove leading and trailing whitespace.
    #   See pgwui_upload above for details.
    #
    # null: 'choice-yes'
    #   Insert NULL values.
    #   See pgwui_upload above for details.
    #
    # file_format: 'csv'
    #   The format of the uploaded files.
    #   See pgwui_upload above for details.
    pgwui_bulk_upload:
      file_format: 'tab'


    # pgwui_copy

    # pgwui_copy:
    #   menu_label: 'copy -- Copy a Schema Between Databases'
    #
    #   default_source_db:  (See description)
    #     The default for the database from which data is copied.
    #     The default is the value of "default_db" in the "pgwui" mapping.
    #
    #   sensitive_dbs:   (See description)
    #     A list of databases for which an extra
    #     confirmation step is required before alteration.  Comparisons
    #     are done in a case-insensitive fashion.  The default is the
    #     value of pgwui.default_db.  The setting ""
    #     means that no database requires additional confirmation
    #     before alteration.  Example:
    #           sensitive_dbs:
    #             - 'scratchdb'
    #             - 'scritchdb'
    #
    #   default_target_db: ''
    #     The default for the database to which data is copied.  (Optional)
    #
    #   default_schema: ''
    #     The default for the name of the schema which is copied.  (Optional)
    #
    #   bin: '/usr/bin'
    #     Absolute path to the directory containing the pg_dump and pg_restore
    #     binaries.  (Optional)
    pgwui_copy:
      sensitive_dbs:
        - 'babase'
        - 'babase_pending'
        - 'babase_history'
      default_target_db: 'babase_test'
      default_schema: 'babase'


  #
  # Pyramid configuration
  #

  # Pyramid's configuration does not use mappings.  Instead it prefaces
  # all of its setting names with "pyramid.".
  pyramid.reload_templates: false
  pyramid.debug_authorization: false
  pyramid.debug_notfound: false
  pyramid.debug_routematch: false
  pyramid.default_locale_name: 'en'
  pyramid.includes: []

  #
  # Beaker session management configuration
  # https://beaker.readthedocs.io/en/latest/configuration.html
  #

  # Beaker's configuration does not use mappings.  Instead it prefaces
  # all of its setting names with "session.".
  session.type: 'memory'
  session.lock_dir: '/var/lock/pgwui_server'
  # Remove cookie in browser on browser close. (boolean)
  session.cookie_expires: true
  session.key: 'pgwui_server'
  # HMAC secret
  # (This should be set by you.)
  #session.secret: 'xxxxxxrandomstring40characterslongxxxxxx'
  session.secret: 'xxxxxxrandomstring40characterslongxxxxxx'

  # Send cookie only over https. (boolean)
  # WARNING: To use HTTP, not HTTPS, "session.secure" must be false!
  # This is the default, as the WSGI application is often
  # expected to be run behind a reverse proxy, which does HTTPS to the client.
  # CAUTION: If you are forcing the browser to use HTTPS you want
  #          "session.secure" to be true.
  session.secure: false
  # Sessions timeout after an hour if unused.
  session.timeout: 3600
  # Pyramid sends cookies for exception pages (boolean)
  session.cookie_on_exception: true


  #
  # Mako templates
  #
  # Fail when a variable reference is undefined. (The Mako default) (boolean)
  #mako.strict_undefined: true


###
# wsgi server configuration
###

server:
  # Use waitress as the webserver, configuring the host and port, and
  # configure a reverse-proxy to the network.
  #
  # An Nginx (https://www.nginx.org) reverse-proxy configuration might
  # look like:
  #
  #     location / {
  #         proxy_pass       http://localhost:6543;
  #         proxy_set_header Host      $host;
  #         proxy_set_header X-Real-IP $remote_addr;
  #     }
  #
  use: egg:waitress#main
  # (Because the "use:" invokes waitress, these are waitress configuration
  # directives.)
  # A value for "host" of 0.0.0.0 or "*", instead of "127.0.0.1", exposes the
  # application to the network.  Unless you trust everyone and every
  # device that might access your network this will, at minimum, expose
  # what could be highly sensitive information.  See the documentation
  # for more secure alternatives.
  host: 127.0.0.1
  port: 6543
  # (A unix socket requires systemd tweaks.)
  #unix_socket: '/var/run/pgwui_server.socket'
  #unix_socket_perms: '660'

  # Connections can sit idle for a day before being killed
  # This gives the server 5 days (in seconds) to respond
  channel_timeout: 432000

  # How many concurrent users? (some may be long-running)
  # (This should probably be set to match what apache does.)
  threads: 20

  # Largest http body (upload size), 1GB
  #max_request_body_size: '1073741824'

  # When using a standalone WSGI server like uwsgi or Apache's mod_wsgi
  # use the pgwui_server's WSGI.
  #use: egg:pgwui_server#main

###
# The DEFAULT section
#
# Paste-deploy passes the content of this mapping to all applications.
#
# Assuming the usual Pyramid coding idiom of def main(global_config,
# **settings): is used in your __init__.py. The global_config variable
# is then a dict containing the content of the config file's top-level
# DEFAULT key, if any.
###

#DEFAULT:
#  an_example_mapping: {example_key: example_value}

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
#
# Configures logging via both syslog(3) and stdout, the latter being
# suitable for a systemd service.
#
# See also:
# https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
###
logging:
  version: 1
  disable_existing_loggers: false
  root:
    # Root logger
    level: INFO
    handlers:
      # - console
      - syslog
  loggers:
    # These next mappings don't do anything as given.  Because they have no
    # handler they emit no messages.  They are an example showing logging
    # customized per pgwui component.  You may want to add
    #   propagate: false
    # keys to avoid duplicate logging if you customize them to
    # emit log messages.
    pgwui_server:
      level: INFO
      handlers: []
      qualname: pgwui_server
    pgwui_upload:
      level: INFO
      handlers: []
      qualname: pgwui_upload
  formatters:
    console:
      format: '%(asctime)s [%(levelname)s]: %(name)s - %(message)s'
  handlers:
    # "console" logs to journalctl (which then seems to log to syslog),
    # when a systemd unit is used to start pserve.
    console:
      class: logging.StreamHandler
      level: INFO
      stream: ext://sys.stdout
      formatter: console
    # "syslog" logs to syslog (which then seems to log to journalctl).
    # This seems to provide "hilighting" based on priority level in a way
    # the console handler does not.
    syslog:
      class: logging.handlers.SysLogHandler
      level: INFO
      address: /dev/log
      formatter: console
      facility: user
