Skip to content

Commit 5ced277

Browse files
committed
update: make app/utils.py compliant to linter
1 parent 7739766 commit 5ced277

File tree

5 files changed

+238
-126
lines changed

5 files changed

+238
-126
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ venv.bak/
105105

106106
# mypy
107107
.mypy_cache/
108+
.idea

app/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from docker import DockerClient
88

9+
from app.types import ConfigChallengeType, ConfigDockerHostType
10+
911

1012
try:
1113
DEBUG = strtobool(getenv("DEBUG", "0"))
@@ -31,8 +33,8 @@
3133
MIN_PORTS = config["random_ports"]["min"]
3234
MAX_PORTS = config["random_ports"]["max"]
3335

34-
CHALLENGES = config["challenges"]
35-
DOCKER_HOSTS = config["hosts"]
36+
CHALLENGES: list[ConfigChallengeType] = config["challenges"]
37+
DOCKER_HOSTS: list[ConfigDockerHostType] = config["hosts"]
3638

3739
for host in DOCKER_HOSTS:
3840
host["client"] = DockerClient(base_url=host["api"])

app/types.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import typing
22

3+
from docker import DockerClient
4+
35

46
class UserType(typing.TypedDict):
57
user_id: int | None
@@ -9,3 +11,36 @@ class UserType(typing.TypedDict):
911
team_name: str | None
1012

1113
is_admin: bool
14+
15+
16+
class ConfigDockerHostType(typing.TypedDict):
17+
domain: str
18+
api: str
19+
client: DockerClient
20+
21+
22+
class ContainerPortType(typing.TypedDict):
23+
port: str
24+
protocol: typing.Literal["http", "ssh"]
25+
26+
27+
class ChallengeContainerType(typing.TypedDict):
28+
docker_image: str
29+
30+
hostname: str | None
31+
ports: list[ContainerPortType]
32+
33+
command: str | None
34+
environment: dict[str, typing.Any] | None
35+
privileged: bool | None
36+
37+
mem_limit: str
38+
read_only: bool
39+
40+
cpu_period: int | None
41+
cpu_quota: int | None
42+
43+
44+
class ConfigChallengeType(typing.TypedDict):
45+
name: str
46+
containers: list[ChallengeContainerType]

0 commit comments

Comments
 (0)