@@ -1,13 +1,10 @@
|
||||
from __future__ import annotations
|
||||
from re import A
|
||||
from tkinter.constants import E
|
||||
|
||||
import yaml
|
||||
from abc import ABC, abstractmethod
|
||||
from pydantic import BaseModel
|
||||
|
||||
from playbook.models import ActModel, PlaybookModel, StepModel, timed_run
|
||||
from playbook.logging_models import PlaybookLog, Status, StepLogModel, log_file_name
|
||||
from playbook.models import ActModel, PlaybookModel, StepModel
|
||||
from playbook.logging_models import PlaybookLog, StepLogModel, log_file_name
|
||||
from playbook.action_registry import ActionFn, ActionRegistry
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -65,7 +65,7 @@ class ActModel(BaseModel):
|
||||
if stepLog.failed:
|
||||
return ActLog.fail(self.name, err=stepLog.error, logs=step_logs)
|
||||
|
||||
previous_step_ctx = stepLog.pipe_ctx
|
||||
previous_step_ctx = previous_step_ctx | stepLog.pipe_ctx
|
||||
|
||||
return ActLog.ok(self.name, msg="success", logs=step_logs)
|
||||
|
||||
@@ -139,14 +139,14 @@ class ContextChecker:
|
||||
self._ctx = ctx
|
||||
|
||||
@classmethod
|
||||
def requires(cls, *args):
|
||||
def requires(cls, required: list[str]):
|
||||
def decorator(func: ActionFn):
|
||||
@functools.wraps(func)
|
||||
def wrapper(ctx: dict[str, object], name: str) -> StepLogModel:
|
||||
if all(key in ctx for key in args):
|
||||
if all(key in ctx for key in required):
|
||||
return func(ctx, name)
|
||||
else:
|
||||
missing_keys = [key for key in args if key not in ctx]
|
||||
missing_keys = [key for key in required if key not in ctx]
|
||||
missing_keys_msg = f"missing context keys: {missing_keys}"
|
||||
return StepLogModel.fail(name, err=missing_keys_msg)
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user