Skip to content

Commit

Permalink
Integrate changes from Piper (#57)
Browse files Browse the repository at this point in the history
* Integrate changes from Piper

* Add constraint for protobuf version in tox.ini
  • Loading branch information
shreejad authored Jul 21, 2022
1 parent 9f29ed0 commit cc19a2e
Show file tree
Hide file tree
Showing 42 changed files with 318 additions and 2,789 deletions.
92 changes: 57 additions & 35 deletions src/google/appengine/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,79 @@
app.wsgi_app = google.appengine.api.wrap_wsgi_app(app.wsgi_app)
```
"""

import os
from google.appengine.api import full_app_id
from typing import Dict, Optional


def wrap_wsgi_app(app, *, use_deferred=False, **kwargs):
"""Wrap a WSGI app with middlewares required to access App Engine APIs."""
return WSGIAppWrapper().wrap_wsgi_app(
app, use_deferred=use_deferred, **kwargs)


class WSGIAppWrapper():
"""A mechanism for overriding wrap_wsgi_app's defaults."""

def __init__(self, *, legacy_behaviors: Optional[Dict[str, bool]] = None):
self.legacy_behaviors = dict(
use_legacy_context_mode=True,
patch_thread_creation=True)
if legacy_behaviors is not None:
self.legacy_behaviors.update(legacy_behaviors)



def wrap_wsgi_app(self, app, *, use_deferred=False, **kwargs):
"""Wrap a WSGI app with middlewares required to access App Engine APIs."""


self.legacy_behaviors.update(kwargs)



def wrap_wsgi_app(app, use_legacy_context_mode=True, use_deferred=False):
"""Wrap a WSGI app with middlewares required to access App Engine APIs."""

from google.appengine.runtime import initialize
from google.appengine.runtime import middlewares
from google.appengine.runtime import default_api_stub

from google.appengine.runtime import initialize
from google.appengine.runtime import middlewares
from google.appengine.runtime import default_api_stub

if self.legacy_behaviors['patch_thread_creation']:


initialize.InitializeThreadingApis()

initialize.InitializeThreadingApis()
default_api_stub.Register(default_api_stub.DefaultApiStub())

default_api_stub.Register(default_api_stub.DefaultApiStub())
def if_legacy_context_mode(f):
return f() if self.legacy_behaviors['use_legacy_context_mode'] else []

def if_deferred_enabled(f):
return f() if use_deferred else []


full_app_id.normalize()
return middlewares.Wrap(
app,
if_legacy_context_mode(lambda: [

def if_legacy(array):
return array if use_legacy_context_mode else []

def if_deferred_enabled(array):
return array if use_deferred else []

return middlewares.Wrap(
app,
if_legacy([
middlewares.MakeInitLegacyRequestOsEnvironMiddleware(),
]) + [
middlewares.RunInNewContextMiddleware,
middlewares.SetContextFromHeadersMiddleware,
middlewares.CallbackMiddleware,
middlewares.UseRequestSecurityTicketForApiMiddleware,
middlewares.WaitForResponseMiddleware,
middlewares.WsgiEnvSettingMiddleware,
middlewares.MakeInitLegacyRequestOsEnvironMiddleware(),
]) + [
middlewares.RunInNewContextMiddleware,
middlewares.SetContextFromHeadersMiddleware,
middlewares.CallbackMiddleware,
middlewares.WaitForResponseMiddleware,
middlewares.WsgiEnvSettingMiddleware,

middlewares.MakeLegacyWsgiEnvSettingMiddleware(),
] + if_legacy([
middlewares.LegacyWsgiRemoveXAppenginePrefixMiddleware,
middlewares.LegacyCopyWsgiEnvToOsEnvMiddleware,
]) + [
middlewares.ErrorLoggingMiddleware,
middlewares.BackgroundAndShutdownMiddleware,
middlewares.SetNamespaceFromHeader,
] + if_deferred_enabled([
middlewares.AddDeferredMiddleware,
]))
middlewares.MakeLegacyWsgiEnvSettingMiddleware(),
] + if_legacy_context_mode(lambda: [
middlewares.LegacyWsgiRemoveXAppenginePrefixMiddleware,
middlewares.LegacyCopyWsgiEnvToOsEnvMiddleware,
]) + [
middlewares.ErrorLoggingMiddleware,
middlewares.BackgroundAndShutdownMiddleware,
middlewares.SetNamespaceFromHeader,
] + if_deferred_enabled(lambda: [
middlewares.AddDeferredMiddleware,
]))
63 changes: 3 additions & 60 deletions src/google/appengine/api/api_base_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@


"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database


Expand All @@ -32,64 +31,8 @@

DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n#google/appengine/api/api_base.proto\x12\x15google.appengine.base\"\x1c\n\x0bStringProto\x12\r\n\x05value\x18\x01 \x02(\t\"\x1f\n\x0eInteger32Proto\x12\r\n\x05value\x18\x01 \x02(\x05\"\x1f\n\x0eInteger64Proto\x12\r\n\x05value\x18\x01 \x02(\x03\"\x1a\n\tBoolProto\x12\r\n\x05value\x18\x01 \x02(\x08\"\x1c\n\x0b\x44oubleProto\x12\r\n\x05value\x18\x01 \x02(\x01\"\x1f\n\nBytesProto\x12\x11\n\x05value\x18\x01 \x02(\x0c\x42\x02\x08\x01\"\x0b\n\tVoidProtoB,\n\x1f\x63om.google.google.appengine.apiB\tApiBasePb')



_STRINGPROTO = DESCRIPTOR.message_types_by_name['StringProto']
_INTEGER32PROTO = DESCRIPTOR.message_types_by_name['Integer32Proto']
_INTEGER64PROTO = DESCRIPTOR.message_types_by_name['Integer64Proto']
_BOOLPROTO = DESCRIPTOR.message_types_by_name['BoolProto']
_DOUBLEPROTO = DESCRIPTOR.message_types_by_name['DoubleProto']
_BYTESPROTO = DESCRIPTOR.message_types_by_name['BytesProto']
_VOIDPROTO = DESCRIPTOR.message_types_by_name['VoidProto']
StringProto = _reflection.GeneratedProtocolMessageType('StringProto', (_message.Message,), {
'DESCRIPTOR' : _STRINGPROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(StringProto)

Integer32Proto = _reflection.GeneratedProtocolMessageType('Integer32Proto', (_message.Message,), {
'DESCRIPTOR' : _INTEGER32PROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(Integer32Proto)

Integer64Proto = _reflection.GeneratedProtocolMessageType('Integer64Proto', (_message.Message,), {
'DESCRIPTOR' : _INTEGER64PROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(Integer64Proto)

BoolProto = _reflection.GeneratedProtocolMessageType('BoolProto', (_message.Message,), {
'DESCRIPTOR' : _BOOLPROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(BoolProto)

DoubleProto = _reflection.GeneratedProtocolMessageType('DoubleProto', (_message.Message,), {
'DESCRIPTOR' : _DOUBLEPROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(DoubleProto)

BytesProto = _reflection.GeneratedProtocolMessageType('BytesProto', (_message.Message,), {
'DESCRIPTOR' : _BYTESPROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(BytesProto)

VoidProto = _reflection.GeneratedProtocolMessageType('VoidProto', (_message.Message,), {
'DESCRIPTOR' : _VOIDPROTO,
'__module__' : 'google.appengine.api.api_base_pb2'

})
_sym_db.RegisterMessage(VoidProto)

_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.appengine.api.api_base_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:

DESCRIPTOR._options = None
Expand Down
15 changes: 5 additions & 10 deletions src/google/appengine/api/api_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

"""Base class useful for testing with API stubs."""



import os
import shutil

Expand All @@ -33,17 +31,16 @@
from google.appengine.datastore import cloud_datastore_v1_remote_stub
from google.appengine.datastore import cloud_datastore_v1_stub
from google.appengine.datastore import datastore_pbs
from google.appengine.datastore import datastore_sqlite_stub
from google.appengine.datastore import datastore_v4_stub






FLAGS = flags.FLAGS

flags.DEFINE_boolean("use_sqlite", False,
"uses the sqlite based datastore stub")
flags.DEFINE_boolean('use_sqlite', False,
'uses the sqlite based datastore stub')

_CLOUD_DATASTORE_ENABLED = datastore_pbs._CLOUD_DATASTORE_ENABLED

Expand Down Expand Up @@ -99,10 +96,8 @@ def ConfigureDatastore(self, app_id='app', **kwargs):
os.remove(filename)

if flags.FLAGS.use_sqlite:




self.datastore_stub = datastore_sqlite_stub.DatastoreSqliteStub(
app_id, self.datastore_file, **kwargs)
raise NotImplementedError('datastore_sqlite_stub not supported')
else:

Expand Down
104 changes: 3 additions & 101 deletions src/google/appengine/api/app_identity/app_identity_service_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@


"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database


Expand All @@ -32,105 +31,8 @@

DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n<google/appengine/api/app_identity/app_identity_service.proto\x12\x10google.appengine\"\xe6\x01\n\x17\x41ppIdentityServiceError\"\xca\x01\n\tErrorCode\x12\x0b\n\x07SUCCESS\x10\x00\x12\x11\n\rUNKNOWN_SCOPE\x10\t\x12\x13\n\x0e\x42LOB_TOO_LARGE\x10\xe8\x07\x12\x16\n\x11\x44\x45\x41\x44LINE_EXCEEDED\x10\xe9\x07\x12\x14\n\x0fNOT_A_VALID_APP\x10\xea\x07\x12\x12\n\rUNKNOWN_ERROR\x10\xeb\x07\x12\x1e\n\x19GAIAMINT_NOT_INITIAILIZED\x10\xec\x07\x12\x10\n\x0bNOT_ALLOWED\x10\xed\x07\x12\x14\n\x0fNOT_IMPLEMENTED\x10\xee\x07\"*\n\x11SignForAppRequest\x12\x15\n\rbytes_to_sign\x18\x01 \x01(\x0c\"?\n\x12SignForAppResponse\x12\x10\n\x08key_name\x18\x01 \x01(\t\x12\x17\n\x0fsignature_bytes\x18\x02 \x01(\x0c\"#\n!GetPublicCertificateForAppRequest\"C\n\x11PublicCertificate\x12\x10\n\x08key_name\x18\x01 \x01(\t\x12\x1c\n\x14x509_certificate_pem\x18\x02 \x01(\t\"\x93\x01\n\"GetPublicCertificateForAppResponse\x12\x44\n\x17public_certificate_list\x18\x01 \x03(\x0b\x32#.google.appengine.PublicCertificate\x12\'\n\x1fmax_client_cache_time_in_second\x18\x02 \x01(\x03\"\x1e\n\x1cGetServiceAccountNameRequest\"=\n\x1dGetServiceAccountNameResponse\x12\x1c\n\x14service_account_name\x18\x01 \x01(\t\"d\n\x15GetAccessTokenRequest\x12\r\n\x05scope\x18\x01 \x03(\t\x12\x1a\n\x12service_account_id\x18\x02 \x01(\x03\x12 \n\x14service_account_name\x18\x03 \x01(\tB\x02\x18\x01\"G\n\x16GetAccessTokenResponse\x12\x14\n\x0c\x61\x63\x63\x65ss_token\x18\x01 \x01(\t\x12\x17\n\x0f\x65xpiration_time\x18\x02 \x01(\x03\" \n\x1eGetDefaultGcsBucketNameRequest\"B\n\x1fGetDefaultGcsBucketNameResponse\x12\x1f\n\x17\x64\x65\x66\x61ult_gcs_bucket_name\x18\x01 \x01(\tB<\n$com.google.appengine.api.appidentityB\x14\x41ppIdentityServicePb')



_APPIDENTITYSERVICEERROR = DESCRIPTOR.message_types_by_name['AppIdentityServiceError']
_SIGNFORAPPREQUEST = DESCRIPTOR.message_types_by_name['SignForAppRequest']
_SIGNFORAPPRESPONSE = DESCRIPTOR.message_types_by_name['SignForAppResponse']
_GETPUBLICCERTIFICATEFORAPPREQUEST = DESCRIPTOR.message_types_by_name['GetPublicCertificateForAppRequest']
_PUBLICCERTIFICATE = DESCRIPTOR.message_types_by_name['PublicCertificate']
_GETPUBLICCERTIFICATEFORAPPRESPONSE = DESCRIPTOR.message_types_by_name['GetPublicCertificateForAppResponse']
_GETSERVICEACCOUNTNAMEREQUEST = DESCRIPTOR.message_types_by_name['GetServiceAccountNameRequest']
_GETSERVICEACCOUNTNAMERESPONSE = DESCRIPTOR.message_types_by_name['GetServiceAccountNameResponse']
_GETACCESSTOKENREQUEST = DESCRIPTOR.message_types_by_name['GetAccessTokenRequest']
_GETACCESSTOKENRESPONSE = DESCRIPTOR.message_types_by_name['GetAccessTokenResponse']
_GETDEFAULTGCSBUCKETNAMEREQUEST = DESCRIPTOR.message_types_by_name['GetDefaultGcsBucketNameRequest']
_GETDEFAULTGCSBUCKETNAMERESPONSE = DESCRIPTOR.message_types_by_name['GetDefaultGcsBucketNameResponse']
_APPIDENTITYSERVICEERROR_ERRORCODE = _APPIDENTITYSERVICEERROR.enum_types_by_name['ErrorCode']
AppIdentityServiceError = _reflection.GeneratedProtocolMessageType('AppIdentityServiceError', (_message.Message,), {
'DESCRIPTOR' : _APPIDENTITYSERVICEERROR,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(AppIdentityServiceError)

SignForAppRequest = _reflection.GeneratedProtocolMessageType('SignForAppRequest', (_message.Message,), {
'DESCRIPTOR' : _SIGNFORAPPREQUEST,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(SignForAppRequest)

SignForAppResponse = _reflection.GeneratedProtocolMessageType('SignForAppResponse', (_message.Message,), {
'DESCRIPTOR' : _SIGNFORAPPRESPONSE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(SignForAppResponse)

GetPublicCertificateForAppRequest = _reflection.GeneratedProtocolMessageType('GetPublicCertificateForAppRequest', (_message.Message,), {
'DESCRIPTOR' : _GETPUBLICCERTIFICATEFORAPPREQUEST,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetPublicCertificateForAppRequest)

PublicCertificate = _reflection.GeneratedProtocolMessageType('PublicCertificate', (_message.Message,), {
'DESCRIPTOR' : _PUBLICCERTIFICATE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(PublicCertificate)

GetPublicCertificateForAppResponse = _reflection.GeneratedProtocolMessageType('GetPublicCertificateForAppResponse', (_message.Message,), {
'DESCRIPTOR' : _GETPUBLICCERTIFICATEFORAPPRESPONSE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetPublicCertificateForAppResponse)

GetServiceAccountNameRequest = _reflection.GeneratedProtocolMessageType('GetServiceAccountNameRequest', (_message.Message,), {
'DESCRIPTOR' : _GETSERVICEACCOUNTNAMEREQUEST,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetServiceAccountNameRequest)

GetServiceAccountNameResponse = _reflection.GeneratedProtocolMessageType('GetServiceAccountNameResponse', (_message.Message,), {
'DESCRIPTOR' : _GETSERVICEACCOUNTNAMERESPONSE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetServiceAccountNameResponse)

GetAccessTokenRequest = _reflection.GeneratedProtocolMessageType('GetAccessTokenRequest', (_message.Message,), {
'DESCRIPTOR' : _GETACCESSTOKENREQUEST,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetAccessTokenRequest)

GetAccessTokenResponse = _reflection.GeneratedProtocolMessageType('GetAccessTokenResponse', (_message.Message,), {
'DESCRIPTOR' : _GETACCESSTOKENRESPONSE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetAccessTokenResponse)

GetDefaultGcsBucketNameRequest = _reflection.GeneratedProtocolMessageType('GetDefaultGcsBucketNameRequest', (_message.Message,), {
'DESCRIPTOR' : _GETDEFAULTGCSBUCKETNAMEREQUEST,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetDefaultGcsBucketNameRequest)

GetDefaultGcsBucketNameResponse = _reflection.GeneratedProtocolMessageType('GetDefaultGcsBucketNameResponse', (_message.Message,), {
'DESCRIPTOR' : _GETDEFAULTGCSBUCKETNAMERESPONSE,
'__module__' : 'google.appengine.api.app_identity.app_identity_service_pb2'

})
_sym_db.RegisterMessage(GetDefaultGcsBucketNameResponse)

_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google.appengine.api.app_identity.app_identity_service_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:

DESCRIPTOR._options = None
Expand Down
Loading

0 comments on commit cc19a2e

Please sign in to comment.