Skip to content

Instantly share code, notes, and snippets.

@i386
Created November 28, 2011 22:51
Show Gist options
  • Save i386/1402465 to your computer and use it in GitHub Desktop.
Save i386/1402465 to your computer and use it in GitHub Desktop.
Bitbucket Broker for Triggering Bamboo Jobs
#!/usr/bin/env python
#
# Copyright 2011 Calico Cube Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import urllib
from brokers import BaseBroker
class AuthenticatedOpener(urllib.FancyURLopener):
def prompt_user_passwd(self, host, realm):
return (self.username, self.password)
class BambooBroker(BaseBroker):
def handle(self, payload):
service = payload['service'];
url_base = service['url_base']
plan_key = service['plan_key']
url = "%s/queue/%s?os_authType=basic" % (url_base, plan_key)
opener = self.get_local('opener', AuthenticatedOpener)
opener.username = service['username']
opener.password = service['password']
opener.open(url, "")
if (__name__ == '__main__'):
broker = BambooBroker()
payload = {
'service': {
'password': u'password',
'username': u'username',
'url_base': u'http://bamboo.mycompany.com:8085/rest/api/latest',
'plan_key': u'BAM-BOO',
}
}
broker.handle(payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment