@@ -46,8 +46,13 @@ def repository_ctx_download_common_args(attr, bucket_name, remote_path):
4646 has_sha256 = len (attr .sha256 ) > 0
4747 if has_integrity == has_sha256 :
4848 fail ("expected exactly one of \" integrity\" and \" sha256\" " )
49+ has_generation = len (attr .generation ) > 0
4950 args = {
50- "url" : bucket_url (bucket_name , remote_path ),
51+ "url" : bucket_url (
52+ bucket_name ,
53+ remote_path ,
54+ attr .generation if has_generation else None ,
55+ ),
5156 "sha256" : attr .sha256 ,
5257 "integrity" : attr .integrity ,
5358 }
@@ -79,8 +84,14 @@ def download_and_extract_args(attr, bucket_name, remote_path):
7984 args .pop ("rename_files" )
8085 return args
8186
82- def bucket_url (bucket , object_path ):
83- return "https://storage.googleapis.com/{}/{}" .format (bucket , url_encode (object_path ))
87+ # Use the JSON API, which allows for more options https://cloud.google.com/storage/docs/json_api/v1/objects/get
88+ def bucket_url (bucket , object_path , generation ):
89+ return "https://storage.googleapis.com/storage/v1/b/{}/o/{}?alt=media" .format (
90+ bucket ,
91+ url_encode (object_path ),
92+ ) + ("&generation={}" .format (
93+ generation ,
94+ ) if generation else "" )
8495
8596def deps_from_file (module_ctx , lockfile_label , jsonpath ):
8697 lockfile_path = module_ctx .path (lockfile_label )
@@ -99,6 +110,7 @@ def parse_lockfile(lockfile_content, jsonpath):
99110 # we expect the following schema:
100111 # - exactly one of sha256 or integrity
101112 # - optionally a remote_path (if not, we populate it with the local_path instead)
113+ has_generation = "generation" in v
102114 has_remote_path = "remote_path" in v
103115 has_integrity = "integrity" in v
104116 has_sha256 = "sha256" in v
@@ -109,6 +121,8 @@ def parse_lockfile(lockfile_content, jsonpath):
109121 }
110122 if has_integrity :
111123 info ["integrity" ] = v ["integrity" ]
124+ if has_generation :
125+ info ["generation" ] = v ["generation" ]
112126 if has_sha256 :
113127 info ["sha256" ] = v ["sha256" ]
114128 processed_lockfile [local_path ] = info
0 commit comments