Skip to content

Commit e5f9720

Browse files
committed
Eliminate uses of requests library in src/azul/service/drs_controller.py (#7633)
1 parent e855cea commit e5f9720

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/azul/service/drs_controller.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from more_itertools import (
2929
one,
3030
)
31-
import requests
3231

3332
from azul import (
3433
CatalogName,
@@ -47,6 +46,9 @@
4746
drs_object_uri,
4847
drs_object_url_path,
4948
)
49+
from azul.http import (
50+
HasCachedHttpClient,
51+
)
5052
from azul.openapi import (
5153
responses,
5254
schema,
@@ -66,7 +68,7 @@
6668
)
6769

6870

69-
class DRSController(ServiceAppController):
71+
class DRSController(ServiceAppController, HasCachedHttpClient):
7072

7173
@cached_property
7274
def service(self) -> RepositoryService:
@@ -149,7 +151,9 @@ def dss_get_file(self, file_uuid, replica, **kwargs):
149151
**kwargs
150152
}
151153
url = self.dss_file_url(file_uuid)
152-
return requests.get(str(url), params=dss_params, allow_redirects=False)
154+
return self._http_client.request('GET', str(url),
155+
fields=dss_params,
156+
redirect=False)
153157

154158
@classmethod
155159
def dss_file_url(cls, file_uuid: str) -> mutable_furl:
@@ -177,7 +181,9 @@ def _dos_gs_url(self, file_uuid, version) -> mutable_furl:
177181
replica='gcp')
178182
while True:
179183
if self.lambda_context.get_remaining_time_in_millis() / 1000 > 3:
180-
dss_response = requests.get(url, params=params, allow_redirects=False)
184+
dss_response = self._http_client.request('GET', url,
185+
fields=params,
186+
redirect=False)
181187
if dss_response.status_code == 302:
182188
url = furl(dss_response.next.url)
183189
assert url.scheme == 'gs', R('Expected a gs:// URL', url)
@@ -238,7 +244,7 @@ class GatewayTimeoutError(ChaliceViewError):
238244

239245

240246
@dataclass
241-
class DRSObject:
247+
class DRSObject(HasCachedHttpClient):
242248
""""
243249
Used to build up a https://ga4gh.github.io/data-repository-service-schemas/docs/#_drsobject
244250
"""
@@ -264,7 +270,7 @@ def add_access_method(self,
264270
def to_json(self) -> JSON:
265271
args = adict(replica='aws', version=self.version)
266272
url = DRSController.dss_file_url(self.uuid).add(args=args)
267-
headers = requests.head(url).headers
273+
headers = self._http_client.request('HEAD', url).headers
268274
version = headers['x-dss-version']
269275
if self.version is not None:
270276
assert version == self.version

0 commit comments

Comments
 (0)