Skip to content

Commit

Permalink
feat: add provider parameters to context (keephq#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored May 21, 2023
1 parent 3f1a71f commit 0d05e6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 5 additions & 17 deletions keep/contextmanager/contextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions keep/step/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d05e6d

Please sign in to comment.