From 2a9ae800833a5d2ab8503142bc28d629d3a4c908 Mon Sep 17 00:00:00 2001
From: francoismg <46478217+francoismg@users.noreply.github.com>
Date: Tue, 30 Jan 2024 06:28:06 +0100
Subject: [PATCH 1/2] Custom url + url validation support
---
.../pyvo_integration/astronomical_archives.py | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/archives/pyvo_integration/astronomical_archives.py b/tools/archives/pyvo_integration/astronomical_archives.py
index 17897f1c..000c3521 100644
--- a/tools/archives/pyvo_integration/astronomical_archives.py
+++ b/tools/archives/pyvo_integration/astronomical_archives.py
@@ -2,6 +2,7 @@
import functools
import json
import os
+import re
import signal
import sys
import urllib
@@ -507,6 +508,20 @@ def _set_archive(self):
self._archives.append(
TapArchive(access_url=self._service_access_url))
+ elif self._archive_type == 'custom':
+ self._service_access_url = \
+ self._json_parameters['archive_selection']['access_url']
+
+ if Utils.is_valid_url(self._service_access_url):
+ self._archives.append(
+ TapArchive(access_url=self._service_access_url))
+ else:
+ error_message = "archive access url is not a valid url"
+ Logger.create_action_log(
+ Logger.ACTION_ERROR,
+ Logger.ACTION_TYPE_ARCHIVE_CONNECTION,
+ error_message)
+
else:
keyword = \
self._json_parameters['archive_selection']['keyword']
@@ -1305,6 +1320,17 @@ def collect_resource_keys(urls_data: list) -> list:
resource_keys.append(key)
return resource_keys
+ @staticmethod
+ def is_valid_url(url: str) -> bool:
+ regex_url = re.compile(
+ r'^(?:http)s?://'
+ r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
+ r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|)'
+ r'(?::\d+)?'
+ r'(?:/?|[/?]\S+)$', re.IGNORECASE)
+
+ return re.match(regex_url, url) is not None
+
class Logger:
_logs = []
From e81642e96a9af9aa42ca44e4ee8da5d3c93f03ea Mon Sep 17 00:00:00 2001
From: francoismg <46478217+francoismg@users.noreply.github.com>
Date: Tue, 30 Jan 2024 06:31:44 +0100
Subject: [PATCH 2/2] Interface update for custom access url
---
tools/archives/pyvo_integration/astronomical_archives.xml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/archives/pyvo_integration/astronomical_archives.xml b/tools/archives/pyvo_integration/astronomical_archives.xml
index 8f9a6433..bfee40fc 100644
--- a/tools/archives/pyvo_integration/astronomical_archives.xml
+++ b/tools/archives/pyvo_integration/astronomical_archives.xml
@@ -24,6 +24,7 @@
+
@@ -47,6 +48,9 @@
+
+
+