Mercurial > libervia-web
changeset 1363:c3dac1e11341
server: options can now be specified with environment variables:
environment variable are named `LIBERVIA_` + the option name in uppercase.
For instance, `LIBERVIA_PASSPHRASE` can be used to set the passphrase of service profile.
Variable are set in this order of priority (lowest to highest priority):
- `sat.conf` settings
- environment variables
- arguments specified at command line
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 15 Nov 2020 16:59:55 +0100 |
parents | 45ebeea1bacd |
children | df40708c4c76 |
files | twisted/plugins/libervia_server.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/twisted/plugins/libervia_server.py Sat Nov 14 22:27:49 2020 +0100 +++ b/twisted/plugins/libervia_server.py Sun Nov 15 16:59:55 2020 +0100 @@ -99,6 +99,8 @@ DATA_DIR_DEFAULT = '' +# prefix used for environment variables +ENV_PREFIX = "LIBERVIA_" # options which are in sat.conf and on command line, # see https://twistedmatrix.com/documents/current/api/twisted.python.usage.Options.html OPT_PARAMETERS_BOTH = [['connection_type', 't', 'https', _("'http', 'https' or 'both' " @@ -129,7 +131,7 @@ ['base_url_ext', '', '', _('The external URL to use as base URL').encode('utf-8'), coerceUnicode], - ['dev_mode', 'D', False, _('Developer mode, automatically reload' + ['dev_mode', 'D', False, _('Developer mode, automatically reload ' 'modified pages').encode('utf-8'), coerceBool], ] # Options which are in sat.conf only @@ -184,10 +186,12 @@ self.handleDeprecated(config_parser) for param in self.optParameters + OPT_PARAMETERS_CFG: name = param[0] + env_name = f"{ENV_PREFIX}{name.upper()}" try: - value = config.getConfig(config_parser, C.CONFIG_SECTION, name, Exception) - # if isinstance(value, str): - # value = value.encode("utf-8") + value = os.getenv(env_name) + if value is None: + value = config.getConfig( + config_parser, C.CONFIG_SECTION, name, Exception) try: param[2] = param[4](value) except IndexError: # the coerce method is optional