-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Labels
Description
balena-sdk-python/balena/utils.py
Lines 28 to 41 in b220606
def is_full_uuid(value: Any) -> bool: | |
""" | |
Return True, if the input value is a valid UUID. False otherwise. | |
""" | |
if isinstance(value, str): | |
if len(value) == 32 or len(value) == 62: | |
try: | |
str(value) | |
return True | |
except ValueError: | |
return False | |
return False |
Not all strings of length 32 or 64 are valid UUIDs, see https://en.wikipedia.org/wiki/Universally_unique_identifier
A common way to check for the UUID validity seems to be something like
from uuid import UUID
try:
UUID(uuid_to_test)
except ValueError:
return False
return True
Originally posted by @pranasziaukas in #326 (comment)