Refactor uuid handling
There are a couple of method in Foreman module for UUID handling that can be better.
Fixes #31228 - Improve UUID check performance
Doing a full match for regexp including saving match data is slow when
all we care about is whether it is a UUID or not. Instead first rule out
quick checks (not a string, wrong length) and only then check with
`.match?` instead of `=~` which just returns a boolean without saving
the match data.