feat: add engine lib modules (ufw, crowdsec, systemd, notify)
This commit is contained in:
1 parent
72eec40ef3
commit
9ad3c93644
5 files changed
+201
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# 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", "curl -s 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])
|
||||
Reference in new issue
Block a user