# HG changeset patch # User Goffi # Date 1605455995 -3600 # Node ID c3dac1e11341a0f0395438bd4e02ee5a289041f3 # Parent 45ebeea1bacdee12a6e716c226e9ed7c7e98e12a 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 diff -r 45ebeea1bacd -r c3dac1e11341 twisted/plugins/libervia_server.py --- 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