Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1701)

Unified Diff: scripts/master/buildbucket/client.py

Issue 2137583002: buildbucket: bypass Cloud Endpoints API server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: buildbucket: bypass Cloud Endpoints API server Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: scripts/master/buildbucket/client.py
diff --git a/scripts/master/buildbucket/client.py b/scripts/master/buildbucket/client.py
index c1a5313a5aec57cf0271739dfa8ced1da34b22d1..2dd106c65ec473fb680444d9cc1fddf75d15552c 100644
--- a/scripts/master/buildbucket/client.py
+++ b/scripts/master/buildbucket/client.py
@@ -5,18 +5,27 @@
"""This file contains buildbucket service client."""
import datetime
+import json
+import os
+import urlparse
from master import auth
from master import deferred_resource
from master.buildbucket import common
+import apiclient
+import httplib2
BUILDBUCKET_HOSTNAME_PRODUCTION = 'cr-buildbucket.appspot.com'
BUILDBUCKET_HOSTNAME_TESTING = 'cr-buildbucket-test.appspot.com'
+THIS_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+DISCOVERY_DOC_PATH = os.path.join(THIS_DIR, 'discovery_doc.json')
-def buildbucket_api_discovery_url(hostname=None):
- return (
- 'https://%s/_ah/api/discovery/v1/apis/{api}/{apiVersion}/rest' % hostname)
+
+# A list of buckets for which we bypass Cloud Endpoints proxy.
+BYPASS_ENDPOINTS_WHITELIST = [
dnj (Google) 2016/07/08 17:37:29 nit: might as well make this a set()
nodir 2016/07/08 17:42:54 Done.
+ 'master.tryserver.infra',
+]
def get_default_buildbucket_hostname(master):
@@ -25,26 +34,39 @@ def get_default_buildbucket_hostname(master):
else BUILDBUCKET_HOSTNAME_TESTING)
-def create_buildbucket_service(
- master, hostname=None, verbose=None):
+def create_buildbucket_service(master, hostname=None, verbose=None):
"""Asynchronously creates buildbucket API resource.
Returns:
A DeferredResource as Deferred.
"""
hostname = hostname or get_default_buildbucket_hostname(master)
+ baseUrl = 'https://%s/%sapi/buildbucket/v1/' % (
+ hostname,
+ '' if master.buildbucket_bucket in BYPASS_ENDPOINTS_WHITELIST else '_ah/',
+ )
cred_factory = deferred_resource.CredentialFactory(
lambda: auth.create_credentials_for_master(master),
ttl=datetime.timedelta(minutes=5),
)
- return deferred_resource.DeferredResource.build(
- 'buildbucket',
- 'v1',
+ with open(DISCOVERY_DOC_PATH) as f:
+ discovery_doc = json.load(f)
+
+ resource = apiclient.discovery.Resource(
dnj (Google) 2016/07/08 17:37:29 nit: Comment that this is copied from the source l
nodir 2016/07/08 17:42:53 Done.
+ http=httplib2.Http(),
+ baseUrl=baseUrl,
+ model=apiclient.model.JsonModel(False),
+ requestBuilder=apiclient.http.HttpRequest,
+ developerKey=None,
+ resourceDesc=discovery_doc,
+ rootDesc=discovery_doc,
+ schema=apiclient.schema.Schemas(discovery_doc))
+ return deferred_resource.DeferredResource(
+ resource,
credentials=cred_factory,
max_concurrent_requests=10,
- discoveryServiceUrl=buildbucket_api_discovery_url(hostname),
verbose=verbose or False,
log_prefix=common.LOG_PREFIX,
timeout=60,

Powered by Google App Engine
This is Rietveld 408576698