Skip to content

Commit 46745ed

Browse files
author
Tim Emiola
committed
Add API management
- update the dependencies - update the apiserving to include the management WSGI support Change-Id: Ie21bf14f0b46d8ea0c1b07a662480d598102df61
1 parent e68c907 commit 46745ed

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎endpoints/apiserving.py‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -59,6 +59,7 @@ def list(self, request):
5959
import cgi
6060
import httplib
6161
import json
62+
import logging
6263
import os
6364

6465
import api_backend_service
@@ -67,13 +68,18 @@ def list(self, request):
6768
import endpoints_dispatcher
6869
import protojson
6970

71+
from google.appengine.api import app_identity
72+
from google.api.control import client as control_client
73+
from google.api.control import wsgi as control_wsgi
74+
7075
from protorpc import messages
7176
from protorpc import remote
7277
from protorpc.wsgi import service as wsgi_service
7378

7479
import util
7580

7681

82+
logger = logging.getLogger(__name__)
7783
package = 'google.appengine.endpoints'
7884

7985

@@ -444,6 +450,7 @@ def api_server(api_services, **kwargs):
444450
instance for the service handlers described by the services passed in.
445451
Additionally, it registers each API in ApiConfigRegistry for later use
446452
in the BackendService.getApiConfigs() (API config enumeration service).
453+
It also configures service control.
447454
448455
Args:
449456
api_services: List of protorpc.remote.Service classes implementing the API
@@ -462,5 +469,29 @@ def api_server(api_services, **kwargs):
462469
if 'protocols' in kwargs:
463470
raise TypeError("__init__() got an unexpected keyword argument 'protocols'")
464471

465-
return endpoints_dispatcher.EndpointsDispatcherMiddleware(
466-
_ApiServer(api_services, **kwargs))
472+
# Construct the api serving app
473+
apis_app = _ApiServer(api_services, **kwargs)
474+
dispatcher = endpoints_dispatcher.EndpointsDispatcherMiddleware(apis_app)
475+
476+
# Determine the service name
477+
service_name = os.environ.get('ENDPOINTS_SERVICE_NAME')
478+
if not service_name:
479+
logger.warn('Did not specify the ENDPOINTS_SERVICE_NAME environment'
480+
' variable so service control is disabled. Please specify the'
481+
' the name of service in ENDPOINTS_SERVICE_NAME to enable it.')
482+
return dispatcher
483+
484+
485+
# The DEFAULT 'config' should be tuned so that it's always OK for python
486+
# App Engine workloads. The config can be adjusted, but that's probably
487+
# unnecessary on App Engine.
488+
controller = control_client.Loaders.DEFAULT.load(service_name)
489+
490+
# Start the GAE background thread that powers the control client's cache.
491+
control_client.use_gae_thread()
492+
controller.start()
493+
494+
return control_wsgi.add_all(
495+
dispatcher,
496+
app_identity.get_application_id(),
497+
controller)

‎setup.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
else:
3131
raise RuntimeError("No version number found!")
3232

33+
install_requires = [
34+
'google-endpoints-api-management>=1.0.0b1'
35+
]
36+
3337
setup(
3438
name='google-endpoints',
3539
version=version,
@@ -52,4 +56,5 @@
5256
],
5357
scripts=['endpoints/endpointscfg.py'],
5458
tests_require=['mox', 'protobuf', 'protorpc', 'pytest', 'webtest'],
59+
install_requires=install_requires,
5560
)

0 commit comments

Comments
 (0)