Files
thePlug/app/services/mitmproxy/manager.py
T
reloia f9e33e2847
Build and Push to Registry / build (push) Successful in 29s
refactor(proxy): move proxy logic to services.mitmproxy and update Docker service model
- Rename DockerService to DockerContainer and add folder attribute
- Move proxy-related modules (models, validator) to services.mitmproxy
- Update imports and references to new module locations
- Refactor Docker utilities to use DockerContainer and improve service discovery
- Add manager.py with create_proxy utility stub
- Initialize discovered Docker services at app startup and warn if none found
2026-04-13 00:24:20 +02:00

28 lines
774 B
Python

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