Repository navigation
Closed
Labels
priority: mediumMedium prioritytype: maintenanceRelated to general repository maintenanceworkload: hoursLikely takes hours to resolve
Description
Why?
The code has accumulated duplication and dead code that makes changes such as #62 and #61 larger and riskier than necessary:
- The services collection is looked up with the same three lines (
current_app.config.foca.db.dbs["serviceStore"].collections["services"].client) ingetServices,getServiceById,deleteServiceandRegisterService.__init__, and the service-info collection in the same way inRegisterServiceInfo.__init__. postServiceandputServiceincloud_registry/ga4gh/registry/server.pyare almost identical.getServiceTypesloads all services and deduplicates their types in Python through aset, so the order of the returned types changes between calls.getServiceByIddeletes_idby hand instead of using a projection, unlikegetServices.- Unused code:
import string # noqa: F401inservice.py;ValidationErrorinexceptions.py(only mentioned in a docstring ofset_service_info_from_config, which never raises it);MetaVersionConfigandcustom.endpoints.services.meta_version(configured, never read);RegisterService.was_replaced(set, never read); the config-file existence check inapp.py, which FOCA does anyway. - Module paths only work because
app.pyis run as a script from insidecloud_registry/:custom_config_model="service_models.custom_config.CustomConfig"inapp.py, andx-openapi-router-controller: ga4gh.registry.serverandx-bearerInfoFunc: app.validate_tokeninconfig.yaml. The app cannot be started as an installed package (e.g.python -m cloud_registry.app). - f-strings in logging calls (
app.py,service.py) and Pydantic v1.dict()inservice_info.py.
How?
- Add one helper that returns a collection client by name and use it everywhere.
- Merge the shared logic of
postServiceandputServiceinto one function. - Compute the distinct service types in MongoDB (aggregation or
distinct) and return them in a stable order. - Use projections instead of deleting
_id. - Remove the unused code listed above (including the
meta_versionconfig key, with a note in the changelog). - Use fully qualified module paths (
cloud_registry.service_models.custom_config.CustomConfig,cloud_registry.ga4gh.registry.server,foca.security.auth.validate_token), and start the app withpython -m cloud_registry.appin the Dockerfile. - Use
%-style logging andmodel_dump().
Behavior of the API must not change; the app-level tests from #71 serve as the safety net.
Acceptance criteria
- No duplicated collection lookups or POST/PUT logic remain.
-
GET /services/typesreturns the same order on repeated calls. - The app starts with
python -m cloud_registry.app; Docker and Compose use it. - All tests pass unchanged (apart from tests of removed code).
Dependencies: #71; after #65. Coordinate with #66 (touches the same controllers).
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritytype: maintenanceRelated to general repository maintenanceworkload: hoursLikely takes hours to resolve
Activity
build: fix packaging and bump dev dependencies (#84)
fix: silence mypy on wrapped getServices call