Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
- pass files_directory_name
- fix files key not found
- fix tests on 3.8
  • Loading branch information
Miłosz Skaza committed Nov 3, 2023
1 parent 597902b commit 8adcfc0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ctfcli/cli/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def healthcheck(self, challenge: str = None) -> int:
click.secho("Success! Challenge passed the healthcheck.", fg="green")
return 0

def mirror(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) -> int:
def mirror(self, challenge: str = None, files_directory: str = "dist", ignore: Union[str, Tuple[str]] = ()) -> int:
config = Config()
challenge_keys = [challenge]

Expand Down Expand Up @@ -910,7 +910,7 @@ def mirror(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) ->
for challenge in challenges:
try:
if not challenge.verify(ignore=ignore):
challenge.mirror(ignore=ignore)
challenge.mirror(files_directory_name=files_directory, ignore=ignore)
else:
click.secho(
f"Challenge '{challenge['name']}' is already in sync. Skipping mirroring.",
Expand Down
6 changes: 3 additions & 3 deletions ctfcli/core/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
from os import PathLike
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union

import click
import yaml
Expand Down Expand Up @@ -568,7 +568,7 @@ def lint(self, skip_hadolint=False, flag_format="flag{") -> bool:
# Note: files won't be included for two reasons:
# 1. To avoid downloading them unnecessarily, e.g., when they are ignored
# 2. Because it's dependent on the implementation whether to save them (mirror) or just compare (verify)
def _normalize_challenge(self, challenge_data: dict[str, Any]):
def _normalize_challenge(self, challenge_data: Dict[str, Any]):
challenge = {}

copy_keys = ["name", "category", "value", "type", "state", "connection_info"]
Expand Down Expand Up @@ -699,7 +699,7 @@ def verify(self, ignore: Tuple[str] = ()) -> bool:

# Handle a special case for files, unless they are ignored
if "files" not in ignore:
local_files = {Path(f).name: f for f in challenge["files"]}
local_files = {Path(f).name: f for f in challenge.get("files", [])}
remote_files = {f.split("/")[-1].split("?token=")[0]: f for f in remote_challenge["files"]}

# Check if there are no extra local files
Expand Down

0 comments on commit 8adcfc0

Please sign in to comment.