Skip to content

Commit ee9d9d0

Browse files
authored
Support for KARTON_CONFIG_FILE env variable for providing configuration file path (#310)
1 parent 9a3208d commit ee9d9d0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

docs/service_configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Configuration values are read from various sources using the following precedenc
2525
- ``/etc/karton/karton.ini`` file (global)
2626
- ``~/.config/karton/karton.ini`` file (user local)
2727
- ``./karton.ini`` file (subsystem local)
28+
- path provided via ``KARTON_CONFIG_FILE`` environment variable
2829
- ``--config-path <path>`` optional, additional path provided in arguments
2930
- ``KARTON_SECTION_OPTION`` values from environment variables e.g. (``secret_key`` option in ``[s3]`` section can be overridden using ``KARTON_S3_SECRET_KEY`` variable)
3031
- Command-line arguments (if ``Karton.main()`` method is used as entrypoint)

karton/core/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Config(object):
1414
- ``/etc/karton/karton.ini`` (global)
1515
- ``~/.config/karton/karton.ini`` (user local)
1616
- ``./karton.ini`` (subsystem local)
17+
- path from ``KARTON_CONFIG_FILE`` environment variable
1718
- ``<path>`` optional, additional path provided in arguments
1819
1920
It is also possible to pass configuration via environment variables.
@@ -38,6 +39,12 @@ def __init__(
3839
) -> None:
3940
self._config: Dict[str, Dict[str, Any]] = {}
4041

42+
path_from_env = os.getenv("KARTON_CONFIG_FILE")
43+
if path_from_env:
44+
if not os.path.isfile(path_from_env):
45+
raise IOError(f"Configuration file not found in {path_from_env}")
46+
self.SEARCH_PATHS = self.SEARCH_PATHS + [path_from_env]
47+
4148
if path is not None:
4249
if not os.path.isfile(path):
4350
raise IOError("Configuration file not found in " + path)

0 commit comments

Comments
 (0)