# Configuration
We are using dynaconf for configuration management and the default config on github or embedded below..:
/data/opa/default-settings.yaml
default:
MODE: "prod"
PROJECT_NAME: "opa-stack"
PROJECT_DESCRIPTION: ""
PROJECT_VERSION: "0.1.0"
# Urls to automatic documentation. Set to null to disable
DOCS_URL: "/docs"
REDOC_URL: "/redoc"
OPENAPI_URL: "/openapi.json" # Can only be null if DOCS_URL and REDOC_URL is also null
OPENAPI_PREFIX: ""
PLUGIN_PATHS: []
PLUGIN_WHITELIST_LIST: []
PLUGIN_WHITELIST_RE: ""
PLUGIN_WHITELIST_TAGS: []
PLUGIN_BLACKLIST_LIST: []
PLUGIN_BLACKLIST_RE: ""
PLUGIN_BLACKLIST_TAGS: []
# CORS
ALLOW_ORIGINS: ["*"]
ALLOW_CREDENTIALS: true
ALLOW_METHODS: ["*"]
ALLOW_HEADERS: ["*"]
SECRET_KEY: ""
# Configuration for optional components..
# They all have a helper-file in ../utils/{component_name.lower()}.py, so check
# in them if you wonder how these values are used. They are also listed in the docs
# @ https://opa-stack.github.io/guide/components.html
#
# The LOAD option is always present, and can be one of auto|yes|no, all defaulting to 'auto'.
# * auto: Makes opa-stack look for the component using a simple dns-check or other simple checks
# Ie.. Check if we "should" be able to use this component.
# It will then try to connect as if you had written "yes", ie, it fails if it is not able to..
# * yes: Makes the coponent required
# * no: Makes it not check at all.
OPTIONAL_COMPONENTS:
MONGODB:
LOAD: "auto"
DRIVER: "mongodb-async-motor"
OPTS:
URL: "mongodb://mongo:mongo@mongo:27017/opa"
WALRUS:
LOAD: "auto"
DRIVER: "redis-walrus"
OPTS:
URL: "redis://redis"
AIOREDIS:
LOAD: "auto"
DRIVER: "redis-aioredis"
OPTS:
URL: "redis://redis"
CELERY:
LOAD: "auto"
DRIVER: "celery"
OPTS:
BACKEND_URL: "redis://redis/1"
BROKER_URL: "pyamqp://guest@rabbitmq//"
# Used different places, currently:
# * Setting FastAPI/Starlette debug-mode (https://www.starlette.io/applications/)
DEBUG: false
# Turns on better exceptions, ie, prettier, and with some more info (like variables)
BETTER_EXCEPTIONS: false
# Python Tools for Visual Studio debug server, running on port 5678
PTVSD: false
# External js files are loaded from the internet as default
SELF_HOSTED: false
dev:
MODE: "dev"
PTVSD: true
BETTER_EXCEPTIONS: true
BETTER_EXCEPTIONS_MAX_LENGTH: 1000
PLUGIN_PATHS:
- "/data/opa/demo-plugins"
- dynaconf_merge
WARNING
The configuration is documenented in this file. All possible configuration is in it, so that is the reference.. Each configuration is not documented on this page.
Dynaconf have a lot of ways to set configuration using files and/or environment-variables. They have very good documentation, so take a look at their page for tips if you need anything special.
The settings we use for dynaconf is:
ENV_SWITCHER_FOR_DYNACONF
: IsENV
, meaning you use the environment variableENV
to set the environment if you want to use those.ENVVAR_PREFIX_FOR_DYNACONF
: IsOPA
. So every setting you want to override using environment variable needs to be prefixed withOPA_
ROOT_PATH_FOR_DYNACONF
: Is/data/settings
, which is the folder you need to put all your settings in if not overwritten by environment variables.INCLUDES_FOR_DYNACONF
: Is['/data/opa/default-settings.yaml', '*.yaml', '*.json', '*.py', '*.ini', '*.toml']
. So those are the settings loaded in that order.
Configurig opa-stack can therefor be done in a bunch of ways, see some examples below
# Environment
Settings are put into environments. So if you want to bundle up your project with all different configuration, and an easy way to switch between the configs. Environments is for you..
See the examples below and you will see how you can have specific config only active in a specific environment.
You can set the environment using the ENV
environment variable to whichever environment you want. Note that the default variables is still set, but they can be overridden by the environments configuration.
# Special environments
# dev
If you set dev
as the ENV
, you will get:
- A webserver that reloads on file-changes
- PTVSD enabled (Python Tools for Visual Studio debug server)
- better exceptions
/data/opa/demo-plugins
(github code) enabled
TIP
Take a look at the development guide for more info about how to leverage what dev-mode enables.
# Examples
# Using a file mounted
If you mount files into the directory /data/settings
, you can have your settings in 1 or more files with .yaml
, .json
, .py
, .ini
, or .toml
extension. Example with a simple .yaml
file
default:
PROJECT_NAME: "opa-stack"
# Using environment variables
Prepend your environment-variable with OPA_
, example setting OPA_PROJECT_NAME=opa-stack
# File with different environments
Mounting in a yaml-file like this
default:
PLUGIN_PATHS:
- "/data/defaultplugins"
both:
PLUGIN_PATHS:
- "/data/specialplugins"
- dynaconf_merge
secret:
PLUGIN_PATHS:
- "/data/specialplugins"
will default set the plugin-path to /data/defaultplugins
. However, if you set the environment variable ENV
to both
, it will load plugins from both /data/defaultplugins
and /data/specialplugins
(the special item dynaconf_merge
merges instead of overwriting).
Setting ENV
to secret
will only load plugins from /data/specialplugins