This repository implements a Python module for reading TOML configuration files used by various Cyber Hygiene components. It will discover, read, and optionally validate a configuration file.
The module will search for the configuration file in the following locations, in the specified order:
- The path in the filesystem specified by the optional
CYHY_CONFIG_PATH
environment variable. - The path in AWS SSM specified
by the optional
CYHY_CONFIG_SSM_PATH
environment variable. - In the current working directory:
cyhy.toml
- In the user's home directory:
~/.cyhy/cyhy.toml
- In the system's
etc
directory:/etc/cyhy.toml
If the configuration file is not found, the module will raise a
FileNotFoundError
.
The module will optionally validate the configuration file against a
Pydantic model. If the configuration file does not
match the model a
ValidationError
will be raised.
Variable | Description |
---|---|
CYHY_CONFIG_PATH |
The path to the configuration file. |
CYHY_CONFIG_SSM_PATH |
The path to the configuration file in AWS SSM. |
from cyhy_config import get_config
from pydantic import ValidationError
try:
config = get_config(file_path=config_file, model=MyModelClass)
except ValidationError:
sys.exit(1)
except FileNotFoundError:
sys.exit(1)
We welcome contributions! Please see CONTRIBUTING.md
for
details.
This project is in the worldwide public domain.
This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.
All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.