def update(self, plugin: RepositoryPlugin, authentication: Optional[Authentication] ) -> None: assert isinstance(plugin, Plugin) url = plugin.direct_file_url(file_uuid=self.file_uuid, file_version=self.file_version, replica=None) self._location = url
def update(self, plugin: RepositoryPlugin, authentication: Optional[Authentication]) -> None: self.drs_path = None # to shorten the retry URLs if self.replica is None: self.replica = 'aws' assert isinstance(plugin, Plugin) dss_url = plugin.direct_file_url(file_uuid=self.file_uuid, file_version=self.file_version, replica=self.replica, token=self.token) dss_response = requests.get(dss_url, allow_redirects=False) if dss_response.status_code == 301: retry_after = int(dss_response.headers.get('Retry-After')) location = dss_response.headers['Location'] location = urllib.parse.urlparse(location) query = urllib.parse.parse_qs(location.query, strict_parsing=True) self.token = one(query['token']) self.replica = one(query['replica']) self.file_version = one(query['version']) self._retry_after = retry_after elif dss_response.status_code == 302: location = dss_response.headers['Location'] # Remove once https://github.com/HumanCellAtlas/data-store/issues/1837 is resolved if True: location = urllib.parse.urlparse(location) query = urllib.parse.parse_qs(location.query, strict_parsing=True) expires = int(one(query['Expires'])) bucket = location.netloc.partition('.')[0] dss_endpoint = one(plugin.sources).name assert bucket == aws.dss_checkout_bucket(dss_endpoint), bucket with aws.direct_access_credentials(dss_endpoint, lambda_name='service'): # FIXME: make region configurable (https://github.com/DataBiosphere/azul/issues/1560) s3 = aws.client('s3', region_name='us-east-1') params = { 'Bucket': bucket, 'Key': location.path[1:], 'ResponseContentDisposition': 'attachment;filename=' + self.file_name, } location = s3.generate_presigned_url( ClientMethod=s3.get_object.__name__, ExpiresIn=round(expires - time.time()), Params=params) self._location = location else: dss_response.raise_for_status() assert False