blob: 0641dc8540c85eb8da1609c79ce909fa2744140b [file] [log] [blame]
"""This module provides the gcs_mirror_url macro."""
# Set to True to force the macro to only return the mirror URL.
# Must be kept in sync with the suffixes supported by gcs_mirror (e.g.
_SUPPORTED_SUFFIXES = [".tar.gz", ".tgz", ".tar.xz", ".deb", ".zip"]
def gcs_mirror_url(url, sha256):
"""Takes the URL of an external resource and computes its GCS mirror URL.
We store backup copies of external resources in the skia-world-readable GCS bucket. This macro
returns a list with two elements: the original URL, and the mirrored URL.
To mirror a new URL, please use the `gcs_mirror` utility found at
url: URL of the mirrored resource.
sha256: SHA256 hash of the mirrored resource.
A list of the form [original URL, mirror URL].
extension = ""
for suffix in _SUPPORTED_SUFFIXES:
if url.endswith(suffix):
extension = suffix
if extension == "":
fail("URL %s has an unsupported suffix." % url)
mirror_url = "%s/%s.%s" % (_GCS_MIRROR_PREFIX, sha256, extension)
return [mirror_url] if _TEST_GCS_MIRROR else [url, mirror_url]