Skip to content

Commit 4ecf218

Browse files
committed
cleanup blob container name validation
1 parent 37c0316 commit 4ecf218

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

packages/graphrag-storage/graphrag_storage/azure_blob_storage.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,27 +277,7 @@ def _validate_blob_container_name(container_name: str) -> None:
277277
-------
278278
bool: True if valid, False otherwise.
279279
"""
280-
# Check the length of the name
281-
if len(container_name) < 3 or len(container_name) > 63:
282-
msg = f"Container name must be between 3 and 63 characters in length. Name provided was {len(container_name)} characters long."
283-
raise ValueError(msg)
284-
285-
# Check if the name starts with a letter or number
286-
if not container_name[0].isalnum():
287-
msg = f"Container name must start with a letter or number. Starting character was {container_name[0]}."
288-
raise ValueError(msg)
289-
290-
# Check for valid characters (letters, numbers, hyphen) and lowercase letters
291-
if not re.match(r"^[a-z0-9-]+$", container_name):
292-
msg = f"Container name must only contain:\n- lowercase letters\n- numbers\n- or hyphens\nName provided was {container_name}."
293-
raise ValueError(msg)
294-
295-
# Check for consecutive hyphens
296-
if "--" in container_name:
297-
msg = f"Container name cannot contain consecutive hyphens. Name provided was {container_name}."
298-
raise ValueError(msg)
299-
300-
# Check for hyphens at the end of the name
301-
if container_name[-1] == "-":
302-
msg = f"Container name cannot end with a hyphen. Name provided was {container_name}."
280+
# Match alphanumeric or single hyphen not at the start or end, repeated 3-63 times.
281+
if not re.match(r"^(?:[0-9a-z]|(?<!^)-(?!$)){3,63}$", container_name):
282+
msg = f"Container name must be between 3 and 63 characters long and contain only lowercase letters, numbers, or hyphens. Name provided was {container_name}."
303283
raise ValueError(msg)

0 commit comments

Comments
 (0)