mirror of
https://github.com/ansible/awx.git
synced 2026-03-30 23:35:05 -02:30
AC-454. Update SCM URL validation and error messages, check for special github/bitbucket URLs.
This commit is contained in:
@@ -140,10 +140,14 @@ def update_scm_url(scm_type, url, username=True, password=True):
|
||||
# hg: http://www.selenic.com/mercurial/hg.1.html#url-paths
|
||||
# svn: http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.reposurls
|
||||
if scm_type not in ('git', 'hg', 'svn'):
|
||||
raise ValueError('unsupported SCM type "%s"' % str(scm_type))
|
||||
raise ValueError('Unsupported SCM type "%s"' % str(scm_type))
|
||||
if not url.strip():
|
||||
return ''
|
||||
parts = urlparse.urlsplit(url)
|
||||
try:
|
||||
parts.port
|
||||
except ValueError:
|
||||
raise ValueError('Invalid %s URL' % scm_type)
|
||||
#print parts
|
||||
if '://' not in url:
|
||||
# Handle SCP-style URLs for git (e.g. [user@]host.xz:path/to/repo.git/).
|
||||
@@ -153,6 +157,9 @@ def update_scm_url(scm_type, url, username=True, password=True):
|
||||
modified_url = '@'.join([userpass, hostpath])
|
||||
parts = urlparse.urlsplit('ssh://%s' % modified_url)
|
||||
elif scm_type == 'git' and ':' in url:
|
||||
if url.count(':') > 1:
|
||||
raise ValueError('Invalid %s URL' % scm_type)
|
||||
|
||||
modified_url = '/'.join(url.split(':', 1))
|
||||
parts = urlparse.urlsplit('ssh://%s' % modified_url)
|
||||
# Handle local paths specified without file scheme (e.g. /path/to/foo).
|
||||
@@ -163,7 +170,7 @@ def update_scm_url(scm_type, url, username=True, password=True):
|
||||
else:
|
||||
parts = urlparse.urlsplit('file://%s' % url)
|
||||
else:
|
||||
raise ValueError('unsupported %s URL "%s"' % (scm_type, url))
|
||||
raise ValueError('Invalid %s URL' % scm_type)
|
||||
#print parts
|
||||
# Validate that scheme is valid for given scm_type.
|
||||
scm_type_schemes = {
|
||||
@@ -172,11 +179,11 @@ def update_scm_url(scm_type, url, username=True, password=True):
|
||||
'svn': ('http', 'https', 'svn', 'svn+ssh'),
|
||||
}
|
||||
if parts.scheme not in scm_type_schemes.get(scm_type, ()):
|
||||
raise ValueError('unsupported %s scheme "%s"' % (scm_type, parts.scheme))
|
||||
raise ValueError('Unsupported %s URL' % scm_type)
|
||||
if parts.scheme == 'file' and parts.netloc not in ('', 'localhost'):
|
||||
raise ValueError('unsupported host "%s" for file:// URL' % (parts.netloc))
|
||||
raise ValueError('Unsupported host "%s" for file:// URL' % (parts.netloc))
|
||||
elif parts.scheme != 'file' and not parts.netloc:
|
||||
raise ValueError('host is required for %s URL' % parts.scheme)
|
||||
raise ValueError('Host is required for %s URL' % parts.scheme)
|
||||
if username is True:
|
||||
netloc_username = parts.username or ''
|
||||
elif username:
|
||||
@@ -189,6 +196,19 @@ def update_scm_url(scm_type, url, username=True, password=True):
|
||||
netloc_password = password
|
||||
else:
|
||||
netloc_password = ''
|
||||
|
||||
# Special handling for github/bitbucket SSH URLs.
|
||||
special_git_hosts = ('github.com', 'bitbucket.org', 'altssh.bitbucket.org')
|
||||
if scm_type == 'git' and parts.scheme == 'ssh' and parts.hostname in special_git_hosts and netloc_username != 'git':
|
||||
raise ValueError('Username must be "git" for SSH access to %s.' % parts.hostname)
|
||||
if scm_type == 'git' and parts.scheme == 'ssh' and parts.hostname in special_git_hosts and netloc_password:
|
||||
raise ValueError('Password not allowed for SSH access to %s.' % parts.hostname)
|
||||
special_hg_hosts = ('bitbucket.org', 'altssh.bitbucket.org')
|
||||
if scm_type == 'hg' and parts.scheme == 'ssh' and parts.hostname in special_hg_hosts and netloc_username != 'hg':
|
||||
raise ValueError('Username must be "hg" for SSH access to %s.' % parts.hostname)
|
||||
if scm_type == 'hg' and parts.scheme == 'ssh' and netloc_password:
|
||||
raise ValueError('Password not supported for SSH with Mercurial.')
|
||||
|
||||
if netloc_username and parts.scheme != 'file':
|
||||
netloc = u':'.join(filter(None, [netloc_username, netloc_password]))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user