使用endpoints_proto_datastore.ndb时如何获取请求对象?

时间:2014-12-01 13:31:28

标签: python google-app-engine

我正在测试一种方法,如果不提供我的问题here中讨论的共享ID,则拒绝对GAE API的请求。这涉及使用bossylobster建议的hiddenProperty方法。

我在GAE上的演示代码如下所示:

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)

我的问题是:如何获取此行中的请求对象?

  • pwd,keytype = request .get_unrecognized_field_info('hiddenProperty')

0 个答案:

没有答案