-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #21: implement versioning logic
- Loading branch information
Showing
13 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask import Blueprint | ||
|
||
from .blueprints.monitor import monitor_blueprint | ||
from .blueprints.search import search_blueprint | ||
|
||
VERSION = "1" | ||
|
||
|
||
def get_blueprint(): | ||
bp = Blueprint(VERSION, __name__) | ||
bp.register_blueprint(monitor_blueprint, url_prefix="/health", strict_slashes=False) | ||
bp.register_blueprint(search_blueprint, url_prefix="/search", strict_slashes=False) | ||
return bp |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask import Blueprint | ||
|
||
from .blueprints.monitor import monitor_blueprint | ||
from .blueprints.search import search_blueprint | ||
|
||
VERSION = "2" | ||
|
||
|
||
def get_blueprint(): | ||
bp = Blueprint(VERSION, __name__) | ||
bp.register_blueprint(monitor_blueprint, url_prefix="/health", strict_slashes=False) | ||
bp.register_blueprint(search_blueprint, url_prefix="/search", strict_slashes=False) | ||
return bp |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask import Blueprint | ||
|
||
monitor_blueprint = Blueprint("monitor", __name__) | ||
|
||
|
||
@monitor_blueprint.route("", methods=["GET"]) | ||
def health(): | ||
return "ok", 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from functools import wraps | ||
|
||
from flask import Blueprint, current_app, jsonify, request | ||
from index_search import AzureIndexSearchQueryError, search | ||
|
||
from app.api.common.ailab_db import DBError, ailab_db_search | ||
from app.api.common.finesse_data import FinesseDataFetchException, fetch_data | ||
from app.utils import sanitize | ||
|
||
search_blueprint = Blueprint("finesse", __name__) | ||
|
||
|
||
def require_non_empty_query(f): | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
query = request.json.get("query") | ||
if not query: | ||
return jsonify({"message": current_app.config["ERROR_EMPTY_QUERY"]}), 400 | ||
return f(*args, **kwargs) | ||
|
||
return decorated_function | ||
|
||
|
||
@search_blueprint.route("/azure", methods=["POST"]) | ||
@require_non_empty_query | ||
def search_azure(): | ||
query = request.json["query"] | ||
query = sanitize(query, current_app.config["SANITIZE_PATTERN"]) | ||
try: | ||
results = search(query, current_app.config["AZURE_CONFIG"]) | ||
return jsonify(results) | ||
except AzureIndexSearchQueryError: | ||
return jsonify({"error": current_app.config["ERROR_AZURE_FAILED"]}), 500 | ||
except Exception: | ||
return jsonify({"error": current_app.config["ERROR_UNEXPECTED"]}), 500 | ||
|
||
|
||
@search_blueprint.route("/static", methods=["POST"]) | ||
@require_non_empty_query | ||
def search_static(): | ||
finesse_data_url = current_app.config["FINESSE_DATA_URL"] | ||
query = request.json["query"] | ||
query = sanitize(query, current_app.config["SANITIZE_PATTERN"]) | ||
match_threshold = current_app.config["FUZZY_MATCH_THRESHOLD"] | ||
try: | ||
data = fetch_data(finesse_data_url, query, match_threshold) | ||
return jsonify(data) | ||
except FinesseDataFetchException: | ||
return jsonify({"error": current_app.config["ERROR_FINESSE_DATA_FAILED"]}), 500 | ||
except Exception: | ||
return jsonify({"error": current_app.config["ERROR_UNEXPECTED"]}), 500 | ||
|
||
|
||
@search_blueprint.route("/ailab", methods=["POST"]) | ||
@require_non_empty_query | ||
def search_ailab_db(): | ||
query = request.json["query"] | ||
query = sanitize(query, current_app.config["SANITIZE_PATTERN"]) | ||
try: | ||
results = ailab_db_search(query) | ||
return jsonify(results) | ||
except DBError: | ||
return jsonify({"error": current_app.config["ERROR_AILAB_FAILED"]}), 500 | ||
except Exception: | ||
return jsonify({"error": current_app.config["ERROR_UNEXPECTED"]}), 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters