summaryrefslogtreecommitdiff
path: root/obsapi
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.de>2017-11-01 12:13:45 +0100
committerScott Bahling <sbahling@suse.de>2017-11-01 12:13:45 +0100
commitda1e9fd7c1236b17590946aff5a7ae638d50c6df (patch)
tree42bf807ff6d5e44f8db1f40fca454100928fdefd /obsapi
parentd8640ac161de82ff0e1f925d0c39f48067d4479a (diff)
downloadobsapi-da1e9fd7c1236b17590946aff5a7ae638d50c6df.tar.gz
obsapi-da1e9fd7c1236b17590946aff5a7ae638d50c6df.tar.xz
obsapi-da1e9fd7c1236b17590946aff5a7ae638d50c6df.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')
-rw-r--r--obsapi/core.py6
-rw-r--r--obsapi/httpapi.py20
2 files changed, 13 insertions, 13 deletions
diff --git a/obsapi/core.py b/obsapi/core.py
index 5200efe..090c953 100644
--- a/obsapi/core.py
+++ b/obsapi/core.py
@@ -8,12 +8,6 @@ from obsapi.sourceapi import ObsSourceApi
from obsapi.buildapi import ObsBuildApi
from obsapi.formatter import Formatter
-try:
- import osc.conf as osc_conf
- osc_conf.get_config()
-except:
- osc_conf = None
-
LSItem = namedtuple('LSItem', 'name md5 size mtime')
Directory = namedtuple('Directory', 'name rev vrev srcmd5')
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)