Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve config #42

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
9 changes: 5 additions & 4 deletions drs_filer/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 11 additions & 8 deletions drs_filer/ga4gh/drs/endpoints/register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ 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
was_replaced = False
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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions drs_filer/ga4gh/drs/endpoints/service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
12 changes: 7 additions & 5 deletions tests/ga4gh/drs/endpoints/test_register_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}


Expand Down Expand Up @@ -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),
Expand Down
10 changes: 6 additions & 4 deletions tests/ga4gh/drs/endpoints/test_service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions tests/ga4gh/drs/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions update-config-map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down