from ._sdk import GovernClient, Governance, IceboxClient, IceboxError
import contextlib
class Workspace:
def __init__(self, target: str, mode: str = "freezer", url: str = "http://127.0.0.1:8443"):
self.target = target
self.mode = mode
self.client = IceboxClient(url)
self.client.accept_charter(self.target)
self.client.add_scope(self.target)
self.client.set_mode(self.mode)
def execute(self, module: str, sandbox: bool = False, approved: bool = True, options: dict | None = None) -> dict:
return self.client.run_module(module, self.target, sandbox=sandbox, approved=approved, options=options)
def audit(self, n: int = 20) -> list[dict]:
return self.client.audit(n)
@contextlib.contextmanager
def tunnel(self, port: int, sandbox: bool = False):
res = self.client.bind_proxy(self.target, port, sandbox=sandbox)
if "error" in res and res["error"]:
raise IceboxError(f"Failed to bind proxy: {res['error']}")
local_port = res.get("local_port")
if not local_port:
raise IceboxError(f"No local port returned: {res}")
try:
yield local_port
finally:
self.client.unbind_proxy(local_port)
__all__ = ["Governance", "GovernClient", "IceboxClient", "IceboxError", "Workspace"]
__version__ = "0.2.6"