def _check_location_uri(context, store_api, store_utils, uri, backend=None): """Check if an image location is valid. :param context: Glance request context :param store_api: store API module :param store_utils: store utils module :param uri: location's uri string :param backend: A backend name for the store """ try: # NOTE(zhiyan): Some stores return zero when it catch exception if CONF.enabled_backends: size_from_backend = store_api.get_size_from_uri_and_backend( uri, backend, context=context) else: size_from_backend = store_api.get_size_from_backend( uri, context=context) is_ok = (store_utils.validate_external_location(uri) and size_from_backend > 0) except (store.UnknownScheme, store.NotFound, store.BadStoreUri): is_ok = False if not is_ok: reason = _('Invalid location') raise exception.BadStoreUri(message=reason)
def validate_external_location(self, uri): if uri and urllib.parse.urlparse(uri).scheme: return store_utils.validate_external_location(uri) else: return True
def validate_external_location(self, uri): if uri and urlparse.urlparse(uri).scheme: return store_utils.validate_external_location(uri) else: return True