Skip to content

Commit

Permalink
Merge pull request #788 from ajstanley/secure_ssl_only
Browse files Browse the repository at this point in the history
allowed i7 harvesting without checking certs
  • Loading branch information
mjordan authored Jun 7, 2024
2 parents 066f567 + 7cdc8e6 commit 986e8ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions i7Import/get_islandora_7_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
parser = argparse.ArgumentParser()
parser.add_argument("--config", required=True, help="Configuration file to use.")
parser.add_argument(
"--metadata_solr_request", required=False, help="Option to solr metadata request."
"--metadata_solr_request",
required=False,
help="Option to supply solr metadata request.",
)
args = parser.parse_args()
utils = i7ImportUtilities(args.config)
Expand All @@ -44,6 +46,8 @@
metadata_solr_request = utils.get_metadata_solr_request(args.metadata_solr_request)
else:
metadata_solr_request = utils.get_default_metadata_solr_request()
if config["secure_ssl_only"] is False:
requests.packages.urllib3.disable_warnings()
if config["debug"]:
pretty_print = metadata_solr_request.replace("&", "\n&")
print(f"Solr request: {pretty_print}")
Expand Down Expand Up @@ -83,7 +87,7 @@
row_count = 0
pbar = InitBar()
num_csv_rows = len(rows)
print(f"Processing {num_csv_rows -1}.")
print(f"Processing {num_csv_rows - 1}.")
with open(config["csv_output_path"], "w", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=headers)
writer.writeheader()
Expand Down
15 changes: 12 additions & 3 deletions i7Import/i7ImportUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, config_location):
"solr_filters": False,
"start": 0,
"rows": 100000,
"secure_ssl_only": True,
}

def get_config(self):
Expand Down Expand Up @@ -97,7 +98,9 @@ def parse_rels_ext(self, pid):
print(f"\n{rels_ext_url}")
try:
rels_ext_download_response = requests.get(
url=rels_ext_url, allow_redirects=True
verify=self.config["secure_ssl_only"],
url=rels_ext_url,
allow_redirects=True,
)
if rels_ext_download_response.ok:
rel_ext = {}
Expand Down Expand Up @@ -136,7 +139,9 @@ def get_default_metadata_solr_request(self):
# then used in another query to get the populated CSV data.
try:
field_list_response = requests.get(
url=fields_solr_url, allow_redirects=True
verify=self.config["secure_ssl_only"],
url=fields_solr_url,
allow_redirects=True,
)
raw_field_list = field_list_response.content.decode()
except requests.exceptions.RequestException as e:
Expand Down Expand Up @@ -196,7 +201,11 @@ def get_i7_asset(self, pid, datastream):
if self.config["get_file_url"]:
obj_download_response = requests.head(url=obj_url, allow_redirects=True)
else:
obj_download_response = requests.get(url=obj_url, allow_redirects=True)
obj_download_response = requests.get(
verify=self.config["secure_ssl_only"],
url=obj_url,
allow_redirects=True,
)
if obj_download_response.status_code == 200:
# Get MIMETYPE from 'Content-Type' header
obj_mimetype = obj_download_response.headers["content-type"]
Expand Down

0 comments on commit 986e8ba

Please sign in to comment.