diff --git a/dbrepo-metadata-db/setup-schema.sql b/dbrepo-metadata-db/setup-schema.sql index e9d96b7151b4584c518595ed43c7c3fc21070bb6..0c281ba9a05a807e812a4278775ec3869a770f8b 100644 --- a/dbrepo-metadata-db/setup-schema.sql +++ b/dbrepo-metadata-db/setup-schema.sql @@ -279,10 +279,8 @@ CREATE TABLE IF NOT EXISTS `mdb_concepts` name VARCHAR(255) null, description TEXT null, created timestamp NOT NULL DEFAULT NOW(), - created_by character varying(36) NOT NULL, PRIMARY KEY (id), - UNIQUE (uri(200)), - FOREIGN KEY (created_by) REFERENCES mdb_users (id) + UNIQUE (uri(200)) ) WITH SYSTEM VERSIONING; CREATE TABLE IF NOT EXISTS `mdb_units` @@ -292,10 +290,8 @@ CREATE TABLE IF NOT EXISTS `mdb_units` name VARCHAR(255) null, description TEXT null, created timestamp NOT NULL DEFAULT NOW(), - created_by character varying(36) NOT NULL, PRIMARY KEY (id), - UNIQUE (uri(200)), - FOREIGN KEY (created_by) REFERENCES mdb_users (id) + UNIQUE (uri(200)) ) WITH SYSTEM VERSIONING; CREATE TABLE IF NOT EXISTS `mdb_columns_concepts` diff --git a/dbrepo-search-service/Dockerfile b/dbrepo-search-service/Dockerfile index bbe8d7710bcff8a579537d469d8c086acbf25e14..5474f0500e79e0ee8ae02fa418413b2e5da60830 100644 --- a/dbrepo-search-service/Dockerfile +++ b/dbrepo-search-service/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10-alpine -RUN adduser -D alpine +RUN apk add bash curl && adduser -D alpine WORKDIR /home/alpine @@ -12,6 +12,7 @@ RUN pip install pipenv && \ COPY ./app ./app COPY ./scripts ./scripts +COPY ./us-yml ./us-yml COPY config.py wsgi.py ./ ENV FLASK_APP=wsgi.py diff --git a/dbrepo-search-service/app/__init__.py b/dbrepo-search-service/app/__init__.py index 72c4679c9d1c5ab13e148302db7164bdff98cee6..014b475338d3348e16121bcc75b487129cef5df7 100644 --- a/dbrepo-search-service/app/__init__.py +++ b/dbrepo-search-service/app/__init__.py @@ -2,7 +2,7 @@ import os import logging -from flasgger import LazyJSONEncoder +from flasgger import LazyJSONEncoder, Swagger from flask import Flask from opensearchpy import OpenSearch from config import Config @@ -41,7 +41,55 @@ def create_app(config_class=Config): metrics = PrometheusMetrics(app) metrics.info("app_info", "Application info", version="0.0.1") - app.config["SWAGGER"] = {"openapi": "3.0.0", "title": "Swagger UI", "uiversion": 3} + app.config["SWAGGER"] = {"openapi": "3.0.1", "title": "Swagger UI", "uiversion": 3} + + swagger_config = { + "headers": [], + "specs": [ + { + "endpoint": "api-search", + "route": "/api-search.json", + "rule_filter": lambda rule: rule.endpoint.startswith('actuator'), + "model_filter": lambda tag: True, # all in + } + ], + "static_url_path": "/flasgger_static", + "swagger_ui": True, + "specs_route": "/swagger-ui/", + } + + template = { + "openapi": "3.0.0", + "info": { + "title": "Database Repository Search Service API", + "description": "Service that searches the search database", + "version": "1.3.0", + "contact": { + "name": "Prof. Andreas Rauber", + "email": "andreas.rauber@tuwien.ac.at" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + }, + }, + "externalDocs": { + "description": "Sourcecode Documentation", + "url": "https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services" + }, + "servers": [ + { + "url": "http://localhost:4000", + "description": "Generated server url" + }, + { + "url": "https://test.dbrepo.tuwien.ac.at", + "description": "Sandbox" + } + ] + } + + swagger = Swagger(app, config=swagger_config, template=template) # https://flask-jwt-extended.readthedocs.io/en/stable/options/ app.config["JWT_ALGORITHM"] = "HS256" app.config["JWT_DECODE_ISSUER"] = os.getenv("JWT_ISSUER") diff --git a/dbrepo-search-service/app/api/__init__.py b/dbrepo-search-service/app/api/__init__.py index f799e8b52597d4a175efba2506b8c65107ddf696..256d62b9bf6eb3a1ec44a1db94d9779289e7a3d0 100644 --- a/dbrepo-search-service/app/api/__init__.py +++ b/dbrepo-search-service/app/api/__init__.py @@ -1,5 +1,5 @@ from flask import Blueprint -api_bp = Blueprint("api", __name__, url_prefix="/api/search") +api_bp = Blueprint("api", __name__) from app.api import routes diff --git a/dbrepo-search-service/app/api/routes.py b/dbrepo-search-service/app/api/routes.py index 48625f6f2d76a2e4b120ce5713fe4d155966150c..695e50e0430c93a2b812a68173d44d08e59afdb6 100644 --- a/dbrepo-search-service/app/api/routes.py +++ b/dbrepo-search-service/app/api/routes.py @@ -56,7 +56,13 @@ def general_filter(index, results): return results -@api_bp.route("<string:index>", methods=["GET"], endpoint="endpoint") +@api_bp.route("/health", methods=["GET"], endpoint="actuator_health") +@swag_from("us-yml/get_health") # ToDo: get the SWAG right +def health(): + return {"status": "UP"} + + +@api_bp.route("/api/search/<string:index>", methods=["GET"], endpoint="search_get_index") @swag_from("us-yml") # ToDo: get the SWAG right def get_index(index): """ @@ -87,11 +93,11 @@ def get_index(index): results_per_page = min(request.args.get("results_per_page", 50, type=int), 500) max_pages = math.ceil(len(results) / results_per_page) page = min(request.args.get("page", 1, type=int), max_pages) - results = results[(results_per_page * (page - 1)) : (results_per_page * page)] + results = results[(results_per_page * (page - 1)): (results_per_page * page)] return {"results": results, "total": total_number_of_results, "status": 200} -@api_bp.route("<string:index>/fields", methods=["GET"], endpoint="blabla") +@api_bp.route("/api/search/<string:index>/fields", methods=["GET"], endpoint="search_get_index_fields") def get_fields(index): """ returns a list of attributes of the data for a specific index. @@ -120,7 +126,7 @@ def get_fields(index): return {"fields": fields, "status": 200} -@api_bp.route("", methods=["POST"], endpoint="endpoint2") +@api_bp.route("/api/search", methods=["POST"], endpoint="search_fuzzy_search") def search(): """ Main endpoint for general searching. diff --git a/dbrepo-search-service/us-yml/get_health.yml b/dbrepo-search-service/us-yml/get_health.yml new file mode 100644 index 0000000000000000000000000000000000000000..a4b273a2bf739abc5385a1ba1bce5c0ebafef1aa --- /dev/null +++ b/dbrepo-search-service/us-yml/get_health.yml @@ -0,0 +1,24 @@ +summary: Return a healthcheck +description: | + Return UP if the instance is ready to serve connections. +consumes: + - application/json +produces: + - application/json +parameters: [] +definitions: + Health: + type: object + properties: + status: + type: string + description: UP +responses: + 200: + description: OK, service is up and running + schema: + $ref: "#/definitions/Column" + 404: + description: Service is not yet ready +tags: + - actuator \ No newline at end of file