import uuid from pathlib import Path from integrations.docker import DockerContainer from services.mitmproxy.models import ServiceConfig async def create_proxy( port: int, name: str, service: ServiceConfig, code: str, services: list[DockerContainer] ) -> int: """ Utility function that will: - run ``integrations/docker`` utilities to change the old port of original service to a random one - write ``code`` into ``/tmp/theplug/{random}.py`` - start a subprocess via asyncio - return the proxy infos (pid, ) """ path = Path("/tmp/theplug/{random}.py".format(random=str(uuid.uuid4()))) path.parent.mkdir(parents=True, exist_ok=True) path.write_text(code, encoding="utf-8") return 0