Skip to content

Commit e336fbc

Browse files
committed
enable environment variable, configuration file and default for "plugincoupling"
1 parent b9ade44 commit e336fbc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

qiita_client/plugin.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ def __call__(self, server_url, job_id, output_dir):
282282
with open(self.conf_fp, 'U') as conf_file:
283283
config.readfp(conf_file)
284284

285+
# the plugin coupling protocoll can be set in three ways
286+
# 1. default is always "filesystem", i.e. first value in
287+
# _ALLOWED_PLUGIN_COUPLINGS. This is to be downward compatible.
288+
# 2. the plugin configuration can hold a section 'network' with an
289+
# option 'PLUGINCOUPLING'. For old config files, this might not
290+
# (yet) be the case. Therefore, we are double checking existance
291+
# of this section and parameter here.
292+
# 3. you can set the environment variable QIITA_PLUGINCOUPLING
293+
# Precedence is 3, 2, 1, i.e. the environment variable overrides the
294+
# other two ways.
295+
plugincoupling = self._ALLOWED_PLUGIN_COUPLINGS[0]
296+
if config.has_section('network') and \
297+
config.has_option('network', 'PLUGINCOUPLING'):
298+
plugincoupling = config.get('network', 'PLUGINCOUPLING')
299+
if 'QIITA_PLUGINCOUPLING' in environ.keys() and \
300+
environ['QIITA_PLUGINCOUPLING'] is not None:
301+
plugincoupling = environ['QIITA_PLUGINCOUPLING']
302+
285303
qclient = QiitaClient(server_url, config.get('oauth2', 'CLIENT_ID'),
286304
config.get('oauth2', 'CLIENT_SECRET'),
287305
# for this group of tests, confirm optional
@@ -290,8 +308,7 @@ def __call__(self, server_url, job_id, output_dir):
290308
# from validating the server's cert using
291309
# certifi's pem cache.
292310
ca_cert=config.get('oauth2', 'SERVER_CERT'),
293-
plugincoupling=config.get('network',
294-
'PLUGINCOUPLING'))
311+
plugincoupling=plugincoupling)
295312

296313
if job_id == 'register':
297314
self._register(qclient)

qiita_client/qiita_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def __init__(self, server_url, client_id, client_secret, ca_cert=None,
221221
self._token = None
222222
self._fetch_token()
223223

224+
# store protocol for plugin coupling
224225
self._plugincoupling = plugincoupling
225226

226227
def _fetch_token(self):

0 commit comments

Comments
 (0)