I'm testing a method to reject requests to our GAE API if not providing a shared-id as discussed in my SO question here. This involves using the hiddenProperty method suggested by bossylobster.
My demo code on GAE looks like this:
import endpoints
from endpoints_proto_datastore.ndb import EndpointsAliasProperty
from endpoints_proto_datastore.ndb import EndpointsModel
from google.appengine.ext import ndb
from protorpc import remote
DEFAULT_ORDER = 'created, sid'
class TestModel(EndpointsModel):
_message_fields_schema = ('sid', 'a1', 'a2', 'created')
a1 = ndb.StringProperty()
a2 = ndb.StringProperty()
created = ndb.DateTimeProperty(auto_now_add=True)
def SidSet(self, value):
if not isinstance(value, basestring):
raise TypeError('SID must be a string.')
self.UpdateFromKey(ndb.Key(TestModel, value))
@EndpointsAliasProperty(setter=SidSet, required=True)
def sid(self):
if self.key is not None:
return self.key.string_id()
@EndpointsAliasProperty(setter=EndpointsModel.OrderSet,
default=DEFAULT_ORDER)
def order(self):
return super(TestModel, self).order
@endpoints.api(name='demogaeapi', version='v1',
scopes=[endpoints.EMAIL_SCOPE],
description='My Demo API')
class MyApi(remote.Service):
@TestModel.method(http_method='GET',
path='testmodel/{sid}',
request_fields=('sid',),
name='testmodel.get')
def testModelGet(self, test_model):
appId,keytype = request.get_unrecognized_field_info('hiddenProperty')
if appId != 'shared-id':
raise endpoints.UnauthorizedException('No, you dont!')
if not test_model.from_datastore:
raise endpoints.NotFoundException('testModel not found.')
return test_model
application = endpoints.api_server([MyApi], restricted=False)
My question is: how do I get at the request object in this line?
- pwd,keytype = request.get_unrecognized_field_info('hiddenProperty')