Exemple #1
0
    def resolve_asset_location(self, asset_url):
        """Retrieve the data asset from the url.

        Returns the asset as a bytestring.

        :param asset_url: URL to retrieve the data asset from
        """
        url_parts = urlparse(asset_url)

        if url_parts.scheme in ['http', 'https']:
            try:
                resp = requests.get(asset_url)
            except Exception as ex:
                raise errors.InvalidAssetLocation(
                    "Failed retrieving asset: %s - %s" %
                    (type(ex).__name__, str(ex)))
            return resp.content
        elif url_parts.scheme in [
                'promenade+http', 'promenade+https', 'deckhand+http',
                'deckhand+https'
        ]:
            try:
                ks_sess = KeystoneUtils.get_session()
                url_parts.scheme = re.sub('^[^+]+\+', '', url_parts.scheme)
                new_url = urlunparse(url_parts)
                resp = ks_sess.get(new_url)
            except Exception as ex:
                raise errors.InvalidAssetLocation(
                    "Failed retrieving asset: %s - %s" %
                    (type(ex).__name__, str(ex)))
            return resp.content
        else:
            raise errors.InvalidAssetLocation("Unknown scheme %s" %
                                              url_parts.scheme)
Exemple #2
0
    def resolve_asset_location(self, asset_url):
        """Retrieve the data asset from the url.

        Returns the asset as a bytestring.

        :param asset_url: URL to retrieve the data asset from
        """
        try:
            return ReferenceResolver.resolve_reference(asset_url)
        except Exception as ex:
            raise errors.InvalidAssetLocation(
                "Unable to resolve asset reference %s: %s" % (asset_url,
                                                              str(ex)))