Skip to content

Commit

Permalink
Merge pull request ceph#56164 from rhcs-dashboard/wip-64890-main
Browse files Browse the repository at this point in the history
mgr/dashboard: fix NVMeoF API

Reviewed-by: Nizamudeen A <[email protected]>
  • Loading branch information
nizamial09 authored Mar 25, 2024
2 parents ad40d6f + 4adf489 commit a8b1b0e
Show file tree
Hide file tree
Showing 14 changed files with 1,072 additions and 493 deletions.
3 changes: 2 additions & 1 deletion src/pybind/mgr/dashboard/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ._auth import ControllerAuthMixin
from ._base_controller import BaseController
from ._crud import CRUDCollectionMethod, CRUDEndpoint, CRUDResourceMethod, SecretStr
from ._docs import APIDoc, EndpointDoc
from ._docs import APIDoc, EndpointDoc, Param
from ._endpoint import Endpoint, Proxy
from ._helpers import ENDPOINT_MAP, allow_empty_body, \
generate_controller_routes, json_error_page, validate_ceph_type
Expand All @@ -23,6 +23,7 @@
'Task',
'ControllerAuthMixin',
'EndpointDoc',
'Param',
'APIDoc',
'allow_empty_body',
'ENDPOINT_MAP',
Expand Down
9 changes: 8 additions & 1 deletion src/pybind/mgr/dashboard/controllers/_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Type, Union

from ..api.doc import SchemaInput, SchemaType

Expand Down Expand Up @@ -115,6 +115,13 @@ def __call__(self, func: Any) -> Any:
return func


class Param(NamedTuple):
type: Union[Type, List[Type]]
description: str
optional: bool = False
default: Optional[Any] = None


class APIDoc(object):
def __init__(self, description="", group=""):
self.tag = group
Expand Down
8 changes: 4 additions & 4 deletions src/pybind/mgr/dashboard/controllers/_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def __init__(self, method=None, path=None, path_params=None, query_params=None,
if method is None:
method = 'GET'
elif not isinstance(method, str) or \
method.upper() not in ['GET', 'POST', 'DELETE', 'PUT']:
method.upper() not in ['GET', 'POST', 'DELETE', 'PUT', 'PATCH']:
raise TypeError("Possible values for method are: 'GET', 'POST', "
"'DELETE', or 'PUT'")
"'DELETE', 'PUT', 'PATCH'")

method = method.upper()

Expand All @@ -25,7 +25,7 @@ def __init__(self, method=None, path=None, path_params=None, query_params=None,
" path parameters by default".format(method))

if path_params is None:
if method in ['POST', 'PUT']:
if method in ['POST', 'PUT', 'PATCH']:
path_params = []

if query_params is None:
Expand All @@ -41,7 +41,7 @@ def __init__(self, method=None, path=None, path_params=None, query_params=None,
self.version = version

def __call__(self, func):
if self.method in ['POST', 'PUT']:
if self.method in ['POST', 'PUT', 'PATCH']:
func_params = _get_function_params(func)
for param in func_params:
if param['name'] in self.path_params and not param['required']:
Expand Down
4 changes: 3 additions & 1 deletion src/pybind/mgr/dashboard/controllers/_rest_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class RESTController(BaseController, skip_registry=True):
'GET': Permission.READ,
'POST': Permission.CREATE,
'PUT': Permission.UPDATE,
'PATCH': Permission.UPDATE,
'DELETE': Permission.DELETE
}

Expand All @@ -60,7 +61,8 @@ class RESTController(BaseController, skip_registry=True):
('get', {'method': 'GET', 'resource': True, 'status': 200, 'version': APIVersion.DEFAULT}),
('delete', {'method': 'DELETE', 'resource': True, 'status': 204, 'version': APIVersion.DEFAULT}), # noqa E501 #pylint: disable=line-too-long
('set', {'method': 'PUT', 'resource': True, 'status': 200, 'version': APIVersion.DEFAULT}),
('singleton_set', {'method': 'PUT', 'resource': False, 'status': 200, 'version': APIVersion.DEFAULT}) # noqa E501 #pylint: disable=line-too-long
('singleton_set', {'method': 'PUT', 'resource': False, 'status': 200, 'version': APIVersion.DEFAULT}), # noqa E501 #pylint: disable=line-too-long
('update', {'method': 'PATCH', 'resource': True, 'status': 200, 'version': APIVersion.DEFAULT}) # noqa E501 #pylint: disable=line-too-long
])

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/pybind/mgr/dashboard/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Auth(RESTController, ControllerAuthMixin):
Provide authenticates and returns JWT token.
"""
# pylint: disable=R0912

def create(self, username, password):
user_data = AuthManager.authenticate(username, password)
user_perms, pwd_expiration_date, pwd_update_required = None, None, None
Expand Down
6 changes: 3 additions & 3 deletions src/pybind/mgr/dashboard/controllers/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _gen_responses(cls, method, resp_object=None,
resp['201'] = {'description': "Resource created.",
'content': {version.to_mime_type():
{'type': 'object'}}}
if method.lower() == 'put':
if method.lower() in ['put', 'patch']:
resp['200'] = {'description': "Resource updated.",
'content': {version.to_mime_type():
{'type': 'object'}}}
Expand Down Expand Up @@ -315,7 +315,7 @@ def set_request_body_param(cls, endpoint_param, method, methods, p_info):
@classmethod
def gen_paths(cls, all_endpoints):
# pylint: disable=R0912
method_order = ['get', 'post', 'put', 'delete']
method_order = ['get', 'post', 'put', 'patch', 'delete']
paths = {}
for path, endpoints in sorted(list(ENDPOINT_MAP.items()),
key=lambda p: p[0]):
Expand Down Expand Up @@ -344,7 +344,7 @@ def gen_paths(cls, all_endpoints):
if summary:
methods[method.lower()]['summary'] = summary

if method.lower() in ['post', 'put']:
if method.lower() in ['post', 'put', 'patch']:
cls.set_request_body_param(endpoint.body_params, method, methods, p_info)
cls.set_request_body_param(endpoint.query_params, method, methods, p_info)

Expand Down
Loading

0 comments on commit a8b1b0e

Please sign in to comment.