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 = [] 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 @@ + + +