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

前端 未结 6 1754
情歌与酒
情歌与酒 2020-12-01 22:04

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 po

相关标签:
6条回答
  • 2020-12-01 22:15

    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.

    0 讨论(0)
  • 2020-12-01 22:18

    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

    0 讨论(0)
  • 2020-12-01 22:21

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

    0 讨论(0)
  • 2020-12-01 22:28

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

    0 讨论(0)
  • 2020-12-01 22:29

    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).

    0 讨论(0)
  • 2020-12-01 22:35

    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.

    0 讨论(0)
提交回复
热议问题