Skip to content

Commit 4ee192a

Browse files
committed
Add a presigned URL to the mix
Working on getting minio direct access async #132
1 parent f0cd089 commit 4ee192a

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

servicex/minio_adaptor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ def __init__(self, minio_endpoint: str,
6262
def get_files(self, request_id):
6363
return [f.object_name for f in self._client.list_objects(request_id)]
6464

65+
def get_access_url(self, request_id: str, object_name: str) -> str:
66+
'''Given a request ID and the file name in that request id, return a URL
67+
that can be directly accessed to download the file.
68+
69+
Args:
70+
request_id (str): The request id guid (that is the bucket in minio)
71+
object_name (str): The file (the object in the minio bucket)
72+
73+
Raises:
74+
NotImplementedError: [description]
75+
76+
Returns:
77+
str: A url good for some amount of time to access the bucket.
78+
'''
79+
return self._client.presigned_get_object(request_id, object_name)
80+
6581
async def download_file(self,
6682
request_id: str,
6783
bucket_fname: str,

servicex/servicex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ async def _get_minio_buckets(self, selection_query: str, data_format: str) \
251251
yield {
252252
'bucket': request_id,
253253
'file': r,
254+
'url': minio_adaptor.get_access_url(request_id, r),
254255
}
255256

256257
# Cache the final status

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class MockMinioAdaptor(MinioAdaptor):
9595
def __init__(self, mocker: MockFixture, files: List[str] = []):
9696
self._files = files
9797
self.mock_download_file = mocker.Mock()
98+
self._access_called_with = None
9899
pass
99100

100101
async def download_file(self, request_id: str, minio_object_name: str, final_path: Path):
@@ -104,6 +105,14 @@ def get_files(self, request_id) -> List[str]:
104105
'Return files in the bucket'
105106
return self._files
106107

108+
def get_access_url(self, request_id: str, object_name: str) -> str:
109+
self._access_called_with = (request_id, object_name)
110+
return "http://the.url.com"
111+
112+
@property
113+
def access_called_with(self) -> Optional[Tuple[str, str]]:
114+
return self._access_called_with
115+
107116

108117
__g_inmem_value = None
109118

tests/test_minio_adaptor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def good_minio_client(mocker):
2626
[make_minio_file('root:::dcache-atlas-xrootd-wan.desy.de:1094::pnfs:desy.de:atlas'
2727
':dq2:atlaslocalgroupdisk:rucio:mc15_13TeV:8a:f1:DAOD_STDM3.05630052'
2828
'._000001.pool.root.198fbd841d0a28cb0d9dfa6340c890273-1.part.minio')]
29+
minio_client.presigned_get_object.return_value = 'http://data.done'
2930

3031
mocker.patch('servicex.minio_adaptor.Minio', return_value=minio_client)
3132

@@ -130,6 +131,13 @@ async def test_download_already_there(mocker, good_minio_client):
130131
p_exists.assert_called_once()
131132

132133

134+
def test_access_url(good_minio_client):
135+
'Make sure the presigned_get_object is properly called'
136+
mn = MinioAdaptor('localhost:9000')
137+
assert mn.get_access_url('123-456', 'file1') == 'http://data.done'
138+
good_minio_client[1].presigned_get_object.assert_called_with('123-456', 'file1')
139+
140+
133141
def test_list_objects(good_minio_client):
134142
ma = MinioAdaptor('localhost:9000')
135143

tests/test_servicex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ async def test_good_run_root_files_from_minio(mocker):
412412
assert len(lst) == 1
413413
assert lst[0]['bucket'] == '123-456'
414414
assert lst[0]['file'] == 'one_minio_entry'
415+
assert lst[0]['url'] == 'http://the.url.com'
415416

416417
assert mock_servicex_adaptor.query_json['result-format'] == 'root-file'
418+
assert mock_minio_adaptor.access_called_with == ('123-456', 'one_minio_entry')
417419

418420

419421
@pytest.mark.asyncio

0 commit comments

Comments
 (0)