Commits

Anonymous committed 6a5ae21

[svn r5698] Added support for configuring hudson authentication info. This closes #4113.

  • Participants
  • Parent commits cc3edbf

Comments (0)

Files changed (2)

File 0.10/HudsonTrac/HudsonTracPlugin.py

 import time
 import calendar
 import feedparser
-import urllib
+import urlparse
+import urllib2
 from datetime import datetime
 from trac.core import *
 from trac.config import Option, BoolOption
     feed_url = Option('hudson', 'feed_url', 'http://localhost/hudson/rssAll',
                       'The url of the hudson rss feed containing the build ' +
                       'statuses. This must be an absolute url.')
+    username = Option('hudson', 'username', '',
+                      'The username to use to access hudson (feed and details)')
+    password = Option('hudson', 'password', '',
+                      'The password to use to access hudson (feed and details)')
     nav_url  = Option('hudson', 'main_page', '/hudson/',
                       'The url of the hudson main page to which the trac nav ' +
                       'entry should link; if empty, no entry is created in ' +
     disp_tab = BoolOption('hudson', 'display_in_new_tab', 'false',
                           'Open hudson page in new tab/window')
 
+    def __init__(self):
+        pwdMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
+        pwdMgr.add_password(None, urlparse.urlsplit(self.feed_url)[1], self.username, self.password)
+
+        self.bAuth = urllib2.HTTPBasicAuthHandler(pwdMgr)
+        self.dAuth = urllib2.HTTPDigestAuthHandler(pwdMgr)
+
+        self.url_opener = urllib2.build_opener(self.bAuth, self.dAuth)
+
     # INavigationContributor methods
 
     def get_active_navigation_item(self, req):
         if 'build' in filters:
             add_stylesheet(req, 'HudsonTrac/hudsontrac.css')
 
-            feed = feedparser.parse(self.feed_url)
+            feed = feedparser.parse(self.feed_url, handlers=[self.bAuth, self.dAuth])
 
             for entry in feed.entries:
                 # Only look at top-level entries
                 title = entry.title
 
                 url = href + '/api/json'
-                line = urllib.urlopen(url).readline()
+                line = self.url_opener.open(url).readline()
                 json = eval(line.replace('false', 'False').replace('true','True').replace('null', 'None'))
 
                 if json['description'] == None:

File 0.10/setup.py

 
 setup(
     name = 'HudsonTrac',
-    version = '0.1',
+    version = '0.2',
     author = "Ronald Tschalär",
     description = "A trac plugin to add hudson build info to the trac timeline",
     license = "BSD",