gee-community / qgis-earthengine-plugin

Integrates Google Earth Engine and QGIS using Python API
http://qgis-ee-plugin.appspot.com
MIT License
454 stars 116 forks source link

Authenticate and set project during initialize #156

Closed gena closed 2 weeks ago

gena commented 2 weeks ago

Fixes #150

XavierCLL commented 2 weeks ago

Issue 1:

In the process to sign-in, If the user leaves the Project ID empty (for example the user want to create the project after sign-in and then setup it later using the "Set project" option), if you reload the plugin or restart Qgis, the plugin crash because the parameter "project" in credentials file is empty.

We can fix it checking if the project ID introduced by the user is empty or not, if so, not write the parameter "project" in credentials file to avoid the crash. Without that parameter, if the user not setup the project and after the deadline, import ee going to show an error about the google cloud project, but that is a better way than crashing.

Traceback (most recent call last):
  File "/home/xavier/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs/ee/data.py", line 1481, in getAlgorithms
    .list(parent=_get_projects_path(), prettyPrint=False)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xavier/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs/googleapiclient/discovery.py", line 1124, in method
    raise TypeError(
TypeError: Parameter "parent" value "projects/" does not match the pattern "^projects/[^/]+$"
XavierCLL commented 2 weeks ago

Issue 2:

In the sign-in process, if for any reason the user close the web-browser without finish the login and/or not accept the permissions, Qgis frozen waiting for the response, and you need to kill Qgis instance.

It is a weird user case that we can fix later.

XavierCLL commented 2 weeks ago

Future feature:

In general I like the implementation, simple and practical, thanks Gena. Remember that we need to release it before Nov 13th.

Thinking as a second version of this implementation, and because for many users setup a project inside the Goggle Cloud platform could be challenging, the ideal is doing something quite similar of how GEE web client does: after sign-in, through API, get the user's projects and let the user select one in a drop list, and also an easy way to create a new project inside the plugin.

gena commented 2 weeks ago

Issue 1:

In the process to sign-in, If the user leaves the Project ID empty (for example the user want to create the project after sign-in and then setup it later using the "Set project" option), if you reload the plugin or restart Qgis, the plugin crash because the parameter "project" in credentials file is empty.

We can fix it checking if the project ID introduced by the user is empty or not, if so, not write the parameter "project" in credentials file to avoid the crash. Without that parameter, if the user not setup the project and after the deadline, import ee going to show an error about the google cloud project, but that is a better way than crashing.

Traceback (most recent call last):
  File "/home/xavier/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs/ee/data.py", line 1481, in getAlgorithms
    .list(parent=_get_projects_path(), prettyPrint=False)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xavier/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs/googleapiclient/discovery.py", line 1124, in method
    raise TypeError(
TypeError: Parameter "parent" value "projects/" does not match the pattern "^projects/[^/]+$"

Good catch, thanks! I will add a check to prevent breaking EE.

gena commented 2 weeks ago

Future feature:

In general I like the implementation, simple and practical, thanks Gena. Remember that we need to release it before Nov 13th.

Thinking as a second version of this implementation, and because for many users setup a project inside the Goggle Cloud platform could be challenging, the ideal is doing something quite similar of how GEE web client does: after sign-in, through API, get the user's projects and let the user select one in a drop list, and also an easy way to create a new project inside the plugin.

There was no time to fully replicate the Code Editor functionality, but it's one of improvements. To do it directly from Python and without installing gcloud it will require adding one more scope to list resources (Cloud Projects). Though boundary cases such as "User already authenticated EE before installing plugin" will have to be taken into account, forcing reauthentication to ensure the Oauth2 token has access.

gena commented 2 weeks ago

Issue 2:

In the sign-in process, if for any reason the user close the web-browser without finish the login and/or not accept the permissions, Qgis frozen waiting for the response, and you need to kill Qgis instance.

It is a weird user case that we can fix later.

Yes, I actually tested this, but ignored as this is something happening in Google Cloud libs. Killing QGIS instance for these few runs is an acceptable workaround for now.