From 9ec705a56de9e1d80ed912f470fa5d545c9200a5 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:09:06 +0200 Subject: [PATCH 1/2] Factored out supported URI schemes to a variable Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/cfbs_config.py | 5 +++-- cfbs/commands.py | 3 ++- cfbs/internal_file_management.py | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 606cf871..3a545861 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -13,6 +13,7 @@ load_bundlenames, ) from cfbs.internal_file_management import ( + SUPPORTED_URI_SCHEMES, clone_url_repo, fetch_archive, SUPPORTED_ARCHIVES, @@ -132,7 +133,7 @@ def _add_using_url( if url.endswith(SUPPORTED_ARCHIVES): config_path, url_commit = fetch_archive(url, checksum) else: - assert url.startswith(("https://", "git://", "ssh://")) + assert url.startswith(SUPPORTED_URI_SCHEMES) config_path, url_commit = clone_url_repo(url) if "@" in url and (url.rindex("@") > url.rindex(".")): @@ -386,7 +387,7 @@ def add_command( before = {m["name"] for m in self.get("build", [])} if to_add[0].endswith(SUPPORTED_ARCHIVES) or to_add[0].startswith( - ("https://", "git://", "ssh://") + SUPPORTED_URI_SCHEMES ): self._add_using_url( url=to_add[0], diff --git a/cfbs/commands.py b/cfbs/commands.py index 2ce8efb1..00b44597 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -44,6 +44,7 @@ from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit from cfbs.validate import validate_config from cfbs.internal_file_management import ( + SUPPORTED_URI_SCHEMES, fetch_archive, get_download_path, local_module_copy, @@ -455,7 +456,7 @@ def _get_modules_by_url(name) -> list: msg = "" files = [] for name in to_remove: - if name.startswith(("https://", "ssh://", "git://")): + if name.startswith(SUPPORTED_URI_SCHEMES): matches = _get_modules_by_url(name) if not matches: user_error("Could not find module with URL '%s'" % name) diff --git a/cfbs/internal_file_management.py b/cfbs/internal_file_management.py index 5172b526..4cbf2ef4 100644 --- a/cfbs/internal_file_management.py +++ b/cfbs/internal_file_management.py @@ -28,6 +28,7 @@ _SUPPORTED_TAR_TYPES = (".tar.gz", ".tgz") SUPPORTED_ARCHIVES = (".zip",) + _SUPPORTED_TAR_TYPES +SUPPORTED_URI_SCHEMES = ("https://", "ssh://", "git://") def local_module_name(module_path): @@ -113,7 +114,7 @@ def local_module_copy(module, counter, max_length): def _get_path_from_url(url): - if not url.startswith(("https://", "ssh://", "git://")): + if not url.startswith(SUPPORTED_URI_SCHEMES): if "://" in url: return user_error("Unsupported URL protocol in '%s'" % url) else: @@ -153,7 +154,7 @@ def _clone_and_checkout(url, path, commit): def clone_url_repo(repo_url): - assert repo_url.startswith(("https://", "ssh://", "git://")) + assert repo_url.startswith(SUPPORTED_URI_SCHEMES) commit = None if "@" in repo_url and (repo_url.rindex("@") > repo_url.rindex(".")): From 940c820c5c03b1376671e6715ddc67ef901c5c58 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Wed, 25 Jun 2025 18:16:06 +0200 Subject: [PATCH 2/2] Added a user error on add from a URL of an unsupported scheme, and fixed crash on attempting to add a non-URL archive file Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/cfbs_config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cfbs/cfbs_config.py b/cfbs/cfbs_config.py index 3a545861..941a2240 100644 --- a/cfbs/cfbs_config.py +++ b/cfbs/cfbs_config.py @@ -386,9 +386,7 @@ def add_command( before = {m["name"] for m in self.get("build", [])} - if to_add[0].endswith(SUPPORTED_ARCHIVES) or to_add[0].startswith( - SUPPORTED_URI_SCHEMES - ): + if to_add[0].startswith(SUPPORTED_URI_SCHEMES): self._add_using_url( url=to_add[0], to_add=to_add[1:], @@ -396,6 +394,12 @@ def add_command( checksum=checksum, ) else: + # for this `if` to be valid, module names containing `://` should be illegal + if "://" in to_add[0]: + user_error( + "URI scheme not supported. The supported URI schemes are: " + + ", ".join(SUPPORTED_URI_SCHEMES) + ) self._add_modules(to_add, added_by, checksum) added = {m["name"] for m in self["build"]}.difference(before)