标签: endpoints-proto-datastore

端点API - protorpc验证错误

protorpc当我使用端点时,我会收到一些奇怪的错误.在这段代码中:

class Application(EndpointsModel):

    _message_fields_schema = ('id', 'name')

    created = ndb.DateTimeProperty(auto_now_add=True)
    name = ndb.StringProperty()
    roles = ndb.IntegerProperty(repeated=True)
    updated = ndb.DateTimeProperty(auto_now=True)
    owner = ndb.KeyProperty(kind='User')

@API.api_class(resource_name="application")
class ApplicationApi(protorpc.remote.Service):

    @Application.method(http_method="GET",
                        request_fields=('id',),
                        name="get",
                        path="applications/{id}")
    def ApplicationGet(self, instance):
        if not instance.from_datastore:
            raise endpoints.NotFoundException("Application not found.")
        return instance

    @Application.query_method(http_method="GET",
                              query_fields=('limit', 'order', 'pageToken'),
                              name="list",
                              path="applications")
    def ApplicationList(self, query):
        return query
Run Code Online (Sandbox Code Playgroud)

当我调用application.get()错误时如下:( 完全跟踪):

TypeError:只能从确切类型为Application的实体进行复制.收到了一个Application实例.

并且调用application.list()错误如下:( 完全跟踪):

ValidationError:<class '.Application'>找到的字段项的预期类型<Application name: u'test'>(类型<class '.Application'>)

可能是什么导致了这个?我的其他模型具有几乎相同的代码(只是不同的属性)工作正常.

python google-app-engine protorpc google-cloud-endpoints endpoints-proto-datastore

30
推荐指数
1
解决办法
801
查看次数

动态创建方法和装饰器,得到错误'functools.partial'对象没有属性'__module__'

我目前正在使用EndpointsModel为AppEngine上的所有模型创建RESTful API.由于它是RESTful,这些api有很多重复代码,我想避免

例如:

class Reducer(EndpointsModel):
    name = ndb.StringProperty(indexed=False)

@endpoints.api(
    name="bigdata",
    version="v1",
    description="""The BigData API""",
    allowed_client_ids=ALLOWED_CLIENT_IDS,
)
class BigDataApi(remote.Service):
    @Reducer.method(
        path="reducer",
        http_method="POST",
        name="reducer.insert",
        user_required=True,
    )
    def ReducerInsert(self, obj):
        pass

    ## and GET, POST, PUT, DELETE
    ## REPEATED for each model
Run Code Online (Sandbox Code Playgroud)

我想让它们变得通用.所以我尝试动态添加方法到类.到目前为止我尝试了什么:

from functools import partial, wraps

def GenericInsert(self, obj, cls):
    obj.owner = endpoints.get_current_user()
    obj.put()
    return obj

# Ignore GenericDelete, GenericGet, GenericUpdate ...

import types
from functools import partial

def register_rest_api(api_server, endpoint_cls):
    name = endpoint_cls.__name__

    # create list method 
    query_method = types.MethodType( …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine functools google-cloud-endpoints endpoints-proto-datastore

18
推荐指数
2
解决办法
8256
查看次数

有没有办法保护Google云端点原型数据存储?

我的设置:

  1. 使用endpoints_proto_datastore的Python,谷歌应用引擎
  2. iOS,端点Obj-C客户端库生成器

背景

我已经设置了一个测试Google云端点api并让它运行得非常快.它运行良好,使用iOS模拟器中的测试应用程序,并使用Google的API Explorer.API目前对所有人开放,无需身份验证.

我想:设置一个API密钥或系统凭证,可以由应用程序使用,以确保它可以单独访问api - 所有其他人都被拒绝.

在该方法谷歌端点验证文档(1)是创建使用OAuth 2.0用户端ID 谷歌开发者控制台(2).所以我为类型为iOS的已安装应用程序创建了一个ID.到现在为止还挺好.

在应用程序中,GTLService对象看起来像这样......

-(GTLServiceDemogaeapi *)myApiService {
    GTMOAuth2Authentication *auth = [[GTMOAuth2Authentication alloc] init];
    auth.clientID = @"10???????????????????ie.apps.googleusercontent.com";
    auth.clientSecret = @"z????????????3";
    auth.scope = @"https://www.googleapis.com/auth/userinfo.email";

    static GTLServiceDemogaeapi *service = nil;
    if (!service) {
        service = [[GTLServiceDemogaeapi alloc] init];
        service.authorizer = auth;
        service.retryEnabled = YES;
        [GTMHTTPFetcher setLoggingEnabled:YES];
    }
    return service;
 }
Run Code Online (Sandbox Code Playgroud)

在GAE上我已经指定了(allowed_client_ids并在方法中添加了用户检查...

@endpoints.api(name='demogaeapi', version='v1',
               allowed_client_ids=['10?????????????ie.apps.googleusercontent.com',
               endpoints.API_EXPLORER_CLIENT_ID],
               scopes=[endpoints.EMAIL_SCOPE],
               description='My Demo API')
class MyApi(remote.Service):

    @TestModel.method(path='testmodel/{id}', name='testmodel.insert', http_method='POST')
    def testModelInsert(self, test_model):

        current_user = endpoints.get_current_user() …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine google-cloud-endpoints endpoints-proto-datastore

11
推荐指数
1
解决办法
966
查看次数

具有AppEngine,Webapp2和Cloud Endpoints Proto Datastore的多个Auth提供程序

我正在开发一个允许用户使用simpleauth进行身份验证的webapp .目前我将支持谷歌和Facebook.除了登录和注销(使用webapp2)之外,webapp还将包含Cloud Endpoint API.客户端将是web,Android和iOS.

我的问题是,如果用户的身份验证提供者是Facebook(或任何其他受支持的OAuth2提供商),我可以使用Endpoints Proto Datastore来user_required=True调用endpoints.get_current_user()我的用户@Model.method吗?如果不可能,这是否意味着我不应该拥有user_required=True并且应该在给定OAuth2令牌的情况下从提供者处获取永久用户ID并将其保留在数据存储区中,为该用户生成我自己的身份验证令牌,然后将该令牌传递给每个请求?

编辑:没有传递身份验证令牌,让经过身份验证的用户请求他们可以传递给API方法的"API令牌"是否有意义?这个令牌是否必须包含在POST或GET正文中,或者它是否可以放在标题/ cookie中(我在其他地方看到了有关使用Cloud Endpoints的标题和cookie的一些问题,但从那以后它已经有一段时间了).这都假设非Google身份验证不起作用.

google-app-engine oauth-2.0 google-cloud-endpoints endpoints-proto-datastore gae-userservice

5
推荐指数
1
解决办法
1417
查看次数

Google Cloud端点和服务帐户返回:Oauth框架用户与oauth令牌用户不匹配

我试图使用类似的服务帐户从cmdline访问谷歌云端点

https://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py

根据示例的说明,我创建了一个clientid + pk12证书,并使用它们通过oauth2client.client模块中的SignedJwtAsertionCredential调用创建凭证.

当我在我的本地devserver上调用我的云端点时,按预期工作,但是当我调用已部署的gae云端点时

Oauth框架用户与oauth令牌用户不匹配.

似乎是对来自user_id_token._set_bearer_user_vars()的oauth.get_client_id(范围)调用失败了.

当我在异常上添加回溯时,它看起来来自_maybe_raise_exception

E 2014-01-02 10:30:53.926 raise NotAllowedError(error_detail)E 2014-01-02 10:30:53.926 NotAllowedError

有没有办法在不更改应用程序的身份验证类型的情况下解决此错误?由于域名限制,似乎不允许请求?

我的目标是在没有用户参与的情况下调用云端点,不确定我是否使用SignedJwtAsertionCredential调用是正确的路径,或者如果可能的话?

附加信息.

端点的身份验证类型设置为"Google App Domain"

端点方法上的user_required为True

当我使用https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29时,从SignedJwtAssertCredential生成的访问令牌是预期的 .

端点在api资源管理器中按预期工作,并且当涉及auth流时.

使用endpoints_proto_datastore库.

python google-app-engine oauth google-cloud-endpoints endpoints-proto-datastore

5
推荐指数
1
解决办法
1178
查看次数

Google App Engine突然启动了端点身份验证失败

我在Google App Engine上有一个应用程序,其iOS和Android客户端通过Google Cloud Endpoints与服务器通信,并且在昨天的某个时间19:21到20:24(服务器时间,所以我假设太平洋),每个通过端点请求我的服务器,无论它来自哪个客户端,都失败了:

D 2014-05-12 20:24:33.353 Checking for id_token.
D 2014-05-12 20:24:33.362 Cert cache miss
D 2014-05-12 20:24:34.705 id_token verification failed.
D 2014-05-12 20:24:34.706 Checking for oauth token.
D 2014-05-12 20:24:34.717 Oauth framework user didn't match oauth token user.
Run Code Online (Sandbox Code Playgroud)

自5月8日以来,我没有对我的应用程序进行任何修改,所以App Engine方面必须有所改变.

FWIW,我的应用程序使用端点 - 原型数据存储区,以防相关(虽然我怀疑它.)

这使我的服务完全无用,我不知道如何升级这个.有关如何解决此问题或如何升级到Google的任何提示?

google-app-engine google-cloud-endpoints endpoints-proto-datastore

5
推荐指数
1
解决办法
155
查看次数

使用适用于Google App Engine的Cloud Endpoints对Android App进行本地测试

我正在开发一款Android应用程序,该应用程序使用Google App Engine上的Google Cloud Endpoints(在Python中)作为其后端.Android应用授权用户在Android设备上使用Google Play服务,这一切都非常有效.

但是,既然我有实际用户,我希望能够在将任何应用引擎API更改部署到生产环境之前在本地进行全部测试,而且我还没想出如何让Android应用与我的本地开发服务器通信任何地方.该测试的建议表明,我只是做与API Explorer中的某些手动修修补补,但由于我使用的端点数据存储原为我的API,这使得Android开发容易,这也使得API浏览器基本没用,因为这些调用我需要制作比我手工制作的复杂得多.

这个问题的一个答案表明,有一种方法可以将Android客户端指向本地服务器,但是虽然我可以使用--host参数让dev_appserver的默认服务器侦听除localhost之外的其他东西,但我似乎无法找到一种方法为API服务器做同样的事情.即使我能做到这一点,它可能只是我的Android应用程序完整的端到端本地测试设置的第一步.

有人可以发布有关我如何做到这一点的更多细节,或者说没有,请告诉我在App Engine上测试使用Google Cloud Endpoints的Android应用程序的最佳做法?提前感谢您的任何答案.

google-app-engine android google-cloud-endpoints endpoints-proto-datastore

5
推荐指数
2
解决办法
3482
查看次数

Proto DataStore 无法在苹果芯片上运行

当我在 Android Studio Canary 15 中运行代码时出现错误

任务“:app:generateInappProto”执行失败。无法解析配置“:app:protobufToolsLocator_protoc”的所有文件。找不到 protoc-3.17.0-osx-aarch_64.exe (com.google.protobuf:protoc:3.17.0)。在以下位置进行了搜索:

android protocol-buffers endpoints-proto-datastore android-studio android-jetpack

5
推荐指数
0
解决办法
194
查看次数

云端点 - 从数据存储区检索单个实体(通过EndpointsModel提供的辅助方法以外的属性)

这个问题完全遵循我在这里提出(并得到回答)的相关问题:尝试检索单个实体时出错

据我所知,要使用除已经提供的辅助方法之外的属性从数据存储中检索单个实体(例如'id')需要将简单的数据属性转换为EndpointsAliasProperty?如果是的话,我该怎么做呢?或者我们只能使用'id'(由提供的辅助方法EndpointsModel),我们不能使用我们定义的任何属性(在这种情况下'title')?

google-cloud-endpoints endpoints-proto-datastore

4
推荐指数
1
解决办法
1266
查看次数

使用endpoints-proto-datastore,如何将属性传递给EndpointsModel中未包含的方法

我试图将属性传递给我的EndpointsModel中未包含的API调用.例如,假设我有以下型号:

class MyModel(EndpointsModel):
  attr1 = ndb.StringProperty()
Run Code Online (Sandbox Code Playgroud)

然后假设我想attr2作为参数传入,但我不想attr2用作过滤器,也不希望它存储在模型中.我只是想传入一些字符串,在方法内部检索它并使用它来执行一些业务逻辑.

该文档描述了query_fields用于指定要传递给方法的字段的参数,但这些参数似乎与模型中包含的属性相关联,因此您无法传递模型中未指定的属性.

同样,文档声明您可以通过路径变量传递属性:

@MyModel.method(request_fields=('id',),
                path='mymodel/{id}', name='mymodel.get'
                http_method='GET')
def MyModelGet(self, my_model):
  # do something with id
Run Code Online (Sandbox Code Playgroud)

但这需要您更改URL,此外它似乎具有与query_fields(该属性必须存在于模型中)相同的约束.

google-app-engine google-cloud-endpoints endpoints-proto-datastore

3
推荐指数
1
解决办法
850
查看次数

如何将api请求中的collection_fields传递给@query_method装饰器?

(这是在github上发布的关于令人敬畏的端点 - 原型数据存储库的相同问题的副本)

我正在尝试实现我的API,以便客户端可以在api请求中传递'?fields ='url参数,然后我可以指示查询构建响应并仅返回请求的collection_fileds.

但是,我不知道如何将url参数传递给@query_method装饰器; 这是我的代码:

@Contact.query_method(query_fields=('limit', 'order', 'pageToken'),
                      collection_fields=('name', 'birthday'),
                      path='contacts',
                      name='contacts.list')
def contacts_list(self, query):
    return query
Run Code Online (Sandbox Code Playgroud)

如何fields将请求中的参数传递给装饰器中的collection_fields = named param?

google-app-engine google-cloud-endpoints endpoints-proto-datastore

3
推荐指数
1
解决办法
639
查看次数

使用endpoint-proto-datastore时设置父键但不设置子键

如何为EndpointsModel设置父/祖先,并让数据存储自动生成实体ID/Key?

我已经尝试调整keys_with_ancestors样本但似乎碰到了一个块,因为它需要指定id和parent.我想做类似的事情,除了只提供父ID或密钥,并由app引擎数据存储自动生成实体ID /密钥.

以下显示了如何使用NDB进行此操作.

class Parent(ndb.Model):
    name = ndb.StringProperty()

class MyModel(ndb.Model):
    attr1 = ndb.StringProperty()
    attr2 = ndb.StringProperty()

p = Parent(name="Jerry")
p_key = p.put()  # or retrieve the key from somewhere else

mod = MyModel(parent=p_key)
mod.put()
Run Code Online (Sandbox Code Playgroud)

这有可能吗,有人能指出我正确的方向吗?谢谢.

python google-app-engine google-cloud-endpoints endpoints-proto-datastore

3
推荐指数
1
解决办法
1407
查看次数

EndpointsModel与ndb.Model

所以我偶然发现EndpointsModel了创建模型的方法.当我在网上看时,基本上没有关于它的教程.对于使用它的人来说,有什么好处?而不是ndb.Model我的意思.

编辑:

此外,我试图模仿代码什么是最好的授权方式,识别和存储有关用户的微妙信息?只是为了检查它,但我的日食红线:

from endpoints_proto_datastore.ndb import EndpointsModel
Run Code Online (Sandbox Code Playgroud)

google-app-engine python-2.7 google-cloud-endpoints endpoints-proto-datastore google-cloud-datastore

2
推荐指数
1
解决办法
945
查看次数