diff options
| author | Scott Bahling <sbahling@suse.de> | 2017-11-01 12:13:45 +0100 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.de> | 2017-11-01 12:13:45 +0100 |
| commit | da1e9fd7c1236b17590946aff5a7ae638d50c6df (patch) | |
| tree | 42bf807ff6d5e44f8db1f40fca454100928fdefd /obsapi/httpapi.py | |
| parent | d8640ac161de82ff0e1f925d0c39f48067d4479a (diff) | |
| download | obsapi-0.0.7.tar.gz obsapi-0.0.7.tar.xz obsapi-0.0.7.zip | |
Only call osc.conf.get_config() when neededobsapi-0.0.7
osc.conf.get_config() can cause calls to password managers like kwallet.
Move this action from module init to the functions that actually need
to access the OBS api and require authentication. We also cache the results
in a local variable now.
Diffstat (limited to 'obsapi/httpapi.py')
| -rw-r--r-- | obsapi/httpapi.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/obsapi/httpapi.py b/obsapi/httpapi.py index 8334224..8ca49e8 100644 --- a/obsapi/httpapi.py +++ b/obsapi/httpapi.py @@ -6,7 +6,6 @@ from null import Null try: import osc.conf as osc_conf - osc_conf.get_config() except: osc_conf = None @@ -20,15 +19,20 @@ class ObsHttpApi(object): def __init__(self, apiurl=None): self.apiurl = apiurl or DEFAULTAPIURL - self.__get_auth() + self._auth = {} self._response = Null() self.retries = 3 self.verify_ssl = True + @property + def __auth(self): + return self._auth.get(self.apiurl, self.__get_auth()) + def __get_auth(self): conf = {} if osc_conf: try: + osc_conf.get_config() conf = osc_conf.get_apiurl_api_host_options(self.apiurl) except: pass @@ -36,9 +40,11 @@ class ObsHttpApi(object): user = conf.get('user', None) password = conf.get('pass', None) if user and password: - self.auth = HTTPBasicAuth(user, password) + self._auth[self.apiurl] = HTTPBasicAuth(user, password) else: - self.auth = None + self._auth[self.apiurl] = None + + return self._auth[self.apiurl] def __api_get(self, api, params=None): @@ -46,7 +52,7 @@ class ObsHttpApi(object): def try_get(): r = requests.get(url, - auth=self.auth, + auth=self.__auth, params=params, verify=self.verify_ssl) self._response = r @@ -68,7 +74,7 @@ class ObsHttpApi(object): url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api) r = requests.put(url, - auth=self.auth, + auth=self.__auth, data=data, params=params, verify=self.verify_ssl) @@ -80,7 +86,7 @@ class ObsHttpApi(object): url = '{0}{1}{2}'.format(self.apiurl, self.rootapi, api) r = requests.post(url, - auth=self.auth, + auth=self.__auth, data=data, params=params, verify=self.verify_ssl) |
