Skip to content

Commit

Permalink
Fix list & add of scenarios & questions via the api client for dfiq1.1 (
Browse files Browse the repository at this point in the history
  • Loading branch information
jkppr authored Aug 23, 2024
1 parent be881c0 commit b9e32b1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api_client/python/timesketch_api_client/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,14 +1639,14 @@ def add_scenario(self, uuid=None, dfiq_id=None, name=None):

form_data = {}
if uuid:
form_data["template_uuid"] = uuid
form_data["uuid"] = uuid
elif dfiq_id:
form_data["template_id"] = dfiq_id
else: # name is provided
scenario_templates = scenario_lib.getScenarioTemplateList(self.api)
for template in scenario_templates:
if template.get("name") == name:
form_data["template_uuid"] = template.get("uuid")
form_data["uuid"] = template.get("uuid")
break
else:
raise ValueError(f"No DFIQ scenario template found with name '{name}'")
Expand Down Expand Up @@ -1684,14 +1684,18 @@ def list_scenarios(self):
response_json = error.get_response_json(response, logger)

scenario_objects = response_json.get("objects", [])
# Check if it's a nested list or a single list
if scenario_objects and isinstance(scenario_objects[0], list):
scenario_objects = scenario_objects[0]

return [
scenario_lib.Scenario(
uuid=scenario_data.get("uuid"),
scenario_id=scenario_data.get("id"),
sketch_id=self.id,
api=self.api,
)
for scenario_data in scenario_objects[0]
for scenario_data in scenario_objects
]

def add_question(self, dfiq_id=None, uuid=None, question_text=None):
Expand Down Expand Up @@ -1725,12 +1729,12 @@ def add_question(self, dfiq_id=None, uuid=None, question_text=None):
if dfiq_id:
form_data["template_id"] = dfiq_id
elif uuid:
form_data["template_uuid"] = uuid
form_data["uuid"] = uuid
else: # question_text is provided
question_templates = scenario_lib.getQuestionTemplateList(self.api)
for template in question_templates:
if template.get("name") == question_text:
form_data["template_uuid"] = template.get("uuid")
form_data["uuid"] = template.get("uuid")
break
else:
form_data["question_text"] = question_text
Expand Down Expand Up @@ -1769,14 +1773,18 @@ def list_questions(self):
response_json = error.get_response_json(response, logger)

question_objects = response_json.get("objects", [])
# Check if it's a nested list or a single list
if question_objects and isinstance(question_objects[0], list):
question_objects = question_objects[0]

return [
scenario_lib.Question(
question_id=question_data.get("id"),
uuid=question_data.get("uuid"),
sketch_id=self.id,
api=self.api,
)
for question_data in question_objects[0]
for question_data in question_objects
]

def add_event(self, message, date, timestamp_desc, attributes=None, tags=None):
Expand Down

0 comments on commit b9e32b1

Please sign in to comment.