Skip to content

Commit 29b475d

Browse files
authored
Remove minio config info from the servicex file (#140)
Fixes #108
1 parent 3d99398 commit 29b475d

File tree

4 files changed

+11
-125
lines changed

4 files changed

+11
-125
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The API access information is normally placed in a `.servicex` file (to keep thi
3333
directory on Windows).
3434
1. The `config_defaults.yaml` file distributed with the `servicex` package.
3535

36-
If no endpoint is specified, then the library defaults to the developer endpoint, which is `http://localhost:5000` for the web-service API, and `localhost:9000` for the `minio` endpoint. No passwords are required.
36+
If no endpoint is specified, then the library defaults to the developer endpoint, which is `http://localhost:5000` for the web-service API. No passwords are used in this case.
3737

3838
Create a `.servicex` file, in the `yaml` format, in the appropriate place for your work that contains the following (for the `xaod` backend; use `uproot` for the uproot backend):
3939

@@ -151,7 +151,6 @@ The file can contain an `api_endpoint` as mentioned above. In addition the other
151151
- Windows: `cache_path: "C:\\Users\\gordo\\Desktop\\cacheme"`
152152
- Linux: `cache_path: "/home/servicex-cache"`
153153

154-
- `minio_endpoint`, `minio_username`, `minio_password` - these are only interesting if you are using a pre-RC2 release of `servicex` - when the `minio` information wasn't part of the API exchange. This feature is depreciated and will be removed around the time `servicex` moves to RC3.
155154
- `backend_types` - a list of yaml dictionaries that contains some defaults for the backends. By default only the `return_data` is there, which for `xaod` is `root` and `uproot` is `parquet`. Allows `servicex` to convert to `pandas.DataFrame` or `awkward` if requested by the user.
156155

157156
All strings are expanded using python's [os.path.expand](https://docs.python.org/3/library/os.path.html#os.path.expandvars) method - so `$NAME` and `${NAME}` will work to expand existing environment variables.

servicex/config_default.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ api_endpoints:
55
- endpoint: http://localhost:5000
66
# token: xxx
77

8-
# These are default settings, depreciated, and should not be used.
9-
# They will be removed in the next version.
10-
api_endpoint:
11-
minio_endpoint: localhost:9000
12-
# The username and password for accessing files generated by servicex.
13-
# NOTE:
14-
# 1. If minio_username and password are specified they will be used.
15-
# 2. If only an endpoint username password is specified they will be used.
16-
# 3. If nothing is specified, then the default_xxxx username passwords will be used.
17-
# minio_password: xxxx
18-
# minio_username: xxxx
19-
default_minio_username: miniouser
20-
default_minio_password: leftfoot1
21-
228
# This is the path of the cache. The "/tmp" will be translated, platform appropriate.
239
cache_path: /tmp/servicex
2410

servicex/minio_adaptor.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
import asyncio
2929
from concurrent.futures.thread import ThreadPoolExecutor
3030
from pathlib import Path
31-
from typing import Any, AsyncIterator, Optional, cast, Dict
31+
from typing import Any, AsyncIterator, List, Optional, Dict, cast
3232
import logging
3333

3434
import backoff
3535
from backoff import on_exception
36-
from confuse import ConfigView
3736
from minio import Minio, ResponseError
3837

3938
from .utils import ServiceXException
@@ -59,8 +58,8 @@ def __init__(self, minio_endpoint: str,
5958
secure=self._secured)
6059

6160
@on_exception(backoff.constant, ResponseError, interval=0.1)
62-
def get_files(self, request_id):
63-
return [f.object_name for f in self._client.list_objects(request_id)]
61+
def get_files(self, request_id) -> List[str]:
62+
return [str(f.object_name) for f in self._client.list_objects(request_id)]
6463

6564
async def download_file(self,
6665
request_id: str,
@@ -106,8 +105,7 @@ class MinioAdaptorFactory:
106105
'''A factor that will return, when asked, the proper minio adaptor to use for a request
107106
to get files from ServiceX.
108107
'''
109-
def __init__(self, c: Optional[ConfigView] = None,
110-
always_return: Optional[MinioAdaptor] = None):
108+
def __init__(self, always_return: Optional[MinioAdaptor] = None):
111109
'''Create the factor with a possible adaptor to always use
112110
113111
Args:
@@ -117,8 +115,6 @@ def __init__(self, c: Optional[ConfigView] = None,
117115
# Get the defaults setup.
118116
self._always = always_return
119117
self._config_adaptor = None
120-
if self._always is None and c is not None:
121-
self._config_adaptor = self._from_config(c)
122118

123119
def from_best(self, transaction_info: Optional[Dict[str, str]] = None) -> MinioAdaptor:
124120
'''Using the information we have, create the proper Minio Adaptor with the correct
@@ -143,41 +139,11 @@ def from_best(self, transaction_info: Optional[Dict[str, str]] = None) -> MinioA
143139
if all(k in transaction_info for k in keys):
144140
logging.getLogger(__name__).debug('Using the request-specific minio_adaptor')
145141
return MinioAdaptor(transaction_info['minio-endpoint'],
146-
transaction_info['minio-secured'],
142+
bool(transaction_info['minio-secured']),
147143
transaction_info['minio-access-key'],
148144
transaction_info['minio-secret-key'])
149-
if self._config_adaptor is not None:
150-
logging.getLogger(__name__).debug('Using the config-file minio_adaptor')
151-
return self._config_adaptor
152-
raise ServiceXException("Do not know how to create a Minio Login info")
153-
154-
def _from_config(self, c: ConfigView) -> MinioAdaptor:
155-
'''Extract the Minio config information from the config file(s). This will be used
156-
if minio login information isn't returned from the request.
157-
158-
Args:
159-
c (ConfigView): The loaded config
160-
161-
Returns:
162-
MinioAdaptor: The adaptor that uses the config's login information.
163-
'''
164-
c_api = c['api_endpoint']
165-
end_point = cast(str, c_api['minio_endpoint'].as_str_expanded())
166-
167-
# Grab the username and password if they are explicitly listed.
168-
if 'minio_username' in c_api:
169-
username = c_api['minio_username'].as_str_expanded()
170-
password = c_api['minio_password'].as_str_expanded()
171-
elif 'username' in c_api:
172-
username = c_api['username'].as_str_expanded()
173-
password = c_api['password'].as_str_expanded()
174-
else:
175-
username = c_api['default_minio_username'].as_str_expanded()
176-
password = c_api['default_minio_password'].as_str_expanded()
177-
178-
return MinioAdaptor(end_point,
179-
access_key=cast(str, username),
180-
secretkey=cast(str, password))
145+
raise ServiceXException("Do not know or have enough information to create a Minio "
146+
f"Login info ({transaction_info})")
181147

182148

183149
async def find_new_bucket_files(adaptor: MinioAdaptor,
@@ -190,7 +156,7 @@ async def find_new_bucket_files(adaptor: MinioAdaptor,
190156
seen = []
191157
async for _ in update:
192158
# Sadly, this is blocking, and so may hold things up
193-
files = adaptor.get_files(request_id)
159+
files = cast(List[str], adaptor.get_files(request_id))
194160

195161
# If there are new files, pass them on
196162
for f in files:

tests/test_minio_adaptor.py

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ def test_list_objects(good_minio_client):
134134
ma = MinioAdaptor('localhost:9000')
135135

136136
f = ma.get_files('111-222-333-444')
137-
assert len(f) == 1
137+
assert len(f) == 1 # type: ignore
138138

139139

140140
def test_list_objects_with_null(bad_then_good_minio_listing):
141141
'''Sometimes for reasons we do not understand we get back a response error from
142142
list_objects minio method'''
143143
ma = MinioAdaptor('localhost:9000')
144144
f = ma.get_files('111-222-333-444')
145-
assert len(f) == 1
145+
assert len(f) == 1 # type: ignore
146146

147147

148148
@pytest.mark.asyncio
@@ -178,55 +178,6 @@ def test_factor_always():
178178
assert f.from_best() is a
179179

180180

181-
def test_factory_set_endpoint():
182-
from confuse import Configuration
183-
c = Configuration('bogus', 'bogus')
184-
c.clear()
185-
c['api_endpoint']['minio_endpoint'] = 'the-good-host.org:9000'
186-
c['api_endpoint']['minio_username'] = 'amazing'
187-
c['api_endpoint']['minio_password'] = 'forkingshirtballs'
188-
189-
c['api_endpoint']['default_minio_username'] = 'badnews'
190-
c['api_endpoint']['default_minio_password'] = 'bears'
191-
192-
m = MinioAdaptorFactory(c).from_best()
193-
assert m._endpoint == 'the-good-host.org:9000'
194-
assert m._access_key == "amazing"
195-
assert m._secretkey == "forkingshirtballs"
196-
197-
198-
def test_factory_use_api_usernamepassword():
199-
from confuse import Configuration
200-
c = Configuration('bogus', 'bogus')
201-
c.clear()
202-
203-
c['api_endpoint']['endpoint'] = 'http://my-left-foot.com:5000'
204-
c['api_endpoint']['username'] = 'thegoodplace'
205-
c['api_endpoint']['password'] = 'forkingshirtballs!'
206-
207-
c['api_endpoint']['minio_endpoint'] = 'the-good-host.org:9000'
208-
209-
m = MinioAdaptorFactory(c).from_best()
210-
assert m._endpoint == 'the-good-host.org:9000'
211-
assert m._access_key == "thegoodplace"
212-
assert m._secretkey == "forkingshirtballs!"
213-
214-
215-
def test_factory_use_default_username_password():
216-
from confuse import Configuration
217-
c = Configuration('bogus', 'bogus')
218-
c.clear()
219-
220-
c['api_endpoint']['minio_endpoint'] = 'the-good-host.org:9000'
221-
c['api_endpoint']['default_minio_username'] = 'thegoodplace'
222-
c['api_endpoint']['default_minio_password'] = 'forkingshirtballs!'
223-
224-
m = MinioAdaptorFactory(c).from_best()
225-
assert m._endpoint == 'the-good-host.org:9000'
226-
assert m._access_key == "thegoodplace"
227-
assert m._secretkey == "forkingshirtballs!"
228-
229-
230181
def test_factory_from_request():
231182
info = {
232183
'minio-access-key': 'miniouser',
@@ -239,19 +190,3 @@ def test_factory_from_request():
239190
assert not m._secured
240191
assert m._access_key == "miniouser"
241192
assert m._secretkey == "leftfoot1"
242-
243-
244-
def test_factory_request_missing():
245-
info = {}
246-
from confuse import Configuration
247-
c = Configuration('bogus', 'bogus')
248-
c.clear()
249-
250-
c['api_endpoint']['minio_endpoint'] = 'the-good-host.org:9000'
251-
c['api_endpoint']['default_minio_username'] = 'thegoodplace'
252-
c['api_endpoint']['default_minio_password'] = 'forkingshirtballs!'
253-
254-
m = MinioAdaptorFactory(c).from_best(info)
255-
assert m._endpoint == 'the-good-host.org:9000'
256-
assert m._access_key == "thegoodplace"
257-
assert m._secretkey == "forkingshirtballs!"

0 commit comments

Comments
 (0)