diff options
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) |
