fix: editTeam endpoint + leaderboard live name resolution + domains in team set + apt-insecure.conf in all service dirs
This commit is contained in:
+39
-3
@@ -68,17 +68,29 @@ def slugify(s: str) -> str:
|
||||
s = re.sub(r"[\s_]+", "-", s)
|
||||
return s or "team"
|
||||
|
||||
def create_team(idx: int, label: str = None):
|
||||
"""Build a full team stack dir with unique ports/passwords."""
|
||||
def create_team(idx: int, label: str = None, domain: str = None):
|
||||
"""Build a full team stack dir with unique ports/passwords.
|
||||
|
||||
label -> team display name (leaderboard/topology)
|
||||
domain -> custom subdomain host, e.g. "cyber-warriors" or
|
||||
"cyber-warriors.gemastik.imrnes.team" (full host accepted).
|
||||
Defaults to slugify(label).gemastik.imrnes.team.
|
||||
"""
|
||||
ports = team_ports(idx)
|
||||
team_dir = TEAMS_DIR / f"team{idx}"
|
||||
label = label or f"Tim {idx}"
|
||||
slug = slugify(label)
|
||||
# normalize custom domain -> host under *.gemastik.imrnes.team
|
||||
host = (domain or f"{slug}.gemastik.imrnes.team").strip().lower()
|
||||
host = host.replace("https://", "").replace("http://", "").rstrip("/")
|
||||
if not host.endswith(".gemastik.imrnes.team"):
|
||||
host = f"{host}.gemastik.imrnes.team"
|
||||
slug = host.split(".")[0]
|
||||
state = {
|
||||
"index": idx,
|
||||
"label": label,
|
||||
"slug": slug,
|
||||
"domain": f"{slug}.gemastik.imrnes.team",
|
||||
"domain": host,
|
||||
"ports": ports,
|
||||
"admin_user": f"admin_team{idx}",
|
||||
"admin_pass": gen_password(20),
|
||||
@@ -185,6 +197,30 @@ def create_team(idx: int, label: str = None):
|
||||
(team_dir / "state.json").write_text(json.dumps(state, indent=2))
|
||||
return state
|
||||
|
||||
def update_team(idx: int, label: str = None, domain: str = None) -> dict:
|
||||
"""Update a team's display name and/or custom domain (live re-route).
|
||||
|
||||
- label updates state.json['label'] (leaderboard/topology use this).
|
||||
- domain updates slug + domain and rewrites the Traefik team route.
|
||||
Returns updated state.
|
||||
"""
|
||||
team_dir = TEAMS_DIR / f"team{idx}"
|
||||
if not (team_dir / "state.json").exists():
|
||||
raise FileNotFoundError(f"Team {idx} not created")
|
||||
st = json.loads((team_dir / "state.json").read_text())
|
||||
if label:
|
||||
st["label"] = str(label).strip()[:48] or st["label"]
|
||||
if domain:
|
||||
host = domain.strip().lower().replace("https://", "").replace("http://", "").rstrip("/")
|
||||
if not host.endswith(".gemastik.imrnes.team"):
|
||||
host = f"{host}.gemastik.imrnes.team"
|
||||
st["domain"] = host
|
||||
st["slug"] = host.split(".")[0]
|
||||
(team_dir / "state.json").write_text(json.dumps(st, indent=2))
|
||||
# re-route domain in Traefik immediately
|
||||
ensure_team_domains()
|
||||
return st
|
||||
|
||||
def start_team(idx: int):
|
||||
team_dir = TEAMS_DIR / f"team{idx}"
|
||||
if not (team_dir / "state.json").exists():
|
||||
|
||||
Reference in New Issue
Block a user