Skip to content

Commit

Permalink
Fix workflow import multipart handling. Closes #1145.
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcodes committed Apr 10, 2024
1 parent f148b87 commit c6cdf11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/falconpy/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,23 @@ def import_definition(self: object, parameters: dict = None, **kwargs) -> Dict[s
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/workflows/WorkflowDefinitionsImport
"""
data_file = kwargs.get("data_file", None)
if data_file:
content_type = "application/x-yaml"
# Create a multipart form payload for our upload file
try:
with open(data_file, "r", encoding="utf-8") as yaml_file:
file_data = yaml_file.read()
file_extended = {"name": "yaml_upload", "data_file": file_data, "type": content_type}
except FileNotFoundError:
data_file = None

if data_file and file_data:
returned = process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="WorkflowDefinitionsImport",
keywords=kwargs,
params=parameters,
data=data_file
files=file_extended
)
else:
returned = generate_error_result("You must provide a workflow file in YAML format to import.")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def run_all_tests(self):
"WorkflowDefinitionsExport": falcon.export_definition(),
"WorkflowDefinitionsImport": falcon.import_definition(validate_only=True, data_file="this_will_415"),
"WorkflowDefinitionsImport": falcon.import_definition(validate_only=True, file_data="this_will_500"),
"WorkflowDefinitionsImport": falcon.import_definition(validate_only=True, data_file="not_here.yml"),
"WorkflowDefinitionsImport": falcon.import_definition(validate_only=True, data_file="tests/test.yml"),
"WorkflowDefinitionsUpdate": falcon.update_definition(change_log="testing"),
"WorkflowGetHumanInputV1": falcon.get_human_input(ids="1234567"),
"WorkflowUpdateHumanInputV1": falcon.update_human_input(input="whatever", note="whatever"),
Expand Down

0 comments on commit c6cdf11

Please sign in to comment.