Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions analysisstore/client/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
if self.port is None and self.use_ssl in (None, False):
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,
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion analysisstore/client/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

host = 'localhost'
port = 8999
use_ssl = False

top_dir = '~/analysisstore'
top_dir = '~/analysisstore'
9 changes: 9 additions & 0 deletions analysisstore/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
mongo_host="localhost",
mongo_port=27017,
testing=True,
use_ssl=True,
log_file_prefix="testing",
)

Expand Down Expand Up @@ -47,3 +48,11 @@ 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["mongo_host"], "use_ssl": testing_config["use_ssl"],
"port": testing_config["port"]}
)
return c
9 changes: 9 additions & 0 deletions analysisstore/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://{testing_config['host']}/"
astore_client_ssl._host_url == base_test_url
astore_client_ssl.aheader_url == base_test_url + "analysis_header"
astore_client_ssl.atail_url == base_test_url + "analysis_tail"
astore_client_ssl.dref_url == base_test_url + "data_reference"
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}
Expand Down
5 changes: 2 additions & 3 deletions analysisstore/test/test_conn_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)