forked from Github-Mirrors/canaille
fix: do not automatically load .env files
This commit is contained in:
parent
57bb0e01bc
commit
21464e952a
9 changed files with 521 additions and 515 deletions
|
@ -12,6 +12,7 @@ Added
|
|||
Changed
|
||||
^^^^^^^
|
||||
- PostgreSQL and MySQL extras does not rely on libraries that need to be compiled.
|
||||
- ``.env`` files are not loaded by default. The ``ENV_FILE`` env var must be passed so ``.env`` files are loaded.
|
||||
|
||||
[0.0.56] - 2024-11-07
|
||||
---------------------
|
||||
|
|
|
@ -80,9 +80,7 @@ def setup_flask_converters(app):
|
|||
app.url_map.converters[model_name.lower()] = model_converter(model_class)
|
||||
|
||||
|
||||
def create_app(
|
||||
config=None, validate=True, backend=None, env_file=".env", env_prefix=""
|
||||
):
|
||||
def create_app(config=None, validate=True, backend=None, env_file=None, env_prefix=""):
|
||||
from .app.configuration import setup_config
|
||||
from .app.features import setup_features
|
||||
from .app.i18n import setup_i18n
|
||||
|
|
|
@ -75,7 +75,7 @@ class RootSettings(BaseSettings):
|
|||
"""
|
||||
|
||||
|
||||
def settings_factory(config, env_file=".env", env_prefix=""):
|
||||
def settings_factory(config, env_file=None, env_prefix=""):
|
||||
"""Pushes the backend specific configuration into CoreSettings, in the
|
||||
purpose break dependency against backends libraries like python-ldap or
|
||||
sqlalchemy."""
|
||||
|
@ -138,7 +138,7 @@ def toml_content(file_path):
|
|||
) from exc
|
||||
|
||||
|
||||
def setup_config(app, config=None, test_config=True, env_file=".env", env_prefix=""):
|
||||
def setup_config(app, config=None, test_config=True, env_file=None, env_prefix=""):
|
||||
from canaille.oidc.installation import install
|
||||
|
||||
app.config.from_mapping(
|
||||
|
@ -151,6 +151,7 @@ def setup_config(app, config=None, test_config=True, env_file=".env", env_prefix
|
|||
if not config and "CONFIG" in os.environ:
|
||||
config = toml_content(os.environ.get("CONFIG"))
|
||||
|
||||
env_file = env_file or os.getenv("ENV_FILE")
|
||||
try:
|
||||
config_obj = settings_factory(
|
||||
config or {}, env_file=env_file, env_prefix=env_prefix
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
slapd: env BIN=$BIN:/usr/bin:/usr/sbin python ldap-server.py
|
||||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 CONFIG=conf/canaille-ldap.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-ldap.toml --extra-files "$CANAILLE__THEME"
|
||||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 ENV_FILE=../.env CONFIG=conf/canaille-ldap.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-ldap.toml --extra-files "$CANAILLE__THEME"
|
||||
client1: env FLASK_DEBUG=1 CONFIG=../conf/client1.cfg FLASK_APP=client flask run --port=5001
|
||||
client2: env FLASK_DEBUG=1 CONFIG=../conf/client2.cfg FLASK_APP=client flask run --port=5002
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 CONFIG=conf/canaille-memory.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-memory.toml --extra-files "$CANAILLE__THEME"
|
||||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 ENV_FILE=../.env CONFIG=conf/canaille-memory.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-memory.toml --extra-files "$CANAILLE__THEME"
|
||||
client1: env FLASK_DEBUG=1 CONFIG=../conf/client1.cfg FLASK_APP=client flask run --port=5001
|
||||
client2: env FLASK_DEBUG=1 CONFIG=../conf/client2.cfg FLASK_APP=client flask run --port=5002
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 CONFIG=conf/canaille-sql.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-sql.toml --extra-files "$CANAILLE__THEME"
|
||||
canaille: env FLASK_DEBUG=1 AUTHLIB_INSECURE_TRANSPORT=1 ENV_FILE=../.env CONFIG=conf/canaille-sql.toml FLASK_APP=demoapp flask run --extra-files conf/canaille-sql.toml --extra-files "$CANAILLE__THEME"
|
||||
client1: env FLASK_DEBUG=1 CONFIG=../conf/client1.cfg FLASK_APP=client flask run --port=5001
|
||||
client2: env FLASK_DEBUG=1 CONFIG=../conf/client2.cfg FLASK_APP=client flask run --port=5002
|
||||
|
|
1013
doc/locales/doc.pot
1013
doc/locales/doc.pot
File diff suppressed because it is too large
Load diff
|
@ -39,7 +39,8 @@ The way environment variables are parsed can be read from the `pydantic-settings
|
|||
Environment file
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Any environment variable can also be written in a ``.env``, and will be read if present.
|
||||
Any environment variable can also be written in an environment file, which path should be passed in the ``ENV_FILE`` environment variable.
|
||||
For instance, set ``ENV_FILE=.env`` to load a ``.env`` file.
|
||||
|
||||
.. code-block:: bash
|
||||
:caption: .env
|
||||
|
|
|
@ -93,7 +93,7 @@ def test_dotenv_file(tmp_path, configuration):
|
|||
|
||||
def test_custom_dotenv_file(tmp_path, configuration):
|
||||
"""Canaille should read configuration from custom .env files if they are
|
||||
passed with ENV_FILE."""
|
||||
passed with env_file."""
|
||||
dotenv = tmp_path / "custom.env"
|
||||
with open(dotenv, "w") as fd:
|
||||
fd.write("FOOBAR=other-custom-value")
|
||||
|
@ -103,7 +103,7 @@ def test_custom_dotenv_file(tmp_path, configuration):
|
|||
|
||||
|
||||
def test_disable_dotenv_file(tmp_path, configuration):
|
||||
"""Canaille should ignore .env files if ENV_FILE is None."""
|
||||
"""Canaille should ignore .env files if env_file is None."""
|
||||
oldcwd = os.getcwd()
|
||||
os.chdir(tmp_path)
|
||||
dotenv = tmp_path / ".env"
|
||||
|
|
Loading…
Reference in a new issue