def download_google_storage()

in container-filetransfer/cloud-transfer.py [0:0]


def download_google_storage(url, path):
    """
    Downloads a 'gs://' URI from Google Storage. Assumes that the data is
    publicly accessible without authentication.

    TODO: Support signed URIs
    """
    components = urlparse(url)
    query_string = parse_qs(components.query)
    if components.scheme in ['http', 'https']:
        if 'sig' not in query_string:
            logger.warning(f"[google-storage] Skipping download of '{url}' because of incorrect scheme or missing SAS token")
            return False

    if urlparse(url).scheme != 'gs':
        logger.warning(f"[google-storage] Skipping download of '{url}' because of incorrect scheme")
        return False

    if not components.hostname or not components.path:
        logger.warning(f"[google-storage] Skipping upload to '{url}' because expected a hostname in format of 'gs://bucket/object'")
        return False
    bucket = components.hostname
    object = components.path[1:]  # strip the leading /

    url = urljoin('http://storage.googleapis.com/', posixpath.join(bucket, object))
    return download(url, path)