summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2015-02-25 08:54:22 (GMT)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2015-02-25 09:46:48 (GMT)
commitb18f90bea7e5f083e6d553153f8e39c64e6ae77b (patch)
treeeba53dbb558d90fc9b047c7259341bd5df50e2a0
parent33bdc035fab492c30ada1efb39f9d789aa1cba53 (diff)
downloadqa-bughandler-b18f90bea7e5f083e6d553153f8e39c64e6ae77b.tar.gz
qa-bughandler-b18f90bea7e5f083e6d553153f8e39c64e6ae77b.tar.xz
Implement both http auth and xmlrpc based credential passingv5
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
-rwxr-xr-xqa-bughandler.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/qa-bughandler.py b/qa-bughandler.py
index 8d44a61..5432a77 100755
--- a/qa-bughandler.py
+++ b/qa-bughandler.py
@@ -29,7 +29,7 @@ from ConfigParser import ConfigParser
from datetime import datetime
from traceback import format_exc
from urlparse import urlparse, urlunparse
-from xmlrpclib import ServerProxy
+from xmlrpclib import ServerProxy, ProtocolError
import logging
import os
import sys
@@ -149,22 +149,33 @@ class Bugzilla(object):
API methods.
"""
- def __init__(self, url, bug_id, logger, verbose=False):
+ def __init__(self, url, username, password, bug_id, logger, verbose=False):
self.url = url
self.bug_id = bug_id
self.logger = logger
self.verbose = verbose
+ self.username = username
+ self.password = password
self.handler = ServerProxy(self.url, verbose=self.verbose)
+ self.http_auth = False
def login(self, username, password):
"""This method implements the HTTP login, adding the user name and the
password to the url, while keeping the url property of the class still
safe to be displayed/logged.
- Warning: This isn't going to work with bugzilla setups that rely on the
- Bugzilla cookie-based auth.
"""
- self.logger.debug('Login in bugzilla: %s', self.url)
+ try:
+ self.handler.Bugzilla.version({})
+ except ProtocolError as e:
+ if e.errcode != 401:
+ raise e
+ self.http_auth = True
+
+ if not self.http_auth:
+ return
+
+ self.logger.debug('Login to bugzilla using http auth: %s', self.url)
# split and unsplit the url with the username and password
oldurl = urlparse(self.url)
@@ -175,9 +186,15 @@ class Bugzilla(object):
# rebuild the handler with the new url
self.handler = ServerProxy(urlunparse(newurl), verbose=self.verbose)
+ def add_credentials (self, params):
+ if not self.http_auth:
+ params.update ({ 'Bugzilla_login': self.username,
+ 'Bugzilla_password': self.password })
+
def get(self):
"""This method returns data from #bug_id bug."""
params = {'ids': [self.bug_id]}
+ self.add_credentials (params)
self.logger.debug('XML-RPC call: Bug.get, params: %r', params)
rv = self.handler.Bug.get(params)
self.logger.debug('XML-RPC response: %r', rv)
@@ -190,6 +207,7 @@ class Bugzilla(object):
"""This method updates a bug with, changing the required fields."""
params = {'ids': [self.bug_id]}
params.update(fields)
+ self.add_credentials (params)
self.logger.debug('XML-RPC call: Bug.update, params: %r', params)
rv = self.handler.Bug.update(params)
self.logger.debug('XML-RPC response: %r', rv)
@@ -198,6 +216,7 @@ class Bugzilla(object):
def add_comment(self, comment):
"""This method adds a comment to the required bug."""
params = {'id': self.bug_id, 'comment': comment}
+ self.add_credentials (params)
self.logger.debug('XML-RPC call: Bug.add_comment, params: %r', params)
rv = self.handler.Bug.add_comment(params)
self.logger.debug('XML-RPC response: %r', rv)
@@ -226,7 +245,8 @@ def compare_status (a, b):
def do_main(settings):
fields = {}
- bugz = Bugzilla(settings.config.url, settings.cli.args.bug_id,
+ bugz = Bugzilla(settings.config.url, settings.config.username,
+ settings.config.password, settings.cli.args.bug_id,
settings.logger)
# we need to login before any request