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
16 changes: 2 additions & 14 deletions server/src/uds/services/OpenShift/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ def test(
# Utility
def sanitized_name(self, name: str) -> str:
"""
Sanitizes the VM name to comply with RFC 1123:
- Converts to lowercase
- Replaces any character not in [a-z0-9.-] with '-'
- Collapses multiple '-' into one
- Removes leading/trailing non-alphanumeric characters
- Limits length to 63 characters
OpenShift only allows machine names with [a-zA-Z0-9_-]
"""
name = name.lower()
# Replace any character not allowed with '-'
name = re.sub(r'[^a-z0-9.-]', '-', name)
# Collapse multiple '-' into one
name = re.sub(r'-{2,}', '-', name)
# Remove leading/trailing non-alphanumeric characters
name = re.sub(r'^[^a-z0-9]+|[^a-z0-9]+$', '', name)
return name[:63]
return re.sub(r'[^a-zA-Z0-9-]', '-', name).lower()[:63]
6 changes: 3 additions & 3 deletions server/tests/services/openshift/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def test_sanitized_name(self) -> None:
test_cases = [
('Test-VM-1', 'test-vm-1'),
('Test_VM@2', 'test-vm-2'),
('My Test VM!!!', 'my-test-vm'),
('Test !!! this is', 'test-this-is'),
('UDS-Pub-Hello World!!--2025065122-v1', 'uds-pub-hello-world-2025065122-v1'),
('My Test VM!!!', 'my-test-vm---'),
('Test !!! this is', 'test-----this-is'),
('UDS-Pub-Hello World!!--2025065122-v1', 'uds-pub-hello-world----2025065122-v1'),
('a' * 100, 'a' * 63), # Test truncation
]
for input_name, expected in test_cases:
Expand Down
Loading