Skip to content

Commit

Permalink
fix: do not check defaultUrl against list of server options (#542)
Browse files Browse the repository at this point in the history
* fix: allow any values in default url server options, not just fixed choices
  • Loading branch information
olevski committed Feb 10, 2021
1 parent 123bafd commit 534b04c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions renku_notebooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions renku_notebooks/api/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ def _deserialize(
is not None,
required=True,
)
serverOptionUrlValue = fields.Str(required=True)
16 changes: 14 additions & 2 deletions renku_notebooks/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]:
Expand Down Expand Up @@ -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."""

Expand All @@ -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)
Expand Down

0 comments on commit 534b04c

Please sign in to comment.