summaryrefslogtreecommitdiff
path: root/obsapi/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'obsapi/core.py')
-rw-r--r--obsapi/core.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/obsapi/core.py b/obsapi/core.py
index ba1ca0b..31782d9 100644
--- a/obsapi/core.py
+++ b/obsapi/core.py
@@ -1,6 +1,13 @@
import requests
+from requests.auth import HTTPBasicAuth
from lxml import etree
from collections import namedtuple
+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')
@@ -121,10 +128,25 @@ class ObsApi(object):
def __init__(self, apiurl=None):
self.apiurl = apiurl or DEFAULTAPIURL
+ self.__get_auth()
+
+ def __get_auth(self):
+ if osc_conf:
+ try:
+ conf = osc_conf.get_apiurl_api_host_options(self.apiurl)
+ except:
+ conf = {}
+
+ user = conf.get('user', None)
+ password = conf.get('pass', None)
+ if user and password:
+ self.auth = HTTPBasicAuth(user, password)
+ else:
+ self.auth = None
def __api_get(self, api, payload=None):
url = '{0}/{1}'.format(self.apiurl, api)
- r = requests.get(url, params=payload)
+ r = requests.get(url, auth=self.auth, params=payload)
return r