diff --git a/docs/swagger-schema.yaml b/docs/swagger-schema.yaml index fec458187d8cb872c6cf4897a10818dc7f151b2d..1b7b7632c665239e19c48e36e6dc9283af605643 100644 --- a/docs/swagger-schema.yaml +++ b/docs/swagger-schema.yaml @@ -633,6 +633,10 @@ paths: summary: "Get a valid CASA version for processing" description: "Get a valid CASA version for processing, providing the optional parameters will filter the version" operationId: "get_casa_version" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "No CASA version found" @@ -651,6 +655,10 @@ paths: summary: "Get a list of valid CASA versions for processing" description: "Get a list of valid CASA versions for processing, providing the optional parameters will filter the versions" operationId: "get_casa_versions" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "No CASA versions found" @@ -667,6 +675,10 @@ paths: summary: "Get a CASA recipe for processing the given capability" description: "Get a valid CASA recipe for processing the given capability" operationId: "get_casa_recipe" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "No CASA recipe found" @@ -685,6 +697,10 @@ paths: summary: "Add a CASA version to the matrix tables" description: "Add a CASA version to the matrix tables to enable for the given capability list" operationId: "add_casa_version" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "CASA version not added" @@ -698,6 +714,10 @@ paths: summary: "Update a CASA version in the matrix tables" description: "Update a CASA version in the matrix tables to enable for the given capability list" operationId: "update_casa_version" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "CASA version not updated" @@ -711,6 +731,10 @@ paths: summary: "Delete a CASA version from the matrix tables" description: "Delete a CASA version from the matrix tables" operationId: "delete_casa_version" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "CASA version not deleted" @@ -725,6 +749,10 @@ paths: summary: "Refresh the links of installed CASA versions" description: "Refresh the links of installed CASA versions, existing links will be replaced for this environment" operationId: "make_casa_links" + consumes: + - "application/json" + produces: + - "application/json" responses: 404: description: "Links not refreshed" @@ -1497,36 +1525,41 @@ parameters: required: true casa-version: name: "version" - in: query + in: body description: "CASA version" - type: "string" required: false + schema: + type: string casa-capability: name: "capability" - in: query + in: body description: "Capability to filter CASA versions" - type: "string" required: false + schema: + type: string casa-capabilities: name: "capabilities" - in: query + in: body description: "Capability list" - type: "array" - items: - type: "string" + schema: + type: array + items: + type: string required: false casa-telescope: name: "telescope" - in: query + in: body description: "Telescope to filter CASA versions" - type: "string" required: false + schema: + type: string casa-compatible: name: "is_cluster_compatible" - in: query + in: body description: "Flag to signal if version is cluster compatible" - type: boolean required: false + schema: + type: boolean externalDocs: description: "More about the capability service" diff --git a/services/capability/capability/views/casa_matrix.py b/services/capability/capability/views/casa_matrix.py index bfb51699f35ca67f3149f40d9fefed739ac0e0a3..68d66e4b42fbdf7339b9465a133d253354abf82f 100644 --- a/services/capability/capability/views/casa_matrix.py +++ b/services/capability/capability/views/casa_matrix.py @@ -21,7 +21,7 @@ File containing definitions for the casa_matrix routes of the Workspaces REST AP import http -from pyramid.httpexceptions import HTTPNotFound +from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound from pyramid.request import Request from pyramid.response import Response from pyramid.view import view_config @@ -36,17 +36,18 @@ def get_casa_version(request: Request) -> Response: :return: Response containing the CASA version and path or a 404 response (HTTPNotFound) if one isn't returned """ + body = request.json_body params = { - "version": request.params["version"] if "version" in request.params else None, - "capability": request.params["capability"] if "capability" in request.params else None, - "telescope": request.params["telescope"] if "telescope" in request.params else None, + "version": body["version"] if "version" in body else None, + "capability": body["capability"] if "capability" in body else None, + "telescope": body["telescope"] if "telescope" in body else None, } params = {k: v for k, v in params.items() if v is not None} casa_version = request.casa_matrix_service.get_version(**params) if casa_version: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{casa_version}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=casa_version) else: return HTTPNotFound(detail=f"No CASA version found.") @@ -60,17 +61,18 @@ def get_casa_versions(request: Request) -> Response: :return: Response containing a list of CASA versions and their paths or a 404 response (HTTPNotFound) if none are returned """ + body = request.json_body params = { - "version": request.params["version"] if "version" in request.params else None, - "capability": request.params["capability"] if "capability" in request.params else None, - "telescope": request.params["telescope"] if "telescope" in request.params else None, + "version": body["version"] if "version" in body else None, + "capability": body["capability"] if "capability" in body else None, + "telescope": body["telescope"] if "telescope" in body else None, } params = {k: v for k, v in params.items() if v is not None} casa_versions = request.casa_matrix_service.get_versions(**params) if casa_versions: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{casa_versions}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=casa_versions) else: return HTTPNotFound(detail=f"No CASA versions found.") @@ -84,10 +86,10 @@ def get_casa_recipe(request: Request) -> Response: :return: Response containing the CASA recipe or a 404 response (HTTPNotFound) if one isn't returned """ - casa_recipe = request.casa_matrix_service.get_recipe(request.params["capability"]) + casa_recipe = request.casa_matrix_service.get_recipe(request.json_body["capability"]) if casa_recipe: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{casa_recipe}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=casa_recipe) else: return HTTPNotFound(detail=f"No CASA recipe found.") @@ -101,17 +103,23 @@ def add_casa_version(request: Request) -> Response: :return: Response containing true if the new matrix version was added or a 404 response (HTTPNotFound) if one isn't added """ - added = request.casa_matrix_service.add_version( - version=request.params["version"], - capabilities=request.params["capabilities"].split(",") if "capabilities" in request.params else [], - is_cluster_compatible=False - if "is_cluster_compatible" in request.params - and request.params["is_cluster_compatible"].lower() in ["0", "false"] - else True, - ) + body = request.json_body + + if "version" not in body: + return HTTPBadRequest(detail=f"CASA version not given") + + if "capabilities" in body and not isinstance(body["capabilities"], list): + return HTTPBadRequest(detail=f"Capabilities given aren't a valid list") + + params = { + "version": body["version"], + "capabilities": body["capabilities"] if "capabilities" in body else [], + "is_cluster_compatible": False if "is_cluster_compatible" in body and body["is_cluster_compatible"].lower() in ["0", "false"] else True, + } + added = request.casa_matrix_service.add_version(**params) if added: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{added}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=added) else: return HTTPNotFound(detail=f"Matrix version not added") @@ -125,17 +133,23 @@ def update_casa_version(request: Request) -> Response: :return: Response containing true if the matrix version was updated or a 404 response (HTTPNotFound) if one isn't updated """ - updated = request.casa_matrix_service.update_version( - version=request.params["version"], - capabilities=request.params["capabilities"].split(",") if "capabilities" in request.params else [], - is_cluster_compatible=False - if "is_cluster_compatible" in request.params - and request.params["is_cluster_compatible"].lower() in ["0", "false"] - else True, - ) + body = request.json_body + + if "version" not in body: + return HTTPBadRequest(detail=f"CASA version not given") + + if "capabilities" in body and not isinstance(body["capabilities"], list): + return HTTPBadRequest(detail=f"Capabilities given aren't a valid list") + + params = { + "version": body["version"], + "capabilities": body["capabilities"] if "capabilities" in body else [], + "is_cluster_compatible": False if "is_cluster_compatible" in body and body["is_cluster_compatible"].lower() in ["0", "false"] else True, + } + updated = request.casa_matrix_service.update_version(**params) if updated: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{updated}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=updated) else: return HTTPNotFound(detail=f"Matrix version not updated") @@ -149,10 +163,15 @@ def delete_casa_version(request: Request) -> Response: :return: Response containing true if version was deleted from the matrix or a 404 response (HTTPNotFound) if one isn't deleted """ - deleted = request.casa_matrix_service.delete_version(request.params["version"]) + body = request.json_body + + if "version" not in body: + return HTTPBadRequest(detail=f"CASA version not given") + + deleted = request.casa_matrix_service.delete_version(body["version"]) if deleted: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{deleted}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=deleted) else: return HTTPNotFound(detail=f"Matrix version not deleted") @@ -169,6 +188,6 @@ def make_casa_links(request: Request) -> Response: found_versions = request.casa_matrix_service.make_links() if found_versions: - return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{found_versions}"}) + return Response(status_int=http.HTTPStatus.OK, json_body=found_versions) else: return HTTPNotFound(detail=f"CASA links not updated")