From c65c322fc659f452e2e16aa136b3afae45482b84 Mon Sep 17 00:00:00 2001 From: Jonathan Hunter <19241458+jmhunter@users.noreply.github.com> Date: Wed, 17 Mar 2021 20:09:41 +0000 Subject: [PATCH] Add variables to hold username and hostname regex Also adjust displayed message to match. Tested locally using 'make dryrun' --- subiquity/ui/views/identity.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/subiquity/ui/views/identity.py b/subiquity/ui/views/identity.py index e1760301..de41fca7 100644 --- a/subiquity/ui/views/identity.py +++ b/subiquity/ui/views/identity.py @@ -40,9 +40,11 @@ from subiquity.common.types import IdentityData log = logging.getLogger("subiquity.views.identity") HOSTNAME_MAXLEN = 64 +HOSTNAME_REGEX = r'[a-z0-9_][a-z0-9_-]*' REALNAME_MAXLEN = 160 SSH_IMPORT_MAXLEN = 256 + 3 # account for lp: or gh: USERNAME_MAXLEN = 32 +USERNAME_REGEX = r'[a-z_][a-z0-9_-]*' class RealnameEditor(StringEditor, WantsToKnowFormField): @@ -107,8 +109,9 @@ class IdentityForm(Form): "Server name too long, must be less than {limit}" ).format(limit=HOSTNAME_MAXLEN) - if not re.match(r'[a-z0-9_][a-z0-9_-]*', self.hostname.value): - return _("Hostname must match NAME_REGEX, i.e. [a-z0-9_][a-z0-9_-]*") + if not re.match(HOSTNAME_REGEX, self.hostname.value): + return _( + "Hostname must match HOSTNAME_REGEX: " + HOSTNAME_REGEX) def validate_username(self): username = self.username.value @@ -121,7 +124,8 @@ class IdentityForm(Form): ).format(limit=USERNAME_MAXLEN) if not re.match(r'[a-z_][a-z0-9_-]*', username): - return _("Username must match NAME_REGEX, i.e. [a-z_][a-z0-9_-]*") + return _( + "Username must match USERNAME_REGEX: " + USERNAME_REGEX) if username in self.reserved_usernames: return _(