Skip to content

Commit

Permalink
Allow FLEXMEASURES_PLUGINS to be read as env var and to be a comma-se…
Browse files Browse the repository at this point in the history
…parated string; document wich settings are also read as env vars

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed May 2, 2023
1 parent b47ab70 commit 51f879d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
18 changes: 17 additions & 1 deletion documentation/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Level above which log messages are added to the log file. See the ``logging`` pa

Default: ``logging.WARNING``

.. note:: This setting is also recognized as environment variable.


.. _modes-config:

Expand Down Expand Up @@ -72,6 +74,7 @@ FLEXMEASURES_PLUGINS
^^^^^^^^^^^^^^^^^^^^^^^^^

A list of plugins you want FlexMeasures to load (e.g. for custom views or CLI functions).
This can be a Python list (e.g. ``["plugin1", "plugin2"]``) or a comma-separated string (e.g. ``"plugin1, plugin2"``).

Two types of entries are possible here:

Expand All @@ -80,9 +83,10 @@ Two types of entries are possible here:

Added functionality in plugins needs to be based on Flask Blueprints. See :ref:`plugins` for more information and examples.


Default: ``[]``

.. note:: This setting is also recognized as environment variable.


FLEXMEASURES_DB_BACKUP_PATH
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -299,6 +303,8 @@ Token for accessing the MapBox API (for displaying maps on the dashboard and ass

Default: ``None``

.. note:: This setting is also recognized as environment variable.

.. _sentry_access_token:

SENTRY_SDN
Expand All @@ -309,6 +315,8 @@ E.g.: ``https://<examplePublicKey>@o<something>.ingest.sentry.io/<project-Id>``

Default: ``None``

.. note:: This setting is also recognized as environment variable.


SQLAlchemy
----------
Expand All @@ -323,6 +331,9 @@ Connection string to the postgres database, format: ``postgresql://<user>:<passw

Default: ``None``

.. note:: This setting is also recognized as environment variable.


SQLALCHEMY_ENGINE_OPTIONS
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -432,6 +443,8 @@ For FlexMeasures to be able to send email to users (e.g. for resetting passwords
This is only a selection of the most important settings.
See `the Flask-Mail Docs <https://flask-mail.readthedocs.io/en/latest/#configuring-flask-mail>`_ for others.

.. note:: The mail settings are also recognized as environment variables.

MAIL_SERVER (*)
^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -543,6 +556,9 @@ Redis

FlexMeasures uses the Redis database to support our forecasting and scheduling job queues.

.. note:: The redis settings are also recognized as environment variables.


FLEXMEASURES_REDIS_URL (*)
^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Config(object):
# This setting contains the domain on which FlexMeasures runs
# and the first month when the domain was under the current owner's administration
FLEXMEASURES_HOSTS_AND_AUTH_START: dict = {"flexmeasures.io": "2021-01"}
FLEXMEASURES_PLUGINS: List[str] = []
FLEXMEASURES_PLUGINS: Union[List[str], str] = [] # str will be checked for commas
FLEXMEASURES_PROFILE_REQUESTS: bool = False
FLEXMEASURES_DB_BACKUP_PATH: str = "migrations/dumps"
FLEXMEASURES_MENU_LOGO_PATH: str = ""
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def read_env_vars(app: Flask):
for var in (
required
+ list(warnable.keys())
+ ["LOGGING_LEVEL", "MAPBOX_ACCESS_TOKEN", "SENTRY_SDN"]
+ ["LOGGING_LEVEL", "MAPBOX_ACCESS_TOKEN", "SENTRY_SDN", "FLEXMEASURES_PLUGINS"]
):
app.config[var] = os.getenv(var, app.config.get(var, None))
# DEBUG in env can come in as a string ("True") so make sure we don't trip here
Expand Down
2 changes: 2 additions & 0 deletions flexmeasures/utils/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def register_plugins(app: Flask):
(last part of the path).
"""
plugins = app.config.get("FLEXMEASURES_PLUGINS", [])
if isinstance(plugins, str):
plugins = [plugin.strip() for plugin in plugins.split(",")]
if not isinstance(plugins, list):
app.logger.error(
f"The value of FLEXMEASURES_PLUGINS is not a list: {plugins}. Cannot install plugins ..."
Expand Down

0 comments on commit 51f879d

Please sign in to comment.