From 534b04c46087914b14195f537019a00489bcf32b Mon Sep 17 00:00:00 2001 From: Tasko Olevski Date: Wed, 10 Feb 2021 13:22:41 +0100 Subject: [PATCH] fix: do not check defaultUrl against list of server options (#542) * fix: allow any values in default url server options, not just fixed choices --- renku_notebooks/__init__.py | 3 +++ renku_notebooks/api/custom_fields.py | 1 + renku_notebooks/api/schemas.py | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/renku_notebooks/__init__.py b/renku_notebooks/__init__.py index ad1bef245..e5d64617c 100644 --- a/renku_notebooks/__init__.py +++ b/renku_notebooks/__init__.py @@ -91,6 +91,9 @@ def create_app(): def handle_error(err): headers = err.data.get("headers", None) messages = err.data.get("messages", {"error": "Invalid request."}) + app.logger.warning( + f"Validation of request parameters failed with the messages: {messages}" + ) if headers: return jsonify({"messages": messages}), err.code, headers else: diff --git a/renku_notebooks/api/custom_fields.py b/renku_notebooks/api/custom_fields.py index 3a86d9ee0..9e02d8cc9 100644 --- a/renku_notebooks/api/custom_fields.py +++ b/renku_notebooks/api/custom_fields.py @@ -59,3 +59,4 @@ def _deserialize( is not None, required=True, ) +serverOptionUrlValue = fields.Str(required=True) diff --git a/renku_notebooks/api/schemas.py b/renku_notebooks/api/schemas.py index a86417b99..9f620f3b7 100644 --- a/renku_notebooks/api/schemas.py +++ b/renku_notebooks/api/schemas.py @@ -13,12 +13,13 @@ from .custom_fields import ( serverOptionCpuValue, serverOptionMemoryValue, + serverOptionUrlValue, ) from ..util.misc import read_server_options_file class LaunchNotebookRequestServerOptions(Schema): - defaultUrl = fields.String(required=True) + defaultUrl = serverOptionUrlValue cpu_request = serverOptionCpuValue mem_request = serverOptionMemoryValue lfs_auto_fetch = fields.Bool(required=True) @@ -30,6 +31,8 @@ def validate_server_options(self, data, **kwargs): for option in data.keys(): if option not in server_options.keys(): continue # presence of option keys are already handled by marshmallow + if option == "defaultUrl": + continue # the defaultUrl field should not be limited to only server options if server_options[option]["type"] == "boolean": continue # boolean options are already validated by marshmallow if data[option] not in server_options[option]["options"]: @@ -214,6 +217,15 @@ class ServerOptionString(ServerOptionBase): ) +class ServerOptionUrl(ServerOptionBase): + """The schema used to describe a single option for the server_options endpoint.""" + + default = serverOptionUrlValue + options = fields.List( + serverOptionUrlValue, validate=lambda x: len(x) >= 1, required=True + ) + + class ServerOptionBool(ServerOptionBase): """The schema used to describe a single option for the server_options endpoint.""" @@ -227,7 +239,7 @@ class ServerOptions(Schema): """ cpu_request = fields.Nested(ServerOptionCpu(), required=True) - defaultUrl = fields.Nested(ServerOptionString(), required=True) + defaultUrl = fields.Nested(ServerOptionUrl(), required=True) gpu_request = fields.Nested(ServerOptionGpu()) lfs_auto_fetch = fields.Nested(ServerOptionBool(), required=True) mem_request = fields.Nested(ServerOptionMemory(), required=True)