summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
authorTim Laszlo <tim.laszlo@gmail.com>2010-07-12 22:14:26 +0000
committerSol Jerome <sol.jerome@gmail.com>2010-07-16 16:36:15 -0500
commit31930aac1c0790304279a380d698c02e62df22b8 (patch)
tree546c02806f8000d13cd2f63614bacc927029ec0e /src/lib/Server
parentd1d0a2e78e2405c8a5f342131712f9f79f16a1c4 (diff)
downloadbcfg2-31930aac1c0790304279a380d698c02e62df22b8.tar.gz
bcfg2-31930aac1c0790304279a380d698c02e62df22b8.tar.bz2
bcfg2-31930aac1c0790304279a380d698c02e62df22b8.zip
Packages: Allow authentication in urls
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5970 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Plugins/Packages.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lib/Server/Plugins/Packages.py b/src/lib/Server/Plugins/Packages.py
index ac20ca1f0..b07720f6a 100644
--- a/src/lib/Server/Plugins/Packages.py
+++ b/src/lib/Server/Plugins/Packages.py
@@ -50,6 +50,19 @@ def source_from_xml(xsource):
ret['url'] += '/'
return ret
+def _fetch_url(url):
+ if '@' in url:
+ mobj = re.match('(\w+://)([^:]+):([^@]+)@(.*)$', url)
+ if not mobj:
+ raise ValueError
+ user = mobj.group(2)
+ passwd = mobj.group(3)
+ url = mobj.group(1) + mobj.group(4)
+ auth = urllib2.HTTPBasicAuthHandler(urllib2.HTTPPasswordMgrWithDefaultRealm())
+ auth.add_password(None, url, user, passwd)
+ urllib2.install_opener(urllib2.build_opener(auth))
+ return urllib2.urlopen(url).read()
+
class Source(object):
basegroups = []
def __init__(self, basepath, url, version, arches, components, groups, rawurl,
@@ -113,7 +126,10 @@ class Source(object):
logger.info("Packages: Updating %s" % url)
fname = self.escape_url(url)
try:
- data = urllib2.urlopen(url).read()
+ data = _fetch_url(url)
+ except ValueError:
+ logger.error("Packages: Bad url string %s" % url)
+ continue
except urllib2.HTTPError, h:
logger.error("Packages: Failed to fetch url %s. code=%s" \
% (url, h.code))
@@ -271,8 +287,15 @@ class YUMSource(Source):
surl += '/'
rmdurl = surl + 'repodata/repomd.xml'
try:
- repomd = urllib2.urlopen(rmdurl).read()
+ repomd = _fetch_url(rmdurl)
xdata = lxml.etree.XML(repomd)
+ except ValueError:
+ logger.error("Packages: Bad url string %s" % rmdurl)
+ continue
+ except urllib2.HTTPError, h:
+ logger.error("Packages: Failed to fetch url %s. code=%s" \
+ % (rmdurl, h.code))
+ continue
except:
logger.error("Failed to process url %s" % rmdurl)
continue