From 06f4f7427319f7dd12b9921de74b7cf5807dcd10 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sat, 11 Mar 2023 16:27:11 -0500 Subject: [PATCH 1/3] Replace flake8 with ruff --- Makefile | 2 +- development.txt | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 711704d..4401321 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ lint: - flake8 --ignore=E402,E501,E712,W503,E203,I002 --exclude=ctfcli/templates **/*.py + ruff check --ignore=E402,E501,E712,I002 --exclude=ctfcli/templates --exclude=build . black --check --exclude=ctfcli/templates . format: diff --git a/development.txt b/development.txt index e834895..2a2c786 100644 --- a/development.txt +++ b/development.txt @@ -3,8 +3,5 @@ twine==3.1.1 setuptools==46.1.3 wheel==0.34.2 black==19.10b0 -flake8==3.7.9 -flake8-bugbear==20.1.2 -flake8-comprehensions==3.1.4 isort==4.3.21 -flake8-isort==2.8.0 \ No newline at end of file +ruff==0.0.254 From 921319cd25b9b564735b2cc331a69e6ff4cf400e Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sat, 11 Mar 2023 16:28:21 -0500 Subject: [PATCH 2/3] Fix F541 --- ctfcli/cli/challenges.py | 10 +++++----- ctfcli/cli/pages.py | 2 +- ctfcli/cli/plugins.py | 2 +- ctfcli/utils/challenge.py | 32 ++++++++++++++++---------------- ctfcli/utils/pages.py | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ctfcli/cli/challenges.py b/ctfcli/cli/challenges.py index fd960cb..c7c94b0 100644 --- a/ctfcli/cli/challenges.py +++ b/ctfcli/cli/challenges.py @@ -173,7 +173,7 @@ def install(self, challenge=None, force=False, ignore=()): else: # If we don't break because of duplicated challenge names click.secho(f'Installing {challenge["name"]}', fg="yellow") create_challenge(challenge=challenge, ignore=ignore) - click.secho(f"Success!", fg="green") + click.secho("Success!", fg="green") def sync(self, challenge=None, ignore=()): if challenge is None: @@ -209,7 +209,7 @@ def sync(self, challenge=None, ignore=()): click.secho(f'Syncing {challenge["name"]}', fg="yellow") sync_challenge(challenge=challenge, ignore=ignore) - click.secho(f"Success!", fg="green") + click.secho("Success!", fg="green") def update(self, challenge=None): config = load_config() @@ -339,7 +339,7 @@ def deploy(self, challenge, host=None): ) else: click.secho( - f"An error occured during deployment", fg="red", + "An error occured during deployment", fg="red", ) def push(self, challenge=None): @@ -406,11 +406,11 @@ def healthcheck(self, challenge): if rcode != 0: click.secho( - f"Healcheck failed", fg="red", + "Healcheck failed", fg="red", ) sys.exit(1) else: click.secho( - f"Success", fg="green", + "Success", fg="green", ) sys.exit(0) diff --git a/ctfcli/cli/pages.py b/ctfcli/cli/pages.py index 8d94005..00aeade 100644 --- a/ctfcli/cli/pages.py +++ b/ctfcli/cli/pages.py @@ -24,7 +24,7 @@ def install(self): pages = Path("./pages") if pages.is_dir() is False: click.secho( - f'"pages" folder not found. All pages must exist in the "pages" folder.', + '"pages" folder not found. All pages must exist in the "pages" folder.', fg="red", ) sys.exit(1) diff --git a/ctfcli/cli/plugins.py b/ctfcli/cli/plugins.py index e07c0a2..494506d 100644 --- a/ctfcli/cli/plugins.py +++ b/ctfcli/cli/plugins.py @@ -18,7 +18,7 @@ def install(self, url): pip3 = shutil.which("pip3") if pip is None and pip3 is None: - click.secho(f"Neither pip nor pip3 was found, is it in the PATH?", fg="red") + click.secho("Neither pip nor pip3 was found, is it in the PATH?", fg="red") return if pip is None: diff --git a/ctfcli/utils/challenge.py b/ctfcli/utils/challenge.py index 7094fd5..7878244 100644 --- a/ctfcli/utils/challenge.py +++ b/ctfcli/utils/challenge.py @@ -79,7 +79,7 @@ def sync_challenge(challenge, ignore=[]): # Create new flags if challenge.get("flags") and "flags" not in ignore: # Delete existing flags - current_flags = s.get(f"/api/v1/flags", json=data).json()["data"] + current_flags = s.get("/api/v1/flags", json=data).json()["data"] for flag in current_flags: if flag["challenge_id"] == challenge_id: flag_id = flag["id"] @@ -88,11 +88,11 @@ def sync_challenge(challenge, ignore=[]): for flag in challenge["flags"]: if type(flag) == str: data = {"content": flag, "type": "static", "challenge_id": challenge_id} - r = s.post(f"/api/v1/flags", json=data) + r = s.post("/api/v1/flags", json=data) r.raise_for_status() elif type(flag) == dict: flag["challenge_id"] = challenge_id - r = s.post(f"/api/v1/flags", json=flag) + r = s.post("/api/v1/flags", json=flag) r.raise_for_status() # Update topics @@ -110,7 +110,7 @@ def sync_challenge(challenge, ignore=[]): # Add new challenge topics for topic in challenge["topics"]: r = s.post( - f"/api/v1/topics", + "/api/v1/topics", json={ "value": topic, "type": "challenge", @@ -122,7 +122,7 @@ def sync_challenge(challenge, ignore=[]): # Update tags if challenge.get("tags") and "tags" not in ignore: # Delete existing tags - current_tags = s.get(f"/api/v1/tags", json=data).json()["data"] + current_tags = s.get("/api/v1/tags", json=data).json()["data"] for tag in current_tags: if tag["challenge_id"] == challenge_id: tag_id = tag["id"] @@ -130,14 +130,14 @@ def sync_challenge(challenge, ignore=[]): r.raise_for_status() for tag in challenge["tags"]: r = s.post( - f"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag} + "/api/v1/tags", json={"challenge_id": challenge_id, "value": tag} ) r.raise_for_status() # Upload files if challenge.get("files") and "files" not in ignore: # Delete existing files - all_current_files = s.get(f"/api/v1/files?type=challenge", json=data).json()[ + all_current_files = s.get("/api/v1/files?type=challenge", json=data).json()[ "data" ] for f in all_current_files: @@ -158,13 +158,13 @@ def sync_challenge(challenge, ignore=[]): data = {"challenge_id": challenge_id, "type": "challenge"} # Specifically use data= here instead of json= to send multipart/form-data - r = s.post(f"/api/v1/files", files=files, data=data) + r = s.post("/api/v1/files", files=files, data=data) r.raise_for_status() # Create hints if challenge.get("hints") and "hints" not in ignore: # Delete existing hints - current_hints = s.get(f"/api/v1/hints", json=data).json()["data"] + current_hints = s.get("/api/v1/hints", json=data).json()["data"] for hint in current_hints: if hint["challenge_id"] == challenge_id: hint_id = hint["id"] @@ -181,7 +181,7 @@ def sync_challenge(challenge, ignore=[]): "challenge_id": challenge_id, } - r = s.post(f"/api/v1/hints", json=data) + r = s.post("/api/v1/hints", json=data) r.raise_for_status() # Update requirements @@ -246,18 +246,18 @@ def create_challenge(challenge, ignore=[]): for flag in challenge["flags"]: if type(flag) == str: data = {"content": flag, "type": "static", "challenge_id": challenge_id} - r = s.post(f"/api/v1/flags", json=data) + r = s.post("/api/v1/flags", json=data) r.raise_for_status() elif type(flag) == dict: flag["challenge"] = challenge_id - r = s.post(f"/api/v1/flags", json=flag) + r = s.post("/api/v1/flags", json=flag) r.raise_for_status() # Create topics if challenge.get("topics") and "topics" not in ignore: for topic in challenge["topics"]: r = s.post( - f"/api/v1/topics", + "/api/v1/topics", json={ "value": topic, "type": "challenge", @@ -270,7 +270,7 @@ def create_challenge(challenge, ignore=[]): if challenge.get("tags") and "tags" not in ignore: for tag in challenge["tags"]: r = s.post( - f"/api/v1/tags", json={"challenge_id": challenge_id, "value": tag} + "/api/v1/tags", json={"challenge_id": challenge_id, "value": tag} ) r.raise_for_status() @@ -288,7 +288,7 @@ def create_challenge(challenge, ignore=[]): data = {"challenge_id": challenge_id, "type": "challenge"} # Specifically use data= here instead of json= to send multipart/form-data - r = s.post(f"/api/v1/files", files=files, data=data) + r = s.post("/api/v1/files", files=files, data=data) r.raise_for_status() # Add hints @@ -303,7 +303,7 @@ def create_challenge(challenge, ignore=[]): "challenge_id": challenge_id, } - r = s.post(f"/api/v1/hints", json=data) + r = s.post("/api/v1/hints", json=data) r.raise_for_status() # Add requirements diff --git a/ctfcli/utils/pages.py b/ctfcli/utils/pages.py index 6ddd568..a1a8d4f 100644 --- a/ctfcli/utils/pages.py +++ b/ctfcli/utils/pages.py @@ -9,7 +9,7 @@ def get_current_pages(): s = generate_session() - return s.get(f"/api/v1/pages", json=True).json()["data"] + return s.get("/api/v1/pages", json=True).json()["data"] def get_existing_page(route, pageset=None): @@ -67,5 +67,5 @@ def install_page(matter, path_obj): "auth_required": auth_required, "format": format, } - r = s.post(f"/api/v1/pages", json=data) + r = s.post("/api/v1/pages", json=data) r.raise_for_status() From dbf48b578d19d041ac7744185e25bb5b0017b47f Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sat, 11 Mar 2023 16:29:39 -0500 Subject: [PATCH 3/3] Fix other lints --- ctfcli/cli/challenges.py | 2 +- ctfcli/cli/pages.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ctfcli/cli/challenges.py b/ctfcli/cli/challenges.py index c7c94b0..b2e9c97 100644 --- a/ctfcli/cli/challenges.py +++ b/ctfcli/cli/challenges.py @@ -364,7 +364,7 @@ def push(self, challenge=None): def healthcheck(self, challenge): config = load_config() - challenges = config["challenges"] + _challenges = config["challenges"] # challenge_path = challenges[challenge] path = Path(challenge) diff --git a/ctfcli/cli/pages.py b/ctfcli/cli/pages.py index 00aeade..f4a0c7d 100644 --- a/ctfcli/cli/pages.py +++ b/ctfcli/cli/pages.py @@ -17,7 +17,8 @@ class Pages(object): def install(self): try: _config = load_config() - except: + except Exception as e: + print(e) click.secho("No ctfcli configuration found", fg="red") sys.exit(1)