require a valid netloc for Credential Type inputs w/ format=url

This commit is contained in:
Ryan Petrello
2019-05-02 14:32:24 -04:00
parent de56e20f11
commit e560dccd36
2 changed files with 18 additions and 15 deletions

View File

@@ -493,13 +493,17 @@ def format_ssh_private_key(value):
@JSONSchemaField.format_checker.checks('url')
def format_url(value):
try:
scheme = urllib.parse.urlparse(value).scheme
parsed = urllib.parse.urlparse(value)
except Exception as e:
raise jsonschema.exceptions.FormatError(str(e))
if scheme == '':
if parsed.scheme == '':
raise jsonschema.exceptions.FormatError(
'Invalid URL: Missing url scheme (http, https, etc.)'
)
if parsed.netloc == '':
raise jsonschema.exceptions.FormatError(
'Invalid URL: {}'.format(value)
)
return True