Skip to content

Commit 4c4873a

Browse files
committed
base: Abide specified configpath when writing API key
Signed-off-by: Cole Robinson <[email protected]>
1 parent 97f9b7a commit 4c4873a

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

bugzilla/_authfiles.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,18 @@ def _default_config_location(filename):
107107
return _default_location(filename, 'config')
108108

109109

110-
def _save_api_key(url, api_key):
110+
def _save_api_key(url, api_key, configpaths):
111111
"""
112112
Save the API_KEY in the config file.
113113
114114
If tokenfile and cookiefile are undefined, it means that the
115115
API was called with --no-cache-credentials and no change will be
116116
made
117117
"""
118-
config_filename = _default_config_location('bugzillarc')
118+
if configpaths:
119+
config_filename = configpaths[0]
120+
else:
121+
config_filename = _default_config_location('bugzillarc')
119122
section = _parse_hostname(url)
120123

121124
cfg = ConfigParser()
@@ -124,7 +127,7 @@ def _save_api_key(url, api_key):
124127
if section not in cfg.sections():
125128
cfg.add_section(section)
126129

127-
cfg[section]['api_key'] = api_key.strip()
130+
cfg.set(section, 'api_key', api_key.strip())
128131

129132
with open(config_filename, 'w') as configfile:
130133
cfg.write(configfile)

bugzilla/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,13 @@ def interactive_login(self, user=None, password=None, force=False,
582582
log.info('Checking API key... ')
583583
self.connect()
584584

585-
if not self.logged_in:
585+
if not self.logged_in: # pragma: no cover
586586
raise BugzillaError("Login with API_KEY failed")
587587
log.info('API Key accepted')
588588

589-
if self._use_creds:
590-
_save_api_key(self.url, self.api_key)
591-
else:
589+
if self._use_creds or self.configpath:
590+
_save_api_key(self.url, self.api_key, self.configpath)
591+
else: # pragma: no cover
592592
log.info("API Key won't be updated because use_creds=False")
593593
return
594594

0 commit comments

Comments
 (0)