Files
apex.ermnvldmr.com/engine/lib/crowdsec.py
T
deytenit 6463bad5ee feat(engine): de-slop commons, harden security, add targeted compose and env bridge
- Purge misplaced RFCs, scratch tokens, and node-proprietary assets
- Decouple remote provisioning to ci/scripts/init-node.py
- Add targeted composition orchestration in actions/compose.py
- Add host-side Xray stale socket cleanup in /dev/shm
- Add actions/env.py for shell exports and .env synchronization
- Harden UFW, backup retention, host tempfiles, and notify dispatcher
- Add pyproject.toml and Makefile with 78 passing unit tests
2026-10-26 00:03:33 +03:00

29 lines
1.2 KiB
Python

# engine/lib/crowdsec.py
"""ctx.crowdsec — install + config deploy + collections (port of configure/crowdsec)."""
from __future__ import annotations
import os
import shutil
class Crowdsec:
def __init__(self, log, sys_, tpl, host):
self.log, self.sys, self.tpl, self.host = log, sys_, tpl, host
def ensure_installed(self) -> None:
if shutil.which("cscli"):
return
self.log.info("Installing CrowdSec via official script...")
self.sys.run(["bash", "-c", "set -o pipefail; curl -sSfL https://install.crowdsec.net | sudo sh"],
check=True)
self.sys.sudo(["apt-get", "install", "-y", "crowdsec"])
def deploy(self, configs_subdir: str, vars: dict, dry_run: bool = False) -> None:
for rel, content in self.tpl.render_dir(configs_subdir, vars).items():
self.host.write_file(os.path.join("/etc/crowdsec", rel), content,
backup=True, dry_run=dry_run, sudo=True)
def install_collections(self, collections) -> None:
self.sys.sudo(["cscli", "hub", "update"])
for c in collections:
self.sys.sudo(["cscli", "collections", "install", c])