Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make all api fields snake-case #1780

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion renku_notebooks/api/classes/server_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def server_options(self) -> Dict[str, Any]:
js = self.manifest
server_options = {}
# url
server_options["defaultUrl"] = js["spec"]["jupyterServer"]["defaultUrl"]
server_options["default_url"] = js["spec"]["jupyterServer"]["defaultUrl"]
# disk
server_options["disk_request"] = js["spec"]["storage"].get("size")
# NOTE: Amalthea accepts only strings for disk request, but k8s allows bytes as number
Expand Down
8 changes: 4 additions & 4 deletions renku_notebooks/api/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def version():
{
"version": config.version,
"data": {
"anonymousSessionsEnabled": config.anonymous_sessions_enabled,
"cloudstorageEnabled": config.cloud_storage.enabled,
"cloudstorageClass": config.cloud_storage.storage_class,
"anonymous_sessions_enabled": config.anonymous_sessions_enabled,
"cloudstorage_enabled": config.cloud_storage.enabled,
"cloudstorage_class": config.cloud_storage.storage_class,
"sshEnabled": config.ssh_enabled,
},
}
Expand Down Expand Up @@ -270,7 +270,7 @@ def launch_notebook(
cpu=server_options["cpu_request"],
gpu=server_options["gpu_request"],
lfs_auto_fetch=server_options["lfs_auto_fetch"],
default_url=server_options["defaultUrl"],
default_url=server_options["default_url"],
)
elif isinstance(server_options, ServerOptions):
requested_server_options = server_options
Expand Down
6 changes: 3 additions & 3 deletions renku_notebooks/api/schemas/config_server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class BaseServerOptionsChoice(Schema):
order = fields.Int(required=True, validate=lambda x: x >= 1)
displayName = fields.Str(required=True)
display_name = fields.Str(required=True)
type = fields.Str(required=True, validate=validate.OneOf(["enum", "boolean"]))


Expand All @@ -22,7 +22,7 @@ class ServerOptionsChoices(Schema):
class Meta:
unknown = EXCLUDE

defaultUrl = fields.Nested(StringServerOptionsChoice, required=False)
default_url = fields.Nested(StringServerOptionsChoice, required=False)
lfs_auto_fetch = fields.Nested(BoolServerOptionsChoice, required=False)


Expand All @@ -32,7 +32,7 @@ class ServerOptionsDefaults(Schema):
class Meta:
unknown = EXCLUDE

defaultUrl = fields.Str(required=True)
default_url = fields.Str(required=True)
lfs_auto_fetch = fields.Bool(required=True)


Expand Down
8 changes: 4 additions & 4 deletions renku_notebooks/api/schemas/server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ServerOptions:

def __post_init__(self):
if self.default_url is None:
self.default_url = config.server_options.defaults["defaultUrl"]
self.default_url = config.server_options.defaults["default_url"]
if self.lfs_auto_fetch is None:
self.lfs_auto_fetch = config.server_options.defaults["lfs_auto_fetch"]
if self.storage is None and self.gigabytes:
Expand Down Expand Up @@ -193,7 +193,7 @@ def from_request(cls, data: Dict[str, Any]) -> "ServerOptions":
cpu=data["cpu_request"],
gpu=data["gpu_request"],
memory=data["mem_request"],
default_url=data["defaultUrl"],
default_url=data["default_url"],
lfs_auto_fetch=data["lfs_auto_fetch"],
storage=data["disk_request"],
)
Expand All @@ -206,9 +206,9 @@ class LaunchNotebookRequestServerOptions(Schema):
# by assigning a value of 0 to a server option we are ensuring that CRC will
# be able to easily find a match."""

defaultUrl = fields.Str(
default_url = fields.Str(
required=False,
load_default=config.server_options.defaults["defaultUrl"],
load_default=config.server_options.defaults["default_url"],
)
cpu_request = CpuField(
required=False,
Expand Down
8 changes: 4 additions & 4 deletions renku_notebooks/api/schemas/servers_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class ServerStatus(Schema):
)
message = fields.String(required=False)
details = fields.List(fields.Nested(ServerStatusDetail), required=True)
totalNumContainers = fields.Integer(
total_num_containers = fields.Integer(
required=True,
validate=validate.Range(min=0, min_inclusive=True),
)
readyNumContainers = fields.Integer(
ready_num_containers = fields.Integer(
required=True,
validate=validate.Range(min=0, min_inclusive=True),
)
Expand Down Expand Up @@ -351,8 +351,8 @@ def get_status(server: UserServerManifest, started: datetime):
output["details"] = get_status_breakdown(server)
if state == ServerStatusEnum.Starting.value:
output["message"] = get_starting_message(output["details"])
output["totalNumContainers"] = len(output["details"])
output["readyNumContainers"] = len(
output["total_num_containers"] = len(output["details"])
output["ready_num_containers"] = len(
[
step
for step in output["details"]
Expand Down
13 changes: 10 additions & 3 deletions renku_notebooks/api/schemas/servers_post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from marshmallow import Schema, fields
from marshmallow import Schema, fields, pre_load

from ...config import config
from .cloud_storage import RCloneStorageRequest
Expand All @@ -22,7 +22,6 @@ class LaunchNotebookRequestWithoutStorage(Schema):
# it will be matched against the closest resource class
server_options = fields.Nested(
LaunchNotebookRequestServerOptions(),
data_key="serverOptions",
required=False,
)
resource_class_id = fields.Int(required=False, load_default=None)
Expand All @@ -36,10 +35,18 @@ class LaunchNotebookRequestWithoutStorage(Schema):
)
default_url = fields.Str(
required=False,
load_default=config.server_options.defaults["defaultUrl"],
load_default=config.server_options.defaults["default_url"],
)
environment_variables = fields.Dict(keys=fields.Str(), values=fields.Str(), load_default=dict())

@pre_load
def _pre_load(self, data, **kwargs):
"""Compatibility with old clients"""
if "serverOptions" in data:
data["server_options"] = data["serverOptions"]
del data["serverOptions"]
return data


class LaunchNotebookRequestWithStorage(LaunchNotebookRequestWithoutStorage):
"""Used to validate the requesting for launching a jupyter server"""
Expand Down
7 changes: 4 additions & 3 deletions renku_notebooks/api/schemas/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
class NotebooksServiceInfo(Schema):
"""Various notebooks service info."""

anonymousSessionsEnabled = fields.Boolean(required=True)
cloudstorageEnabled = fields.Boolean(required=True)
sshEnabled = fields.Boolean(required=True)
anonymous_sessions_enabled = fields.Boolean(required=True)
cloudstorage_enabled = fields.Boolean(required=True)
cloudstorage_class = fields.String(required=True)
ssh_enabled = fields.Boolean(required=True)


class NotebooksServiceVersions(Schema):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dummy_server_defaults.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"defaultUrl": "/lab",
"default_url": "/lab",
"lfs_auto_fetch": false
}
6 changes: 3 additions & 3 deletions tests/unit/dummy_server_options.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"defaultUrl": {
"default_url": {
"default": "/lab",
"displayName": "Default Environment",
"display_name": "Default Environment",
"options": ["/lab", "/rstudio"],
"order": 2,
"type": "enum"
},
"lfs_auto_fetch": {
"default": false,
"displayName": "Automatically fetch LFS data",
"display_name": "Automatically fetch LFS data",
"order": 4,
"type": "boolean"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_server_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ServerOptions(0, 2000000000, 0, lfs_auto_fetch=True),
),
(
{"disk_request": 1000000000, "lfs_auto_fetch": True, "defaultUrl": "/test"},
{"disk_request": 1000000000, "lfs_auto_fetch": True, "default_url": "/test"},
ServerOptions(0, 0, 0, 1000000000, lfs_auto_fetch=True, default_url="/test"),
),
],
Expand Down
Loading