balena-io / balena-sdk-python

Balena SDK for Python
Apache License 2.0
67 stars 46 forks source link

Not all strings of length 32 or 64 are valid UUIDs #336

Open pranasziaukas opened 1 year ago

pranasziaukas commented 1 year ago

https://github.com/balena-io/balena-sdk-python/blob/b220606083d7da8723612154995ed45701c5a792/balena/utils.py#L28-L41

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 https://github.com/balena-io/balena-sdk-python/pull/326#discussion_r1238661657_