chartbook.conf_validation#
Security validation for user-provided configuration values.
This module provides validation for values that will be inserted into conf.py templates. Since conf.py is executed as Python code by Sphinx, all user input must be validated to prevent code injection attacks.
Module Contents#
Classes#
Validated site configuration for conf.py template rendering. |
Functions#
Whether the missing files are every output of one pipeline, and nothing else. |
|
Validate configuration values intended for conf.py template. |
|
Validate that all source files referenced in the manifest exist. |
Data#
API#
- chartbook.conf_validation.OUTPUT_FILE_TYPES#
‘frozenset(…)’
- class chartbook.conf_validation.SiteConfig[source]#
Validated site configuration for conf.py template rendering.
All string values are validated against security patterns to prevent Python code injection when rendered into conf.py templates.
Attributes: title: Project title (alphanumeric, spaces, basic punctuation). author: Author name (alphanumeric, spaces, basic punctuation). copyright: Copyright text (alphanumeric, spaces, basic punctuation). sphinx_theme: Sphinx theme name (must be from allowed list).
- SAFE_TEXT_PATTERN: ClassVar[re.Pattern]#
‘compile(…)’
- classmethod from_manifest(manifest: dict, pipeline_theme: str) chartbook.conf_validation.SiteConfig[source]#
Create a validated SiteConfig from manifest dictionary.
- Parameters:
- Returns:
Validated SiteConfig instance.
- Return type:
- Raises:
ValidationError – If any value fails validation.
- chartbook.conf_validation.built_nothing(manifest: dict, missing_files: list) bool[source]#
Whether the missing files are every output of one pipeline, and nothing else.
That is a pipeline that has not been built yet: a project just made by
chartbook init, or a fresh clone, whose build makes its data, charts, notebooks and models. A pipeline that has some of them and lacks others has been built, and what it lacks is a mistake to report, as is a missing write-up, note or README, which nothing builds.- Parameters:
manifest (dict) – The manifest dictionary from chartbook.toml.
missing_files (list[MissingFile]) – What :func:
validate_source_filesfound missing.
- Return type:
- chartbook.conf_validation.validate_conf_py_values(manifest: dict, pipeline_theme: str) chartbook.conf_validation.SiteConfig[source]#
Validate configuration values intended for conf.py template.
This is the main entry point for validation. It ensures all values that will be inserted into conf.py are safe from code injection.
- Parameters:
- Returns:
Validated SiteConfig instance with all values safe for templating.
- Return type:
- Raises:
ValidationError – If any value fails security validation.
- chartbook.conf_validation.validate_source_files(manifest: dict, base_dir) list[source]#
Validate that all source files referenced in the manifest exist.
Checks for the existence of:
Dataframe parquet files (path)
Dataframe documentation files (docs_path, when mode=“path”)
Chart HTML files (path)
Chart documentation files (docs_path, when mode=“path”)
Notebook files (path)
Note markdown files (path)
Model files or directories (path), metrics files (metrics_path) and write-ups (docs_path)
Each pipeline’s README (project.readme)
User-specified logo and favicon files
- Parameters:
manifest (dict) – The manifest dictionary from chartbook.toml.
base_dir (Path) – The base directory of the project.
- Returns:
List of MissingFile objects for any files that don’t exist.
- Return type: