api: Keep track of action controllers

We need to be able to resolve the original, unversioned methods.
Register these things slightly differently. It would likely be better to
fold these action controllers into the main controllers, but that's a
lot of code motion that I don't really want to do right now.

Change-Id: Iee37500e6b2dbacf0c1514bfc52ef2dfe8ceb94f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-03-25 19:07:55 +00:00
parent e504b76508
commit 233fe1865f
2 changed files with 9 additions and 2 deletions

View File

@ -94,7 +94,7 @@ def _create_controller(main_controller, action_controller_list):
controller = wsgi.Resource(main_controller())
for ctl in action_controller_list:
controller.register_actions(ctl())
controller.register_subcontroller_actions(ctl())
return controller

View File

@ -396,8 +396,8 @@ class Resource(wsgi.Application):
""":param controller: object that implement methods created by routes
lib
"""
self.controller = controller
self.sub_controllers = []
self.default_serializers = dict(json=JSONDictSerializer)
@ -413,6 +413,13 @@ class Resource(wsgi.Application):
for key, method_name in actions.items():
self.wsgi_actions[key] = getattr(controller, method_name)
def register_subcontroller_actions(self, sub_controller):
"""Registers sub-controller actions with this resource."""
self.sub_controllers.append(sub_controller)
actions = getattr(sub_controller, 'wsgi_actions', {})
for key, method_name in actions.items():
self.wsgi_actions[key] = getattr(sub_controller, method_name)
def get_action_args(self, request_environment):
"""Parse dictionary created by routes library."""