Skip to content

Commit

Permalink
update: make app/utils.py compliant to linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-J committed Aug 10, 2024
1 parent 7739766 commit 5ced277
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ venv.bak/

# mypy
.mypy_cache/
.idea
6 changes: 4 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from docker import DockerClient

from app.types import ConfigChallengeType, ConfigDockerHostType


try:
DEBUG = strtobool(getenv("DEBUG", "0"))
Expand All @@ -31,8 +33,8 @@
MIN_PORTS = config["random_ports"]["min"]
MAX_PORTS = config["random_ports"]["max"]

CHALLENGES = config["challenges"]
DOCKER_HOSTS = config["hosts"]
CHALLENGES: list[ConfigChallengeType] = config["challenges"]
DOCKER_HOSTS: list[ConfigDockerHostType] = config["hosts"]

for host in DOCKER_HOSTS:
host["client"] = DockerClient(base_url=host["api"])
35 changes: 35 additions & 0 deletions app/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import typing

from docker import DockerClient


class UserType(typing.TypedDict):
user_id: int | None
Expand All @@ -9,3 +11,36 @@ class UserType(typing.TypedDict):
team_name: str | None

is_admin: bool


class ConfigDockerHostType(typing.TypedDict):
domain: str
api: str
client: DockerClient


class ContainerPortType(typing.TypedDict):
port: str
protocol: typing.Literal["http", "ssh"]


class ChallengeContainerType(typing.TypedDict):
docker_image: str

hostname: str | None
ports: list[ContainerPortType]

command: str | None
environment: dict[str, typing.Any] | None
privileged: bool | None

mem_limit: str
read_only: bool

cpu_period: int | None
cpu_quota: int | None


class ConfigChallengeType(typing.TypedDict):
name: str
containers: list[ChallengeContainerType]
Loading

0 comments on commit 5ced277

Please sign in to comment.