Skip to content

Commit

Permalink
Drop testing parameters to skip SSL verification
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Aug 16, 2023
1 parent e992603 commit 7d7cb60
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/galaxy/files/sources/invenio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
import ssl
import urllib.request
from typing import (
Any,
Expand Down Expand Up @@ -34,13 +33,6 @@
stream_to_open_named_file,
)

# TODO: Remove this block. Ignoring SSL errors for testing purposes.
VERIFY = False
SSL_CONTEXT = ssl.create_default_context()
SSL_CONTEXT.check_hostname = False
SSL_CONTEXT.verify_mode = ssl.CERT_NONE


AccessStatus = Literal["public", "restricted"]


Expand Down Expand Up @@ -230,7 +222,7 @@ def create_draft_record(self, title: str, user_context: OptionalUserContext = No
"Cannot create record without authentication token. Please set your personal access token in your Galaxy preferences."
)

response = requests.post(self.records_url, json=create_record_request, headers=headers, verify=VERIFY)
response = requests.post(self.records_url, json=create_record_request, headers=headers)
self._ensure_response_has_expected_status_code(response, 201)
record = response.json()
return record
Expand All @@ -247,7 +239,7 @@ def upload_file_to_draft_record(
headers = self._get_request_headers(user_context)

# Add file metadata entry
response = requests.post(upload_file_url, json=[{"key": filename}], headers=headers, verify=VERIFY)
response = requests.post(upload_file_url, json=[{"key": filename}], headers=headers)
self._ensure_response_has_expected_status_code(response, 201)

# Upload file content
Expand All @@ -256,11 +248,11 @@ def upload_file_to_draft_record(
upload_file_content_url = file_entry["links"]["content"]
commit_file_upload_url = file_entry["links"]["commit"]
with open(file_path, "rb") as file:
response = requests.put(upload_file_content_url, data=file, headers=headers, verify=VERIFY)
response = requests.put(upload_file_content_url, data=file, headers=headers)
self._ensure_response_has_expected_status_code(response, 200)

# Commit file upload
response = requests.post(commit_file_upload_url, headers=headers, verify=VERIFY)
response = requests.post(commit_file_upload_url, headers=headers)
self._ensure_response_has_expected_status_code(response, 200)

def download_file_from_record(
Expand All @@ -273,7 +265,7 @@ def download_file_from_record(
download_file_content_url = self._get_download_file_url(record_id, filename, user_context)
headers = self._get_request_headers(user_context)
req = urllib.request.Request(download_file_content_url, headers=headers)
with urllib.request.urlopen(req, timeout=DEFAULT_SOCKET_TIMEOUT, context=SSL_CONTEXT) as page:
with urllib.request.urlopen(req, timeout=DEFAULT_SOCKET_TIMEOUT) as page:
f = open(file_path, "wb")
return stream_to_open_named_file(
page, f.fileno(), file_path, source_encoding=get_charset_from_http_headers(page.headers)
Expand Down Expand Up @@ -364,7 +356,7 @@ def _get_response(
self, user_context: OptionalUserContext, request_url: str, params: Optional[Dict[str, Any]] = None
) -> dict:
headers = self._get_request_headers(user_context)
response = requests.get(request_url, params=params, headers=headers, verify=VERIFY)
response = requests.get(request_url, params=params, headers=headers)
self._ensure_response_has_expected_status_code(response, 200)
return response.json()

Expand Down

0 comments on commit 7d7cb60

Please sign in to comment.