diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 9cab370..8008bb9 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -53,7 +53,7 @@ jobs: if: matrix.dependencies == 'conda' run: | set -vxeo pipefail - conda install -y -c conda-forge six mongoquery doct jsonschema mock pymongo pytest pyyaml requests tornado ujson + conda install -y -c conda-forge six mongoquery doct jsonschema mock pymongo pytest pyyaml requests tornado ujson 'setuptools<81' pip install mongomock - name: Install the package diff --git a/analysisstore/client/commands.py b/analysisstore/client/commands.py index caf94ea..1ca34bb 100644 --- a/analysisstore/client/commands.py +++ b/analysisstore/client/commands.py @@ -13,7 +13,10 @@ class AnalysisClient: """Client used to pass messages between analysisstore server and apps""" def __init__(self, config): self.host = config['host'] - self.port = config['port'] + self.port = config.get('port') + self.use_ssl = config.get('use_ssl', False) + if self.port is None and not self.use_ssl: + raise KeyError("at least one of port or use_ssl must be defined") self._insert_dict = {'analysis_header': self.insert_analysis_header, 'analysis_tail': self.insert_analysis_tail, 'data_reference_header': self.insert_data_reference_header, @@ -27,7 +30,11 @@ def __init__(self, config): @property def _host_url(self): """URL to the tornado instance""" - return 'http://{}:{}/'.format(self.host, self.port) + if not self.use_ssl: # if not using ssl, connect to specified port + url = 'http://{}:{}/'.format(self.host, self.port) + else: # if using ssl, just use https protocol + url = f'https://{self.host}/' + return url @property def aheader_url(self): diff --git a/analysisstore/client/conf.py b/analysisstore/client/conf.py index c655fc4..caacddd 100644 --- a/analysisstore/client/conf.py +++ b/analysisstore/client/conf.py @@ -1,5 +1,6 @@ host = 'localhost' port = 8999 +use_ssl = False -top_dir = '~/analysisstore' \ No newline at end of file +top_dir = '~/analysisstore' diff --git a/analysisstore/test/conftest.py b/analysisstore/test/conftest.py index 655b565..23e113f 100644 --- a/analysisstore/test/conftest.py +++ b/analysisstore/test/conftest.py @@ -18,6 +18,7 @@ mongo_host="localhost", mongo_port=27017, testing=True, + use_ssl=True, log_file_prefix="testing", ) @@ -47,3 +48,14 @@ def astore_client(): {"host": testing_config["mongo_host"], "port": testing_config["service_port"]} ) return c + +@pytest.fixture(scope="function") +def astore_client_ssl(): + c = AnalysisClient( + { + "host": testing_config["host"], + "use_ssl": testing_config["use_ssl"], + "port": testing_config["port"], + } + ) + return c diff --git a/analysisstore/test/test_client.py b/analysisstore/test/test_client.py index e4cf615..492b3fc 100644 --- a/analysisstore/test/test_client.py +++ b/analysisstore/test/test_client.py @@ -26,6 +26,15 @@ def test_urls(astore_client): astore_client.dref_header_url == base_test_url + "data_reference_header" +def test_ssl(astore_client_ssl): + base_test_url = f"https://{astore_client_ssl.host}/" + assert astore_client_ssl._host_url == base_test_url + assert astore_client_ssl.aheader_url == base_test_url + "analysis_header" + assert astore_client_ssl.atail_url == base_test_url + "analysis_tail" + assert astore_client_ssl.dref_url == base_test_url + "data_reference" + assert astore_client_ssl.dref_header_url == base_test_url + "data_reference_header" + + def test_doc_or_uid_to_uid(astore_server, astore_client): m_uid = str(uuid.uuid4()) test_dict = {"name": "test_doc", "uid": m_uid} diff --git a/analysisstore/test/test_conn_pool.py b/analysisstore/test/test_conn_pool.py index 7d18207..74bfffe 100644 --- a/analysisstore/test/test_conn_pool.py +++ b/analysisstore/test/test_conn_pool.py @@ -7,6 +7,5 @@ def test_client_badconf(): config = {"host": "localhost"} pytest.raises(KeyError, AnalysisClient, config) config["port"] = testing_config["port"] - conn = AnalysisClient(config) - conn.host == testing_config["host"] - conn.port == testing_config["port"] + config["use_ssl"] = testing_config["use_ssl"] + client = AnalysisClient(config) diff --git a/requirements.txt b/requirements.txt index 45dbdec..25f5773 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pyyaml requests tornado ujson +setuptools<81