Skip to content

Backend Configuration

Petr Stehlík edited this page Nov 13, 2017 · 8 revisions

Liberouter API provides several options to change before running the API. Default configuration can be found in config-default.ini.

If you want to change any of the values provided below create your own .ini file and pass it to the backend using --config argument or place valid config.ini file in backend/ folder.

The biggest priority has the config passed by the argument, then the backend/config.ini and finally the config-default.ini.

The available options with description are:

  • API ([api])
    • debug (default: false) enable debug mode for Flask and Liberouter API
    • host (default: localhost) specify on which host to run (if you want to bind to public interface use 0.0.0.0
    • port (default: 5555) specify port on which to run
    • threaded (default: true) if enabled each request is processed in its own thread
    • version (default: 1.0) used for URL API versioning
    • modules (default: /modules) path to modules folder
    • ssl (default: false) use SSL for connections (rather use webserver-enabled SSL)
    • pam (default: false) enable Linux PAM for authorization
    • cors (default: false) enable Cross-Origin Resource Sharing
    • session_timeout (default: 900) how long a session will be valid in seconds
    • session_max_per_user (default: 10) limit number of sessions created by a single unique user
  • Database ([database])
    • provider (default: sqlite, values : sqlite|mongodb) choose DB provider
    • users (default: users) users table/collection name
    • configuration (default: configuration) configuration table/collection name
  • MongoDB ([mongodb])
    • server (default: localhost) address of MongoDB server
    • port (default: 27017) port of MongoDB server
    • database (default: liberouter) database name
    • user username for secured access
    • password password for secured access
  • SQLite ([sqlite])
    • file path to file where to store database
  • SSL ([ssl])
    • key path to keyfile
    • certificate path to certificate file

Backend Module Configuration

Your backend scripts can use *.ini files and Liberouter GUI provides you with API to do it. *.ini files look like this:

[section-name]
key=value
key=value ; use semicolon for comments

Liberouter API provides you with ConfigParser instance. If you need advanced features see official documentation

API Support

Let's say you have a config.ini placed in the same folder as your __init__.py. You need to do following things in your __init__.py:

from liberouterapi import config

config.load(path = __path__[0] + '/config.ini')

config is a global object which you can use to load and read your data.

Reading Data

Once your config is loaded into the global object, you can use the following syntax to read data from it:

# If 'key' is not found, config returns 'default-value'
value = config['section-name'].get('key', 'default-value')

# You can also use dynamic type cast
value = config['section-name'].getboolean('single_machine', True)

Internally, config object uses configparser. You might want to read the docs for more details, but the most important things to know are that fallback values are optional and you have methods get, getboolean, getint and getfloat at your disposal for reading data.