Skip to content

Commit

Permalink
Add explicit get method on ui_restart endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Apr 22, 2021
1 parent 649ee8e commit 9e99527
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/middlewared/middlewared/plugins/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from middlewared.logger import CrashReporting
from middlewared.schema import accepts, Bool, Dict, Int, IPAddr, List, Str
from middlewared.service import (
CallError, ConfigService, no_auth_required, job, pass_app, private, Service, throttle, ValidationErrors
CallError, ConfigService, no_auth_required, job, pass_app, private, rest_api_metadata,
Service, throttle, ValidationErrors
)
import middlewared.sqlalchemy as sa
from middlewared.utils import Popen, run, start_daemon_thread, sw_buildtime, sw_version, osc
Expand Down Expand Up @@ -1470,6 +1471,7 @@ async def do_update(self, data):

return await self.config()

@rest_api_metadata(extra_explicit_methods=['GET'])
@accepts(Int('delay', default=3, validators=[Range(min=0)]))
async def ui_restart(self, delay):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/middlewared/middlewared/restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ async def register_resources(self):
res_kwargs['post'] = methodname
else:
res_kwargs['get'] = methodname
for rest_method in (method['explicit_methods'] or []):
assert rest_method in ('post', 'get')
for rest_method in map(str.lower, (method['extra_explicit_methods'] or [])):
assert rest_method in ('get',)
# Only allow get for now as that's the only use case we have for now NAS-110243
res_kwargs[rest_method] = methodname

Resource(self, self.middleware, short_methodname, service['config'], parent=parent, **res_kwargs)
Expand Down
6 changes: 3 additions & 3 deletions src/middlewared/middlewared/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def wrapper(fn):
return wrapper


def rest_api_metadata(explicit_methods=None):
def rest_api_metadata(extra_explicit_methods=None):
"""
Allow having endpoints specify explicit rest methods.
Expand All @@ -192,7 +192,7 @@ def rest_api_metadata(explicit_methods=None):
"""
def wrapper(fn):
fn._rest_api_metadata = {
'explicit_methods': explicit_methods,
'extra_explicit_methods': extra_explicit_methods,
}
return fn
return wrapper
Expand Down Expand Up @@ -1087,7 +1087,7 @@ def get_methods(self, service, cli):
'filterable': hasattr(method, '_filterable'),
'filterable_schema': None,
'pass_application': hasattr(method, '_pass_app'),
'explicit_methods': method._rest_api_metadata['explicit_methods'] if hasattr(
'explicit_methods': method._rest_api_metadata['extra_explicit_methods'] if hasattr(
method, '_rest_api_metadata') else None,
'require_websocket': hasattr(method, '_pass_app') and not method._pass_app['rest'],
'job': hasattr(method, '_job'),
Expand Down

0 comments on commit 9e99527

Please sign in to comment.