Prevent invalid tags on builds

Fixes #1632
This commit is contained in:
Joseph Schorr 2016-07-25 17:50:35 -07:00
parent 640012103c
commit 0fe3e6510a
5 changed files with 41 additions and 5 deletions

View file

@ -1,15 +1,26 @@
import urllib
import re
from functools import wraps
from uuid import uuid4
REPOSITORY_NAME_REGEX = re.compile(r'^[\.a-zA-Z0-9_-]+$')
TAG_REGEX = re.compile(r'^[\w][\w\.-]{0,127}$')
VALID_TAG_PATTERN = r'[\w][\w.-]{0,127}'
FULL_TAG_PATTERN = r'^[\w][\w.-]{0,127}$'
TAG_REGEX = re.compile(FULL_TAG_PATTERN)
TAG_ERROR = ('Invalid tag: must match [A-Za-z0-9_.-], NOT start with "." or "-", '
'and can contain 1-128 characters')
def escape_tag(tag, default='latest'):
""" Escapes a Docker tag, ensuring it matches the tag regular expression. """
if not tag:
return default
tag = re.sub(r'^[^\w]', '_', tag)
tag = re.sub(r'[^\w\.-]', '_', tag)
return tag[0:127]
def parse_namespace_repository(repository, library_namespace, include_tag=False):
parts = repository.rstrip('/').split('/', 1)