Skip to content

Commit b74e9d4

Browse files
dweissbacherjshcodes
authored andcommitted
Add WorkflowDefinitionsStatus endpoint and corresponding method in Workflows class
1 parent c1e3634 commit b74e9d4

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

.github/wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ shubham
12831283
WorkflowUpdateHumanInputV
12841284
WorkflowGetHumanInputV
12851285
WorkflowDefinitionsCreate
1286+
WorkflowDefinitionsStatus
12861287
WorkflowDefinitionsUpdate
12871288
WorkflowDefinitionsImport
12881289
WorkflowDefinitionsExport

src/falconpy/_constant/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"setContentUpdatePoliciesPrecedence", "setDeviceControlPoliciesPrecedence",
5858
"setFirewallPoliciesPrecedence", "setPreventionPoliciesPrecedence", "signalChangesExternal",
5959
"setRTResponsePoliciesPrecedence", "setSensorUpdatePoliciesPrecedence", "GetDeviceDetails",
60-
"CreateSavedSearchesDeployV1", "cancel-scans", "get-rules-get"
60+
"CreateSavedSearchesDeployV1", "cancel-scans", "get-rules-get", "WorkflowDefinitionsStatus"
6161
]
6262
MOCK_OPERATIONS: List[str] = [
6363
"GetImageAssessmentReport", "DeleteImageDetails", "ImageMatchesPolicy"

src/falconpy/_endpoint/_workflows.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,31 @@
198198
}
199199
]
200200
],
201+
[
202+
"WorkflowDefinitionsStatus",
203+
"POST",
204+
"/workflows/entities/definition-actions/v1",
205+
"Enable or disable a workflow definition, or stop all executions for a definition."
206+
"When a definition is disabled it will not execute against any new trigger events.",
207+
"workflows",
208+
[
209+
{
210+
"type": "string",
211+
"description": "Specify one of these actions:\n enable - enable the workflow(s) specified in ids\n "
212+
"disable - disable the workflow(s) specified in ids.\n cancle - cancel all in-flight executions for "
213+
"the workflow specified in ids",
214+
"name": "action_name",
215+
"in": "query",
216+
"required": True
217+
},
218+
{
219+
"description": "IDs of workflow definitions",
220+
"name": "body",
221+
"in": "body",
222+
"required": True
223+
}
224+
]
225+
],
201226
[
202227
"WorkflowDefinitionsExport",
203228
"GET",

src/falconpy/workflows.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
force_default,
4343
process_service_request,
4444
handle_single_argument,
45-
generate_error_result
45+
generate_error_result,
46+
args_to_params
4647
)
4748
from ._payload import (
4849
simple_action_parameter,
@@ -840,6 +841,61 @@ def provision(self: object, body: dict = None, **kwargs) -> Union[Dict[str, Unio
840841
body=body
841842
)
842843

844+
@force_default(defaults=["parameters", "body"], default_types=["dict"])
845+
def set_workflow_definition_status(self: object,
846+
body: dict = None,
847+
parameters: dict = None,
848+
**kwargs
849+
) -> Union[Dict[str, Union[int, dict]], Result]:
850+
"""Enable or disable a workflow definition, or stop all executions for a definition.
851+
852+
When a definition is disabled it will not execute against any new trigger events.
853+
854+
Keyword arguments:
855+
action_name -- action to perform, 'enable', 'disable', or 'cancel'.
856+
body -- full body payload, not required if ids are provided as keyword.
857+
You must use body if you are going to specify action_parameters.
858+
{
859+
"ids": [
860+
"string"
861+
]
862+
}
863+
ids -- IDs of workflow definitions to perform the action against. String or list of strings.
864+
parameters - full parameters payload, not required if action_name is provide as a keyword.
865+
866+
This method only supports keywords for providing arguments.
867+
868+
Returns: dict object containing API response.
869+
870+
HTTP Method: POST
871+
872+
Swagger URL
873+
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/workflows/WorkflowDefinitionsAction
874+
"""
875+
if not body:
876+
body = generic_payload_list(submitted_keywords=kwargs, payload_value="ids")
877+
878+
_allowed_actions = ['enable', 'disable', 'cancel']
879+
operation_id = "WorkflowDefinitionsStatus"
880+
parameter_payload = args_to_params(parameters, kwargs, Endpoints, operation_id)
881+
action_name = parameter_payload.get("action_name", "Not Specified")
882+
# Only process allowed actions
883+
if action_name.lower() in _allowed_actions:
884+
returned = process_service_request(
885+
calling_object=self,
886+
endpoints=Endpoints,
887+
operation_id=operation_id,
888+
body=body,
889+
keywords=kwargs,
890+
params=parameters,
891+
body_validator={"ids": list} if self.validate_payloads else None,
892+
body_required=["ids"] if self.validate_payloads else None
893+
)
894+
else:
895+
returned = generate_error_result("Invalid value specified for action_name parameter.")
896+
897+
return returned
898+
843899
# These method names align to the operation IDs in the API but
844900
# do not conform to snake_case / PEP8 and are defined here for
845901
# backwards compatibility / ease of use purposes
@@ -851,6 +907,7 @@ def provision(self: object, body: dict = None, **kwargs) -> Union[Dict[str, Unio
851907
WorkflowDefinitionsExport = export_definition
852908
WorkflowDefinitionsImport = import_definition
853909
WorkflowDefinitionsUpdate = update_definition
910+
WorkflowDefinitionsStatus = set_workflow_definition_status
854911
WorkflowExecute = execute
855912
WorkflowExecuteInternal = execute_internal
856913
WorkflowMockExecute = mock_execute

tests/test_workflows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def run_all_tests(self):
4343
"WorkflowDefinitionsImport4": falcon.import_definition(validate_only=True, data_file="tests/test.yml", name="workflow_name"),
4444
"WorkflowDefinitionsImport4": falcon.import_definition(validate_only=True, data_file=binary_example, name="workflow_name"),
4545
"WorkflowDefinitionsUpdate": falcon.update_definition(change_log="testing"),
46+
"WorkflowDefinitionsStatus": falcon.set_workflow_definition_status(ids="1234567", action_name="enable"),
4647
"WorkflowGetHumanInputV1": falcon.get_human_input(ids="1234567"),
4748
"WorkflowUpdateHumanInputV1": falcon.update_human_input(input="whatever", note="whatever"),
4849
"WorkflowActivitiesContentCombined": falcon.search_activities_content(limit=1)

0 commit comments

Comments
 (0)