aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/mgagit/templates
diff options
context:
space:
mode:
authorColin Guthrie <colin@mageia.org>2014-11-17 16:27:08 +0000
committerColin Guthrie <colin@mageia.org>2014-11-17 16:30:49 +0000
commit2ec01cbfca0cebb809be77392c1be6d1720d904d (patch)
tree5a2bcf3e4a10cc082ee5410cd7b71ebce511453f /deployment/mgagit/templates
parent55537cd411c829e8383149e5de540f889d3480a4 (diff)
downloadpuppet-2ec01cbfca0cebb809be77392c1be6d1720d904d.tar
puppet-2ec01cbfca0cebb809be77392c1be6d1720d904d.tar.gz
puppet-2ec01cbfca0cebb809be77392c1be6d1720d904d.tar.bz2
puppet-2ec01cbfca0cebb809be77392c1be6d1720d904d.tar.xz
puppet-2ec01cbfca0cebb809be77392c1be6d1720d904d.zip
mgagit: Hopefully fix bugzilla integration.
Our bugzilla no longer supports cookies so we have to use a token itstead. It's essentially exactly the same as a cookie, but different therefore meaning we have to handle it ourselves manually. I don't really get the benefit here, but hey ho. mga#14585
Diffstat (limited to 'deployment/mgagit/templates')
-rwxr-xr-xdeployment/mgagit/templates/git-post-receive-hook34
1 files changed, 23 insertions, 11 deletions
diff --git a/deployment/mgagit/templates/git-post-receive-hook b/deployment/mgagit/templates/git-post-receive-hook
index 4edd1548..2efe6755 100755
--- a/deployment/mgagit/templates/git-post-receive-hook
+++ b/deployment/mgagit/templates/git-post-receive-hook
@@ -10,7 +10,6 @@ sys.path.insert(0, LIBDIR)
import git_multimail
import xmlrpclib
-from cookielib import LWPCookieJar
from bugz.bugzilla import BugzillaProxy
import urllib2
@@ -31,7 +30,7 @@ COMMIT_REPLACE = 'http://gitweb.mageia.org/%s/commit/?id=%s'
MAGEIA_BUGZILLA_URL = 'https://bugs.mageia.org/xmlrpc.cgi'
MAGEIA_BUGZILLA_PASSWORD_FILE = '.gitzilla-password'
-MAGEIA_BUGZILLA_COOKIE_FILE = '.gitzilla-cookie'
+MAGEIA_BUGZILLA_AUTHTOKEN_FILE = '.gitzilla-authtoken'
git_multimail.FOOTER_TEMPLATE = """\
@@ -83,17 +82,20 @@ git_multimail.Environment = MageiaEnvironment
# bug URLs
class MageiaLinksRevision(git_multimail.Revision):
bz = None
+ tokenfile = None
+ token = None
def bugzilla_init(self):
if self.bz is None:
- cookie_file = os.path.join(os.environ['HOME'], MAGEIA_BUGZILLA_COOKIE_FILE)
- self.cookiejar = LWPCookieJar(cookie_file)
+ self.tokenfile = os.path.join(os.environ['HOME'], MAGEIA_BUGZILLA_AUTHTOKEN_FILE)
try:
- self.cookiejar.load()
+ token = open(self.tokenfile, 'r').readline().rstrip()
+ if token:
+ self.token = token
except IOError:
pass
- self.bz = BugzillaProxy(MAGEIA_BUGZILLA_URL, cookiejar=self.cookiejar)
+ self.bz = BugzillaProxy(MAGEIA_BUGZILLA_URL)
return self.bz
def bugzilla_login(self):
@@ -102,19 +104,29 @@ class MageiaLinksRevision(git_multimail.Revision):
'password': open(os.path.join(os.environ['HOME'], MAGEIA_BUGZILLA_PASSWORD_FILE), 'r').readline().rstrip(),
'remember': True
}
- self.bz.User.login(params)
- self.cookiejar.save()
- os.chmod(self.cookiejar.filename, 0600)
+ result = self.bz.User.login(params)
+ if 'token' in result:
+ self.token = result['token']
+ if self.tokenfile is not None:
+ fd = open(self.tokenfile, 'w')
+ fd.write(self.token)
+ fd.write('\n')
+ fd.close()
+ os.chmod(self.tokenfile, 0600)
+ return True
+ return False
def bugzilla_call(self, method, *args):
"""Attempt to call method with args. Log in if authentication is required.
"""
try:
+ if self.token is not None:
+ arg[0]['token'] = self.token
return method(*args)
except xmlrpclib.Fault, fault:
# Fault code 410 means login required
- if fault.faultCode == 410:
- self.bugzilla_login()
+ if fault.faultCode == 410 and self.bugzilla_login():
+ arg[0]['token'] = self.token
return method(*args)
raise