Skip to content

Commit

Permalink
Merge pull request #20 from mradigen/master
Browse files Browse the repository at this point in the history
feat: /api/team/containers
  • Loading branch information
mradigen authored Jan 25, 2024
2 parents 87761b7 + b6002eb commit c5da0d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/pwncore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class Config:
config = Config(
development=True,
db_url="sqlite://:memory:",
# docker_url=None, # None for default system docker
docker_url=None, # None for default system docker
# Or set it to an arbitrary URL for testing without Docker
docker_url="http://google.com",
# docker_url="http://google.com",
flag="C0D",
max_containers_per_team=3,
jwt_secret="mysecret",
Expand Down
18 changes: 17 additions & 1 deletion src/pwncore/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tortoise.transactions import atomic

from pwncore.config import config
from pwncore.models import Team, User, Team_Pydantic, User_Pydantic
from pwncore.models import Team, User, Team_Pydantic, User_Pydantic, Container
from pwncore.routes.auth import RequireJwt

# Metadata at the top for instant accessibility
Expand Down Expand Up @@ -81,3 +81,19 @@ async def remove_member(user_info: UserRemoveBody, response: Response, jwt: Requ
response.status_code = 500
return {"msg_code": config.msg_codes["db_error"]}
return {"msg_code": config.msg_codes["user_removed"]}


@router.get("/containers")
async def get_team_containers(response: Response, jwt: RequireJwt):
containers = await Container.filter(team_id=jwt["team_id"]).prefetch_related(
"ports", "problem"
)

result = {}
for container in containers:
# mypy complains id doesnt exist in Problem
result[container.problem.id] = await container.ports.all().values_list( # type: ignore[attr-defined]
"port", flat=True
)

return result

0 comments on commit c5da0d9

Please sign in to comment.