Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions changelogs/fragments/1499-rework-slugify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bugfixes:
- Adjust regex pattern for character conversion for slugs
- Only do slug generation in netbox_secret if needed
- Make slug generation optional by providing `slug` key
breaking_changes:
- This changes the behavior for generating slugs. If you were relying on the previous behavior, you need to be aware that this behavior has changed.
3 changes: 2 additions & 1 deletion plugins/module_utils/netbox_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def run(self):
# Used for msg output
name = data.get("name")

data["slug"] = self._to_slug(name)
if not data.get("slug"):
data["slug"] = self._to_slug(name)

object_query_params = self._build_query_params(
endpoint_name, data, user_query_params
Expand Down
15 changes: 11 additions & 4 deletions plugins/module_utils/netbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,10 +1423,11 @@ def _to_slug(self, value):
return value
elif isinstance(value, int):
return value
else:
removed_chars = re.sub(r"[^\-\.\w\s]", "", value)
convert_chars = re.sub(r"[\-\.\s]+", "-", removed_chars)
return convert_chars.strip().lower()

value = re.sub(r"[^\-.\w\s]", "", value)
value = re.sub(r"^[\s.]+|[\s.]+$", "", value)
value = re.sub(r"[-.\s]+", "-", value)
return value.strip().lower()

def _normalize_data(self, data):
"""
Expand All @@ -1444,10 +1445,16 @@ def _normalize_data(self, data):
pass
else:
for subk, subv in v.items():
if subk == "slug":
continue

sub_data_type = QUERY_TYPES.get(subk, "q")
if sub_data_type == "slug":
data[k][subk] = self._to_slug(subv)
else:
if k == "slug":
continue

if k == "scope":
data_type = QUERY_TYPES.get(
ENDPOINT_NAME_MAPPING[SCOPE_TO_ENDPOINT[data["scope_type"]]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@
},
{
"before": {
"slug": "Test to_slug"
"slug": "already--valid_slug"
},
"after": {
"slug": "test-to_slug"
"slug": "already--valid_slug"
}
},
{
Expand Down Expand Up @@ -345,4 +345,4 @@
"mac_address": "AA:BB:CC:DD:EE:FF"
}
}
]
]
Loading