Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UUID check to anywhere checking for ints #22

Merged
merged 3 commits into from
Mar 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
@@ -622,7 +622,7 @@ def is_valid_uuid(self, match):
"""Determine if the match is already UUID."""
try:
uuid_obj = UUID(match)
except ValueError:
except (ValueError, AttributeError):
return False
return str(uuid_obj) == match

@@ -704,7 +704,9 @@ def _build_query_params(
"Link Aggregation Group (LAG)", "interfaces"
)
query_dict.update({"type": intf_type})
if isinstance(module_data["device"], int):
if isinstance(module_data["device"], int) or self.is_valid_uuid(
module_data["device"]
):
query_dict.update({"device_id": module_data["device"]})
else:
query_dict.update({"device": module_data["device"]})
@@ -713,7 +715,9 @@ def _build_query_params(
query_dict.update({"prefix": module_data["parent"]})

elif parent == "ip_addresses":
if isinstance(module_data["device"], int):
if isinstance(module_data["device"], int) or self.is_valid_uuid(
module_data["device"]
):
query_dict.update({"device_id": module_data["device"]})
else:
query_dict.update({"device": module_data["device"]})
@@ -800,7 +804,9 @@ def _change_choices_id(self, endpoint, data):
required_choices = REQUIRED_ID_FIND[endpoint]
for choice in required_choices:
if data.get(choice):
if isinstance(data[choice], int):
if isinstance(data[choice], int) or self.is_valid_uuid(
data[choice]
):
continue
choice_value = self._fetch_choice_value(data[choice], endpoint)
data[choice] = choice_value
@@ -858,7 +864,9 @@ def _find_ids(self, data, user_query_params):
)
# If user passes in an integer, add to ID list to id_list as user
# should have passed in a tag ID
elif isinstance(list_item, int):
elif isinstance(list_item, int) or self.is_valid_uuid(
list_item
):
id_list.append(list_item)
continue
else:
@@ -880,7 +888,7 @@ def _find_ids(self, data, user_query_params):

if isinstance(v, list):
data[k] = id_list
elif isinstance(v, int):
elif isinstance(v, int) or self.is_valid_uuid(v):
pass
elif query_id:
data[k] = query_id.id
@@ -896,7 +904,7 @@ def _to_slug(self, value):
"""
if value is None:
return value
elif isinstance(value, int):
elif isinstance(value, int) or self.is_valid_uuid(value):
return value
else:
removed_chars = re.sub(r"[^\-\.\w\s]", "", value)
Loading
Oops, something went wrong.