Dispatch parameterized daemon actions
This commit is contained in:
+25
-4
@@ -81,7 +81,13 @@ class Plugin:
|
||||
+ ", ".join(missing)
|
||||
)
|
||||
|
||||
def execute(self, action, config, runtime_state):
|
||||
def execute(
|
||||
self,
|
||||
action,
|
||||
config,
|
||||
runtime_state,
|
||||
request_parameters=None,
|
||||
):
|
||||
if action not in self.actions:
|
||||
raise RegistryError(
|
||||
f"plugin {self.name} does not support action {action}"
|
||||
@@ -98,9 +104,18 @@ class Plugin:
|
||||
# Backward-compatible generic state injection. Existing one-argument
|
||||
# plugins continue to receive only config; state-aware plugins can
|
||||
# declare a second positional parameter named runtime_state.
|
||||
parameters = list(inspect.signature(handler).parameters.values())
|
||||
handler_parameters = list(
|
||||
inspect.signature(handler).parameters.values()
|
||||
)
|
||||
|
||||
if len(parameters) >= 2:
|
||||
if len(handler_parameters) >= 3:
|
||||
return handler(
|
||||
config,
|
||||
runtime_state,
|
||||
request_parameters or {},
|
||||
)
|
||||
|
||||
if len(handler_parameters) >= 2:
|
||||
return handler(config, runtime_state)
|
||||
|
||||
return handler(config)
|
||||
@@ -178,7 +193,12 @@ class Registry:
|
||||
in self.resources.items()
|
||||
}
|
||||
|
||||
def execute(self, resource_id, action):
|
||||
def execute(
|
||||
self,
|
||||
resource_id,
|
||||
action,
|
||||
request_parameters=None,
|
||||
):
|
||||
resource = self.resources.get(resource_id)
|
||||
|
||||
if resource is None:
|
||||
@@ -190,6 +210,7 @@ class Registry:
|
||||
action,
|
||||
resource.config,
|
||||
resource.runtime_state,
|
||||
request_parameters,
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user