Docker changed their namespace regex, so we need to adjust

Fixes #617
This commit is contained in:
Joseph Schorr 2015-10-14 14:41:39 -04:00
parent e31dda35df
commit a8aa6d1939
2 changed files with 27 additions and 10 deletions

View file

@ -6,7 +6,8 @@ import anunidecode
INVALID_PASSWORD_MESSAGE = 'Invalid password, password must be at least ' + \
'8 characters and contain no whitespace.'
INVALID_USERNAME_CHARACTERS = r'[^a-z0-9_]'
VALID_CHARACTERS = '_' + string.digits + string.lowercase
VALID_CHARACTERS = string.digits + string.lowercase
MIN_LENGTH = 4
MAX_LENGTH = 30
@ -48,8 +49,13 @@ def _gen_filler_chars(num_filler_chars):
def generate_valid_usernames(input_username):
# Docker's regex: [a-z0-9]+(?:[._-][a-z0-9]+)*
normalized = input_username.encode('unidecode', 'ignore').strip().lower()
prefix = re.sub(INVALID_USERNAME_CHARACTERS, '_', normalized)[:30]
prefix = re.sub(r'_{2,}', '_', prefix)
if prefix.endswith('_'):
prefix = prefix[0:len(prefix) - 1]
num_filler_chars = max(0, MIN_LENGTH - len(prefix))