in modular-service-cli/modular_service_cli/service/utils.py [0:0]
def validate_api_link(url: str) -> str | None:
url = url.lstrip()
if "://" in url and not url.lower().startswith("http"):
return 'Invalid API link: not supported scheme'
try:
scheme, auth, host, port, path, query, fragment = parse_url(url)
except LocationParseError as e:
return 'Invalid API link'
if not scheme:
return 'Invalid API link: missing scheme'
if not host:
return 'Invalid API link: missing host'
try:
req = urllib.request.Request(url)
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
pass
except urllib.error.URLError as e:
return 'Invalid API link: cannot make a request'