From cc29c610656ed48fe0d7e1eb5bd60c78b813b075 Mon Sep 17 00:00:00 2001 From: Sarthak Gupta Date: Sat, 19 Jun 2021 11:35:28 +0530 Subject: [PATCH] refactor: improve config --- drs_filer/config.yaml | 9 +++++---- .../ga4gh/drs/endpoints/register_objects.py | 19 +++++++++++-------- drs_filer/ga4gh/drs/endpoints/service_info.py | 8 ++++---- .../drs/endpoints/test_register_objects.py | 12 +++++++----- .../ga4gh/drs/endpoints/test_service_info.py | 10 ++++++---- tests/ga4gh/drs/test_server.py | 10 ++++++---- update-config-map.sh | 6 +++--- 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/drs_filer/config.yaml b/drs_filer/config.yaml index 09c1e20..28ccdaa 100644 --- a/drs_filer/config.yaml +++ b/drs_filer/config.yaml @@ -88,7 +88,8 @@ endpoints: updatedAt: "2020-01-01" environment: "ENV" version: "0.0.0" - url_prefix: http - external_host: 193.166.24.114 - external_port: 8080 - api_path: ga4gh/drs/v1 + service: + url_prefix: http + external_host: 193.166.24.114 + external_port: 8080 + api_path: ga4gh/drs/v1 diff --git a/drs_filer/ga4gh/drs/endpoints/register_objects.py b/drs_filer/ga4gh/drs/endpoints/register_objects.py index da2d79b..1ef5742 100644 --- a/drs_filer/ga4gh/drs/endpoints/register_objects.py +++ b/drs_filer/ga4gh/drs/endpoints/register_objects.py @@ -35,10 +35,12 @@ def register_object( current_app.config['FOCA'].db.dbs['drsStore']. collections['objects'].client ) - url_prefix = current_app.config['FOCA'].endpoints['url_prefix'] - external_host = current_app.config['FOCA'].endpoints['external_host'] - external_port = current_app.config['FOCA'].endpoints['external_port'] - api_path = current_app.config['FOCA'].endpoints['api_path'] + conf = current_app.config['FOCA'].endpoints + + url_prefix = conf['service']['url_prefix'] + external_host = conf['service']['external_host'] + external_port = conf['service']['external_port'] + api_path = conf['service']['api_path'] # Set flags and parameters for POST/PUT routes replace = True @@ -46,10 +48,10 @@ def register_object( if object_id is None: replace = False id_length = ( - current_app.config['FOCA'].endpoints['objects']['id_length'] + conf['objects']['id_length'] ) id_charset: str = ( - current_app.config['FOCA'].endpoints['objects']['id_charset'] + conf['objects']['id_charset'] ) # evaluate character set expression or interpret literal string as set try: @@ -120,11 +122,12 @@ def __add_access_ids(data: List) -> List: Returns: Access methods metadata complete with unique access identifiers. """ + conf = current_app.config['FOCA'].endpoints id_charset = eval( - current_app.config['FOCA'].endpoints['access_methods']['id_charset'] + conf['access_methods']['id_charset'] ) id_length = ( - current_app.config['FOCA'].endpoints['access_methods']['id_length'] + conf['access_methods']['id_length'] ) access_ids = [] for method in data: diff --git a/drs_filer/ga4gh/drs/endpoints/service_info.py b/drs_filer/ga4gh/drs/endpoints/service_info.py index 3c13f5f..1077353 100644 --- a/drs_filer/ga4gh/drs/endpoints/service_info.py +++ b/drs_filer/ga4gh/drs/endpoints/service_info.py @@ -35,10 +35,10 @@ def __init__(self) -> None: conf_info: Service info details as per enpoints config. """ conf = current_app.config['FOCA'].endpoints - self.url_prefix = conf['url_prefix'] - self.host_name = conf['external_host'] - self.external_port = conf['external_port'] - self.api_path = conf['api_path'] + self.url_prefix = conf['service']['url_prefix'] + self.host_name = conf['service']['external_host'] + self.external_port = conf['service']['external_port'] + self.api_path = conf['service']['api_path'] self.conf_info = conf['service_info'] self.db_coll_info = ( current_app.config['FOCA'].db.dbs['drsStore'] diff --git a/tests/ga4gh/drs/endpoints/test_register_objects.py b/tests/ga4gh/drs/endpoints/test_register_objects.py index b4057b1..693bc42 100644 --- a/tests/ga4gh/drs/endpoints/test_register_objects.py +++ b/tests/ga4gh/drs/endpoints/test_register_objects.py @@ -38,10 +38,12 @@ "id_charset": 'string.digits', "id_length": 6 }, - "url_prefix": "http", - "external_host": "1.2.3.4", - "external_port": 8080, - "api_path": "ga4gh/drs/v1" + "service": { + "url_prefix": "http", + "external_host": "1.2.3.4", + "external_port": 8080, + "api_path": "ga4gh/drs/v1" + } } @@ -70,7 +72,7 @@ def test_register_object_invalid_config(): """ app = Flask(__name__) endpoint_config = deepcopy(ENDPOINT_CONFIG) - del endpoint_config['url_prefix'] + del endpoint_config['service']['url_prefix'] app.config['FOCA'] = \ Config( db=MongoConfig(**MONGO_CONFIG), diff --git a/tests/ga4gh/drs/endpoints/test_service_info.py b/tests/ga4gh/drs/endpoints/test_service_info.py index 3993458..a2b05cc 100644 --- a/tests/ga4gh/drs/endpoints/test_service_info.py +++ b/tests/ga4gh/drs/endpoints/test_service_info.py @@ -68,10 +68,12 @@ "id_length": 6 }, "service_info": deepcopy(SERVICE_INFO_CONFIG), - "url_prefix": "http", - "external_host": "1.2.3.4", - "external_port": 8080, - "api_path": "ga4gh/drs/v1" + "service": { + "url_prefix": "http", + "external_host": "1.2.3.4", + "external_port": 8080, + "api_path": "ga4gh/drs/v1" + } } SERVICE_CONFIG = { "url_prefix": "http", diff --git a/tests/ga4gh/drs/test_server.py b/tests/ga4gh/drs/test_server.py index 777cafa..32e962b 100644 --- a/tests/ga4gh/drs/test_server.py +++ b/tests/ga4gh/drs/test_server.py @@ -83,10 +83,12 @@ "id_length": 6 }, "service_info": deepcopy(SERVICE_INFO_CONFIG), - "url_prefix": "http", - "external_host": "1.2.3.4", - "external_port": 8080, - "api_path": "ga4gh/drs/v1" + "service": { + "url_prefix": "http", + "external_host": "1.2.3.4", + "external_port": 8080, + "api_path": "ga4gh/drs/v1" + } } data_objects_path = "tests/data_objects.json" diff --git a/update-config-map.sh b/update-config-map.sh index 3f71848..7ce3c8a 100755 --- a/update-config-map.sh +++ b/update-config-map.sh @@ -31,9 +31,9 @@ echo "Current Kubernetes namespace: $NAMESPACE"; echo echo " * Getting current default configuration" APP_CONFIG=$(yq --arg HOST_NAME "$HOST_NAME" \ - '.endpoints.url_prefix = "https" | - .endpoints.external_host = $HOST_NAME | - .endpoints.external_port = 443' \ + '.endpoints.service.url_prefix = "https" | + .endpoints.service.external_host = $HOST_NAME | + .endpoints.service.external_port = 443' \ "$APP_CONFIG_PATH") || exit 4 echo " * Getting current configMap"