From 1351c8f724a813c439ec352beacccd496df3a9e1 Mon Sep 17 00:00:00 2001 From: Bruce Martin Date: Sun, 22 Mar 2020 09:23:28 -0600 Subject: [PATCH] restrict methods on all endpoints (#1271) * restrict methods on all endpoints * lint --- server/app/app.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/server/app/app.py b/server/app/app.py index 260bc9ae..03e2bb95 100644 --- a/server/app/app.py +++ b/server/app/app.py @@ -22,7 +22,7 @@ from functools import wraps webbp = Blueprint("webapp", "server.common.web", template_folder="templates") -@webbp.route("/") +@webbp.route("/", methods=["GET"]) def dataset_index(dataset=None): config = current_app.app_config if dataset is None: @@ -44,12 +44,12 @@ def dataset_index(dataset=None): return make_response(f"Invalid dataset {dataset}: {str(e)}", HTTPStatus.BAD_REQUEST) -@webbp.route("/favicon.png") +@webbp.route("/favicon.png", methods=["GET"]) def favicon(): return send_from_directory(os.path.join(webbp.root_path, "static/img/"), "favicon.png") -@webbp.route("/health") +@webbp.route("/health", methods=["GET"]) def health(): config = current_app.app_config return health_check(config) @@ -95,8 +95,8 @@ def static_redirect(dataset, therest): def dataroot_test_index(): # the following index page is meant for testing/debugging purposes data = '' - data += 'Hosted Cellxgene' - data += '

Welcome to cellxgene

' + data += "Hosted Cellxgene" + data += "

Welcome to cellxgene

" try: config = current_app.app_config @@ -111,16 +111,16 @@ def dataroot_test_index(): # skip over invalid datasets pass - data += '
Select one of these datasets...
' - data += '" except Exception as e: - data += f'
Unable to locate datasets from {config.dataroot}: {str(e)}' + data += f"
Unable to locate datasets from {config.dataroot}: {str(e)}" - data += '' + data += "" return make_response(data) @@ -234,8 +234,10 @@ class Server: bp_api = Blueprint("api_dataset", __name__, url_prefix="/" + api_version) resources = get_api_resources(bp_api) self.app.register_blueprint(resources.blueprint) - self.app.add_url_rule("//", "dataset_index", dataset_index) - self.app.add_url_rule("//static/", "static_redirect", static_redirect) + self.app.add_url_rule("//", "dataset_index", dataset_index, methods=["GET"]) + self.app.add_url_rule( + "//static/", "static_redirect", static_redirect, methods=["GET"] + ) self.app.matrix_data_cache_manager = matrix_data_cache_manager self.app.annotations = annotations