Can I access Datastore entities of my other Google App Engine Applications

偶尔善良 提交于 2019-11-26 17:49:14

问题


As we know, in Google App engine, for each registered email account, we are allowed to make 10 applications. Now, I need to share entities among the applications. Is this possible? If yes, how is it implemented?


回答1:


No, this cannot be done. However, as Nick Johnson points out, you can use remote_api to do what you need.




回答2:


Are you sure you really need to do this? Don't forget, you can have multiple versions of an application running against the same datastore. Only 1 version of the app is your "default" and gets your non appspot.com domain name, but you can have completely different codebases running against the same datastore/memcache addressable with ..appspot.com

I don't know if this satisfies your needs but thought I'd throw it out there.




回答3:


Yo can do it using Cloud Datastore API access. Until now, I can't be able to do it using ndb library.

This is the code (Python) in your current app:

from google.appengine.api import app_identity

scope = "https://www.googleapis.com/auth/datastore"
authorization_token, _ = app_identity.get_access_token(scope)
headers = {'Content-Type': 'application/json', "Authorization": "Bearer " + authorization_token}
payload = {"gqlQuery": { "queryString": "SELECT * FROM Entities"} }
url = "https://datastore.googleapis.com/v1beta3/projects/otherAppName:runQuery"

result = urlfetch.fetch(url, payload=json.dumps(payload), method=urlfetch.POST,
     follow_redirects=True, headers=headers)

just change "otherAppName" with the short name of the other App Engine app whose datastore you want to access. Change "Entities" with the name of the Model you want to access. Remember to give access to yourCurrentApp in the otherNameApp (IAM menu in the cloud console), set permissions to yourcurrentapp@appspot.gserviceaccount.com to access the datastore/project

In result you will get the response, you must json-parse it and you will get a very low level detail of the datastore entities from the query (including keys, paths, field names, types and value for each field and each row of the results). If you have ndb.JsonProperties you will receive a BLOB value (DATABLOB in the next example code) , you must transform it :

from google.appengine.ext.bulkload import transform 
b = json.loads(transform.blobproperty_from_base64(DATOBLOB))

Hope this can help you. I'm waiting for the answer using ndb in my other post: GAE NDB Datastore new feature: Access Datastore entities from other GAE app




回答4:


Check the ISSUE with GAE before going to implement as stated in documentation. I had tried to implement as stated there but with fail because of the issue. Your request to the remote API will reach the target server but won't perform anything. Hope that the issue be solved soon.




回答5:


There's a new possibility: if one of the applications can be "part of" another, you can have it be a "module".




回答6:


By activating Cloud Datastore access in App Engine's settings it's possible to share a datastore with other App Engine applications (or third party applications).



来源:https://stackoverflow.com/questions/8956230/can-i-access-datastore-entities-of-my-other-google-app-engine-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!