Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no_ssl parameter as flag to verify or not #79

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions fusion_report/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
19 changes: 9 additions & 10 deletions fusion_report/common/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"]
Expand All @@ -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:
Expand Down Expand Up @@ -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)"]
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions fusion_report/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ 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)
Expand Down
Loading