From ba06c3d871dee7cdfb77b41cc20beecbf531b2fc Mon Sep 17 00:00:00 2001 From: Annick Renevey <47788523+rannick@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:53:17 +0200 Subject: [PATCH 1/3] add no_ssl parameter as flag to verify or not --- CHANGELOG.md | 8 ++++++++ fusion_report/arguments.json | 5 +++++ fusion_report/common/net.py | 19 +++++++++---------- fusion_report/download.py | 8 ++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a09bf..6d5124d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## dev + + ## [3.1.0] + +### Added + +- Added support to run the tool without SSL chain verification for users behind proxy servers who act as MITM + ### Changed - Scoring formula changed to: diff --git a/fusion_report/arguments.json b/fusion_report/arguments.json index 3a25384..839099a 100644 --- a/fusion_report/arguments.json +++ b/fusion_report/arguments.json @@ -111,6 +111,11 @@ "key": "--no-mitelman", "help": "Do not download mitelman fusion database", "action": "store_true" + }, + { + "key": ["-no_ssl"], + "help": "Turn off verification of SSL certificates when downloading data.", + "action": "store_true" } ], "cosmic": [ diff --git a/fusion_report/common/net.py b/fusion_report/common/net.py index 00e5f28..813ff77 100644 --- a/fusion_report/common/net.py +++ b/fusion_report/common/net.py @@ -96,13 +96,12 @@ def get_cosmic_qiagen_token(params: Namespace): return json.loads(token_response)["access_token"] @staticmethod - def get_large_file(url: str) -> None: + def get_large_file(url: str, no_ssl) -> None: """Method for downloading a large file.""" LOG.info(f"Downloading {url}") try: headers = {"User-Agent": "Mozilla/5.0"} - response = requests.get(url, headers=headers, stream=True) - + response = requests.get(url, headers=headers, stream=True, verify = no_ssl) file = url.split("/")[-1].split("?")[0] if ( @@ -118,7 +117,7 @@ def get_large_file(url: str) -> None: raise DownloadException(ex) @staticmethod - def get_cosmic_from_sanger(token: str, return_err: List[str]) -> None: + def get_cosmic_from_sanger(token: str, return_err: List[str], no_ssl) -> None: """Method for download COSMIC database from sanger website.""" files = [] file: str = Settings.COSMIC["FILE"] @@ -131,10 +130,10 @@ def get_cosmic_from_sanger(token: str, return_err: List[str]) -> None: ), } try: - res = requests.get(url, headers=headers) + res = requests.get(url, headers=headers, verify = no_ssl) auth_url: str = res.json()["url"] LOG.info(f"auth_url: {auth_url}") - Net.get_large_file(auth_url) + Net.get_large_file(auth_url, no_ssl) files.append(".".join(file.split(".")[:-1])) with gzip.open(file, "rb") as archive, open(files[0], "wb") as out_file: @@ -170,11 +169,11 @@ def get_cosmic_from_qiagen(token: str, return_err: List[str], outputpath: str) - return_err.append(f'{Settings.COSMIC["NAME"]}: {ex}') @staticmethod - def get_fusiongdb2(self, return_err: List[str]) -> None: + def get_fusiongdb2(self, return_err: List[str], no_ssl) -> None: """Method for download FusionGDB2 database.""" try: url: str = f'{Settings.FUSIONGDB2["HOSTNAME"]}/{Settings.FUSIONGDB2["FILE"]}' - Net.get_large_file(url) + Net.get_large_file(url, no_ssl) file: str = f'{Settings.FUSIONGDB2["FILE"]}' df = pd.read_excel(file, engine="openpyxl") df["fusion"] = df["5'-gene (text format)"] + "--" + df["3'-gene (text format)"] @@ -188,11 +187,11 @@ def get_fusiongdb2(self, return_err: List[str]) -> None: return_err.append(f"FusionGDB2: {ex}") @staticmethod - def get_mitelman(self, return_err: List[str]) -> None: + def get_mitelman(self, return_err: List[str], no_ssl) -> None: """Method for download Mitelman database.""" try: url: str = f'{Settings.MITELMAN["HOSTNAME"]}/{Settings.MITELMAN["FILE"]}' - Net.get_large_file(url) + Net.get_large_file(url, no_ssl) with ZipFile(Settings.MITELMAN["FILE"], "r") as archive: files = [ x for x in archive.namelist() if "MBCA.TXT.DATA" in x and not "MACOSX" in x diff --git a/fusion_report/download.py b/fusion_report/download.py index e739d32..44e1030 100644 --- a/fusion_report/download.py +++ b/fusion_report/download.py @@ -42,21 +42,21 @@ def download_all(self, params: Namespace) -> None: if not params.no_mitelman: # MITELMAN - Net.get_mitelman(self, return_err) + Net.get_mitelman(self, return_err, params.no_ssl) if not params.no_fusiongdb2: # FusionGDB2 - Net.get_fusiongdb2(self, return_err) + Net.get_fusiongdb2(self, return_err, params.no_ssl) if not params.no_cosmic: # COSMIC self.validate(params) if params.qiagen: Logger(__name__).info("Downloading resources from QIAGEN...") - Net.get_cosmic_from_qiagen(self.cosmic_token, return_err, params.output) + Net.get_cosmic_from_qiagen(self.cosmic_token, return_err, params.output, params.no_ssl) else: Logger(__name__).info("Downloading resources from SANGER...") - Net.get_cosmic_from_sanger(self.cosmic_token, return_err) + Net.get_cosmic_from_sanger(self.cosmic_token, return_err, params.no_ssl) if len(return_err) > 0: raise DownloadException(return_err) From e05d72937e9ad1c9aaff8543293541382981bc0c Mon Sep 17 00:00:00 2001 From: Annick Renevey <47788523+rannick@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:58:22 +0200 Subject: [PATCH 2/3] param not in list --- fusion_report/arguments.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fusion_report/arguments.json b/fusion_report/arguments.json index 839099a..295523a 100644 --- a/fusion_report/arguments.json +++ b/fusion_report/arguments.json @@ -113,7 +113,7 @@ "action": "store_true" }, { - "key": ["-no_ssl"], + "key": "-no_ssl", "help": "Turn off verification of SSL certificates when downloading data.", "action": "store_true" } From 71c12cdaabbd1bb19d673fee98298c19a6abda6d Mon Sep 17 00:00:00 2001 From: Annick Renevey <47788523+rannick@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:58:33 +0200 Subject: [PATCH 3/3] black --- fusion_report/common/net.py | 4 ++-- fusion_report/download.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fusion_report/common/net.py b/fusion_report/common/net.py index 813ff77..198c8ab 100644 --- a/fusion_report/common/net.py +++ b/fusion_report/common/net.py @@ -101,7 +101,7 @@ def get_large_file(url: str, no_ssl) -> None: LOG.info(f"Downloading {url}") try: headers = {"User-Agent": "Mozilla/5.0"} - response = requests.get(url, headers=headers, stream=True, verify = no_ssl) + response = requests.get(url, headers=headers, stream=True, verify=no_ssl) file = url.split("/")[-1].split("?")[0] if ( @@ -130,7 +130,7 @@ def get_cosmic_from_sanger(token: str, return_err: List[str], no_ssl) -> None: ), } try: - res = requests.get(url, headers=headers, verify = no_ssl) + res = requests.get(url, headers=headers, verify=no_ssl) auth_url: str = res.json()["url"] LOG.info(f"auth_url: {auth_url}") Net.get_large_file(auth_url, no_ssl) diff --git a/fusion_report/download.py b/fusion_report/download.py index 44e1030..b6aa668 100644 --- a/fusion_report/download.py +++ b/fusion_report/download.py @@ -53,7 +53,9 @@ def download_all(self, params: Namespace) -> None: self.validate(params) if params.qiagen: Logger(__name__).info("Downloading resources from QIAGEN...") - Net.get_cosmic_from_qiagen(self.cosmic_token, return_err, params.output, params.no_ssl) + Net.get_cosmic_from_qiagen( + self.cosmic_token, return_err, params.output, params.no_ssl + ) else: Logger(__name__).info("Downloading resources from SANGER...") Net.get_cosmic_from_sanger(self.cosmic_token, return_err, params.no_ssl)