Trees | Indices | Help |
|
---|
|
1 # This file is part of Buildbot. Buildbot is free software: you can 2 # redistribute it and/or modify it under the terms of the GNU General Public 3 # License as published by the Free Software Foundation, version 2. 4 # 5 # This program is distributed in the hope that it will be useful, but WITHOUT 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 8 # details. 9 # 10 # You should have received a copy of the GNU General Public License along with 11 # this program; if not, write to the Free Software Foundation, Inc., 51 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 13 # 14 # Copyright 2011, Louis Opter <kalessin@kalessin.fr> 15 16 # Quite inspired from the github hook. 17 18 import hmac 19 from twisted.python import log 20 from buildbot.util import json 21 246527 self._auth_code = headers['Google-Code-Project-Hosting-Hook-Hmac'] 28 self._body = body # we need to save it if we want to authenticate it 29 self._branch = branch 30 31 payload = json.loads(body) 32 self.project = payload['project_name'] 33 self.repository = payload['repository_path'] 34 self.revisions = payload['revisions'] 35 self.revision_count = payload['revision_count']3638 m = hmac.new(secret_key) 39 m.update(self._body) 40 digest = m.hexdigest() 41 return digest == self._auth_code4244 changes = [] 45 46 for r in self.revisions: 47 files = set() 48 files.update(r['added']) 49 files.update(r['modified']) 50 files.update(r['removed']) 51 changes.append(dict( 52 author=r['author'], 53 files=list(files), 54 comments=r['message'], 55 revision=r['revision'], 56 when=r['timestamp'], 57 # Let's hope Google add the branch one day: 58 branch=r.get('branch', self._branch), 59 revlink=r['url'], 60 repository=self.repository, 61 project=self.project 62 )) 63 64 return changes67 headers = request.received_headers 68 body = request.content.getvalue() 69 70 # Instantiate a Payload object: this will parse the body, get the 71 # authentication code from the headers and remember the branch picked 72 # up by the user (Google Code doesn't send on which branch the changes 73 # were made) 74 payload = Payload(headers, body, options.get('branch', 'default')) 75 76 if 'secret_key' in options: 77 if not payload.authenticate(options['secret_key']): 78 raise GoogleCodeAuthFailed() 79 else: 80 log.msg("Missing secret_key in the Google Code WebHook options: " 81 "cannot authenticate the request!") 82 83 log.msg('Received %d changes from Google Code' % 84 (payload.revision_count,)) 85 changes = payload.changes() 86 87 return changes, 'Google Code'88
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 25 19:40:37 2012 | http://epydoc.sourceforge.net |