"""Security-lake playbook, step 2: install the `ocsf` domain pack, release 1.

The install pins the pack by fingerprint (a release whose bytes differ from the
published fingerprint is refused with `pack_fingerprint_mismatch`), creates the
pack's draft contract and its derived labels, and makes its three OCSF catalogs
available as source mappings.
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))  # playbooks/playbook_api.py
from playbook_api import Api, State

api, state = Api(), State("security-lake")

install = api.post("/domain-packs/ocsf:install", {"version": 1}, key="security-lake-install")
print(f"pack: {install['pack']} v{install['version']} {install['status']}")
print(f"pack_fingerprint: {install['pack_fingerprint']}")
print(f"entity_types: {', '.join(install['entity_types'])}")
labels = {entry["name"]: entry["label_id"] for entry in install["labels"]}
for name in sorted(labels):
    print(f"label: {name}")
state.update(install_id=install["install_id"], label_ids=labels)
