Skip to content

hooks_dir

hooks_dir

OCI hooks directory discovery.

Reads containers.conf to figure out where podman would look for global hook descriptors, and reports whether shield's own hook is installed in any of them.

HOOK_JSON_FILENAME = 'terok-shield-createRuntime.json' module-attribute

find_hooks_dirs()

Find hooks directories podman would check.

Reads containers.conf (user config overrides system config). Returns the configured directories in precedence order (last wins for podman). Empty when no hooks_dir entry is configured — terok always patches containers.conf at setup time, so an empty result implies setup has not run.

Source code in src/terok_shield/podman_info/hooks_dir.py
def find_hooks_dirs() -> list[Path]:
    """Find hooks directories podman would check.

    Reads ``containers.conf`` (user config overrides system config).
    Returns the configured directories in precedence order (last wins
    for podman).  Empty when no ``hooks_dir`` entry is configured —
    terok always patches ``containers.conf`` at setup time, so an
    empty result implies setup has not run.
    """
    user_dirs = _parse_hooks_dir_from_conf(_user_containers_conf())
    if user_dirs:
        return [Path(d).expanduser() for d in user_dirs]

    for conf_path in reversed(_SYSTEM_CONF_PATHS):
        dirs = _parse_hooks_dir_from_conf(conf_path)
        if dirs:
            return [Path(d).expanduser() for d in dirs]

    return []

has_global_hooks(hooks_dirs=None)

Check if terok-shield hooks are installed in any global hooks dir.

Parameters:

Name Type Description Default
hooks_dirs list[Path] | None

Directories to check (default: auto-detect via find_hooks_dirs).

None
Source code in src/terok_shield/podman_info/hooks_dir.py
def has_global_hooks(hooks_dirs: list[Path] | None = None) -> bool:
    """Check if terok-shield hooks are installed in any global hooks dir.

    Args:
        hooks_dirs: Directories to check (default: auto-detect via
            [`find_hooks_dirs`][terok_shield.podman_info.hooks_dir.find_hooks_dirs]).
    """
    if hooks_dirs is None:
        hooks_dirs = find_hooks_dirs()
    return any((d / HOOK_JSON_FILENAME).is_file() for d in hooks_dirs)

global_hooks_hint()

Short hint telling the user to run terok-shield setup.

Source code in src/terok_shield/podman_info/hooks_dir.py
def global_hooks_hint() -> str:
    """Short hint telling the user to run ``terok-shield setup``."""
    return (
        "Per-container --hooks-dir does not persist on container restart\n"
        "(ref: https://github.com/containers/podman/issues/17935).\n"
        "\n"
        "Run 'terok-shield setup' to install global hooks."
    )