Skip to content

Commit

Permalink
Resolve action keyword collision. Closes #1161.
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcodes committed Jun 4, 2024
1 parent 8a79554 commit a820f73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/falconpy/_util/_uber.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def handle_field(tgt: str, kwa: dict, fld: str) -> str:

def handle_body_payload_ids(kwa: dict) -> dict:
"""Migrates the IDs parameter list over to the body payload."""
if kwa.get("action", None) in PREFER_IDS_IN_BODY:
if kwa.get("operation", None) in PREFER_IDS_IN_BODY:
if kwa.get("ids", None):
# Handle the GET to POST method redirection for passed IDs
if not kwa.get("body", {}).get("ids", None):
Expand Down Expand Up @@ -115,12 +115,12 @@ def handle_container_operations(kwa: dict, base_string: str) -> Tuple[dict, str,
"""Handle Base URLs and keyword arguments for container registry operations."""
# Default to non-container registry operations
do_container = False
if kwa.get("action", None) in MOCK_OPERATIONS:
if kwa.get("operation", None) in MOCK_OPERATIONS:
for base in [burl for burl in dir(BaseURL) if "__" not in burl]:
if BaseURL[base].value == base_string.replace("https://", ""):
base_string = f"https://{ContainerBaseURL[base].value}"
do_container = True
if kwa.get("action", None) == "ImageMatchesPolicy":
if kwa.get("operation", None) == "ImageMatchesPolicy":
if "parameters" not in kwa:
kwa["parameters"] = {}
kwa["parameters"]["policy_type"] = "image-prevention-policy"
Expand Down
13 changes: 9 additions & 4 deletions src/falconpy/api_complete/_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def command(self, *args, **kwargs) -> Union[Dict[str, Union[int, dict]], bytes]:
Keyword arguments
----
action : str (Default: None)
operation : str (Default: None)
API Operation ID to perform
Please note: The keyword "action" will also be accepted but
may collide with operation parameters and is not recommended.
parameters : dict (Default: {})
Parameter payload (Query string)
body : dict (Default: {})
Expand Down Expand Up @@ -178,13 +180,16 @@ def command(self, *args, **kwargs) -> Union[Dict[str, Union[int, dict]], bytes]:
Dictionary or binary object containing API response depending on requested operation.
"""
try:
if not kwargs.get("action", None):
if not kwargs.get("operation", None):
# Assume they're passing it in as the first argument.
kwargs["action"] = args[0]
kwargs["operation"] = args[0]
# Issue #1161 - operation is specified using the action keyword
if kwargs.get("action", None) and not kwargs.get("operation", None):
kwargs["operation"] = kwargs.get("action")
except IndexError:
pass # They didn't specify an action, try for an override instead.

uber_command = [a for a in self.commands if a[0] == kwargs.get("action", None)]
uber_command = [a for a in self.commands if a[0] == kwargs.get("operation", None)]
if kwargs.get("override", None):
uber_command = [["Manual"] + kwargs["override"].split(",")]
if uber_command:
Expand Down

0 comments on commit a820f73

Please sign in to comment.