From d976eeb21fe1c74c1603852f077cae46f2b6391c Mon Sep 17 00:00:00 2001 From: Noah Dove Date: Tue, 25 Apr 2023 17:22:17 -0700 Subject: [PATCH] Fix: Swagger UI for indexer is a stub (#5051) --- lambdas/indexer/app.py | 68 +++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/lambdas/indexer/app.py b/lambdas/indexer/app.py index d1fe5250d7..e06537ea5a 100644 --- a/lambdas/indexer/app.py +++ b/lambdas/indexer/app.py @@ -28,6 +28,7 @@ SignatureHelper, ) from azul.indexer.index_controller import ( + Action, IndexController, ) from azul.indexer.log_forwarding_controller import ( @@ -38,6 +39,14 @@ ) from azul.openapi import ( format_description, + params, + schema, +) +from azul.openapi.responses import ( + json_content, +) +from azul.openapi.spec import ( + AuxSpec, ) log = logging.getLogger(__name__) @@ -46,10 +55,8 @@ 'openapi': '3.0.1', 'info': { 'title': config.indexer_name, - # FIXME: Swagger UI for indexer is a stub - # https://github.com/DataBiosphere/azul/issues/5051 'description': format_description(''' - This is the indexer component for Azul. + This is the internal API for Azul's indexer component. '''), 'version': '1.0' } @@ -103,14 +110,17 @@ def static_resource(file): return app.swagger_resource(file) -@app.route('/openapi', methods=['GET'], cors=True) +aux_spec = AuxSpec(app_name='indexer') + + +@app.route('/openapi', methods=['GET'], cors=True, **aux_spec.openapi()) def openapi(): return Response(status_code=200, headers={'content-type': 'application/json'}, body=app.spec()) -@app.route('/version', methods=['GET'], cors=True) +@app.route('/version', methods=['GET'], cors=True, **aux_spec.version()) def version(): from azul.changelog import ( compact_changes, @@ -121,27 +131,27 @@ def version(): } -@app.route('/health', methods=['GET'], cors=True) +@app.route('/health', methods=['GET'], cors=True, **aux_spec.full_health()) def health(): return app.health_controller.health() -@app.route('/health/basic', methods=['GET'], cors=True) +@app.route('/health/basic', methods=['GET'], cors=True, **aux_spec.basic_health()) def basic_health(): return app.health_controller.basic_health() -@app.route('/health/cached', methods=['GET'], cors=True) +@app.route('/health/cached', methods=['GET'], cors=True, **aux_spec.cached_health()) def cached_health(): return app.health_controller.cached_health() -@app.route('/health/fast', methods=['GET'], cors=True) +@app.route('/health/fast', methods=['GET'], cors=True, **aux_spec.fast_health()) def fast_health(): return app.health_controller.fast_health() -@app.route('/health/{keys}', methods=['GET'], cors=True) +@app.route('/health/{keys}', methods=['GET'], cors=True, **aux_spec.custom_health()) def health_by_key(keys: Optional[str] = None): return app.health_controller.custom_health(keys) @@ -151,7 +161,43 @@ def update_health_cache(_event: chalice.app.CloudWatchEvent): app.health_controller.update_cache() -@app.route('/{catalog}/{action}', methods=['POST']) +@app.route('/{catalog}/{action}', methods=['POST'], method_spec={ + 'tags': ['Indexing'], + 'summary': 'Notify the indexer to perform an action on a bundle', + 'requestBody': { + 'description': 'Contents of the notification', + 'required': True, + **json_content(schema.object( + match=schema.object( + bundle_uuid=str, + bundle_version=str + ), + source=schema.object( + id=str, + spec=str + ) + )) + }, + 'parameters': [ + params.path('catalog', + schema.enum(*config.catalogs), + description='The name of the catalog to notify.'), + params.path('action', + schema.enum(Action.add.name, Action.delete.name), + description='Which action to perform.'), + ], + 'responses': { + '200': { + 'description': 'Notification was successfully queued for processing' + }, + '400': { + 'description': 'Request was rejected due to malformed parameters' + }, + '401': { + 'description': 'Request lacked a valid HMAC header' + } + } +}) def post_notification(catalog: CatalogName, action: str): """ Receive a notification event and queue it for indexing or deletion.