From 0d05e6d20c45f119e6b3e79730e87e63be035176 Mon Sep 17 00:00:00 2001 From: Shahar Glazner Date: Sun, 21 May 2023 12:23:07 +0300 Subject: [PATCH] feat: add provider parameters to context (#139) --- keep/contextmanager/contextmanager.py | 22 +++++----------------- keep/step/step.py | 3 +++ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/keep/contextmanager/contextmanager.py b/keep/contextmanager/contextmanager.py index d3c200f62..4a87d872a 100644 --- a/keep/contextmanager/contextmanager.py +++ b/keep/contextmanager/contextmanager.py @@ -152,26 +152,14 @@ def set_condition_results( if condition_alias: self.aliases[condition_alias] = result - def get_actionable_results(self): - actionable_results = [] - for step_id in self.steps_context: - # TODO: more robust way to identify the alias - if step_id == "this": - continue - if "conditions" in self.steps_context[step_id]: - # TODO: more robust way to identify actionable results - # TODO: support multiple conditions - for condition in self.steps_context[step_id]["conditions"]: - for condition_result in self.steps_context[step_id]["conditions"][ - condition - ]: - if condition_result["result"]: - actionable_results.append(condition_result) - return actionable_results + def set_step_provider_paremeters(self, step_id, provider_parameters): + if step_id not in self.steps_context: + self.steps_context[step_id] = {"provider_parameters": {}, "results": []} + self.steps_context[step_id]["provider_parameters"] = provider_parameters def set_step_context(self, step_id, results, foreach=False): if step_id not in self.steps_context: - self.steps_context[step_id] = {"conditions": {}, "results": []} + self.steps_context[step_id] = {"provider_parameters": {}, "results": []} # If this is a foreach step, we need to append the results to the list # so we can iterate over them diff --git a/keep/step/step.py b/keep/step/step.py index 0f35cde73..0e422c09b 100644 --- a/keep/step/step.py +++ b/keep/step/step.py @@ -33,6 +33,9 @@ def run(self): rendered_providers_parameters[parameter] = self.io_handler.render( self.provider_parameters[parameter] ) + self.context_manager.set_step_provider_paremeters( + self.step_id, rendered_providers_parameters + ) step_output = self.provider.query(**rendered_providers_parameters) except Exception as e: raise StepError(e)