Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """An interface to the milo service, which provides buildbot information. | |
| 6 | |
| 7 The protocol buffer defining the API is located here: | |
| 8 https://github.com/luci/luci-go/blob/master/milo/api/proto/buildbot.proto | |
| 9 | |
| 10 The API basically returns the same thing as the buildbot JSON API. We use the | |
| 11 milo API instead of raw buildbot json because this is the method supported by | |
| 12 Chrome infra team; the data is available longer and pinging the API does not | |
| 13 DOS buildbot pages. | |
| 14 """ | |
| 15 | |
| 16 import base64 | |
| 17 import json | |
| 18 | |
| 19 from google.appengine.api import urlfetch | |
| 20 | |
| 21 _BUILDBOT_JSON_URL = ( | |
| 22 'https://luci-milo.appspot.com/prpc/milo.Buildbot/' | |
| 23 'GetBuildbotBuildJSON') | |
| 24 | |
| 25 | |
| 26 def GetBuildbotBuildInfo(master, builder, build_num): | |
| 27 body = json.dumps({ | |
| 28 'master': master, | |
| 29 'builder': builder, | |
| 30 'build_num': int(build_num) | |
| 31 }) | |
| 32 headers = { | |
| 33 'Accept': 'application/json', | |
| 34 'Content-Type': 'application/json', | |
| 35 } | |
| 36 try: | |
| 37 response = urlfetch.fetch( | |
| 38 url=_BUILDBOT_JSON_URL, | |
| 39 method=urlfetch.POST, | |
| 40 payload=body, | |
| 41 headers=headers) | |
| 42 except urlfetch.Error: | |
| 43 return None | |
| 44 if response.status_code != 200: | |
| 45 return None | |
| 46 | |
| 47 # Unwrap the gRPC message | |
| 48 resp = json.loads(response.content[5:]) # Remove the jsonp header. | |
|
eakuefner
2017/01/09 21:30:31
Is there documentation on their jsonp format anywh
sullivan
2017/01/09 21:57:16
I added a comment; this is a really common prefix
| |
| 49 # Decompress and unmarshal the json message. | |
| 50 data = base64.b64decode(resp['data']) | |
| 51 if not data: | |
| 52 return None | |
| 53 result = json.loads(data) | |
| 54 # Convert properties and steps lists to dicts | |
| 55 properties = {p[0] : p[1] for p in result['properties']} | |
| 56 result['properties'] = properties | |
| 57 steps = {step['name'] : step for step in result['steps']} | |
| 58 result['steps'] = steps | |
| 59 result['masterName'] = master | |
| 60 return result | |
| OLD | NEW |