pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
501 stars 239 forks source link

add google datastore as backend #109

Open ghost opened 4 years ago

kiptoomm commented 4 years ago

hey @fengsp, any chance to merge this any time soon?

ghost commented 4 years ago

Hi @kiptoomm, We are waiting too for this approval, you can use our own flask-session fork instead.

You will need to set the following settings into the Flask application in order to use our fork:

'SESSION_TYPE' = 'datastore'
'GCLOUD_APP_PROJECT_ID': '<your_app_project_id>'

Best regards.

kiptoomm commented 4 years ago

Hi @kiptoomm, We are waiting too for this approval, you can use our own flask-session fork instead.

You will need to set the following settings into the Flask application in order to use our fork:

'SESSION_TYPE' = 'datastore'
'GCLOUD_APP_PROJECT_ID': '<your_app_project_id>'

Best regards.

Thanks @alvarogf-vt, nice solution. With this implementation, how are the session objects stored? For example, with a mongodb backend, they're stored in a database called flask_session and collection sessions. We can access the objects thru mongo shell (command line). That is, I'm wondering what the datastore equivalents to the above are, if any.

kiptoomm commented 4 years ago

Hey @alvarogf-vt, I also noticed/had a couple of issues/questions arising from https://github.com/alvarogf-vt/flask-session/commit/2162ca02a5b7ce57f52d06dbf868988bb1259465:

export DATASTORE_EMULATOR_HOST=localhost:8432

However, it somehow interfered with my other calls to a remote instance of data store that I use for storing other values (that is, it looks like I cannot fetch my cloud datastore entities while using the datastore emulator) :(

Any advice on how to use your implementation locally would be greatly helpful.

ghost commented 4 years ago

Hi @kiptoomm

I meant you need to configure the Flask application as above:

import flask

app = flask.Flask(__name__)
app.config['GCLOUD_APP_PROJECT_ID'] = os.getenv('GCLOUD_APP_PROJECT_ID')

so you can pass GCLOUD_APP_PROJECT_ID as an os environment variable, this variable is needed in order to connect with your datastore instance once it has been deployed on Google cloud platform.

You can run your application with the google datastore emulator by executing dev_appserver.py from the google cloud SDK with the datastore options

GOOGLE_APPLICATION_CREDENTIALS needs to be set in order to execute dev_appserver.py locally, but the google internals tools know how to get project ID from this file, it could be interseting to investigate the way they have to do that in order not to require GCLOUD_APP_PROJECT_ID.