diff options
| author | Scott Bahling <sbahling@suse.de> | 2015-04-19 12:16:39 +0200 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.de> | 2015-04-19 12:16:39 +0200 |
| commit | 942ac9bdbe918873eb4f5984f87d54e1f93efc51 (patch) | |
| tree | 331ebd363e5695c84809452d418aaeb3f93c6115 /obsapi | |
| parent | ca716bc03703a42cccd4bad5254bc18042b17866 (diff) | |
| download | obsapi-942ac9bdbe918873eb4f5984f87d54e1f93efc51.tar.gz obsapi-942ac9bdbe918873eb4f5984f87d54e1f93efc51.tar.xz obsapi-942ac9bdbe918873eb4f5984f87d54e1f93efc51.zip | |
Get OBS authentication from osc if installed
Diffstat (limited to 'obsapi')
| -rw-r--r-- | obsapi/core.py | 24 |
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 |
