Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Selection: Replace text input with a project selection dropdown #166

Open
zacdezgeo opened this issue Dec 16, 2024 · 3 comments
Open
Assignees

Comments

@zacdezgeo
Copy link
Collaborator

zacdezgeo commented Dec 16, 2024

The current project selection workflow in the plugin requires users to manually input a Google Cloud project name as a text string. This input is then sent to Earth Engine (EE) without any validation, which can lead to errors if the project name is misspelled or unregistered for Earth Engine access.

To improve the user experience, the plugin should allow users to select a Google Cloud project from a dropdown list, similar to how the Earth Engine Code Editor handles project selection. The dropdown should fetch and display only active projects associated with the user’s account.

Related links:

@alukach alukach self-assigned this Jan 2, 2025
@alukach
Copy link
Collaborator

alukach commented Jan 7, 2025

I spent some time working through this but have been unable to retrieve a list of projects for a given set of credentials.

After authenticating, I've been trying the following:

from googleapiclient import discovery
from ee.data import get_persistent_credentials

credentials = get_persistent_credentials()
service = discovery.build("cloudresourcemanager", "v1", credentials=credentials)
request = service.projects().list()
while request is not None:
    response = request.execute()
    for project in response.get("projects", []):
        print(f'{project["projectId"]=}')
    request = service.projects().list_next(
        previous_request=request, previous_response=response
    )

However, this yields the following error:

googleapiclient.errors.HttpError: 
<HttpError 403 when requesting https://cloudresourcemanager.googleapis.com/v1/projects?alt=json 
returned "Cloud Resource Manager API has not been used in project 517222506229 before 
or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=517222506229 
then retry. If you enabled this API recently, wait a few minutes for the action to 
propagate to our systems and retry.". 
Details: "[
    {
        '@type': 'type.googleapis.com/google.rpc.Help', 
        'links': [
            {
                'description': 'Google developers console API activation', 
                'url': 'https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=517222506229'
            }
        ]
    }, 
    {
        '@type': 'type.googleapis.com/google.rpc.ErrorInfo', 
        'reason': 'SERVICE_DISABLED', 
        'domain': 'googleapis.com', 
        'metadata': {
            'service': 'cloudresourcemanager.googleapis.com', 
            'consumer': 'projects/517222506229'
        }
    }
]">

The project 517222506229 mentioned comes from the OAuth credentials hardcoded into the earthengine API.

Unless an administrator of the OAuth client for the earthengine API is willing/capable of updating the client configuration to enable the cloud resource manager API, I don't think we can make such a query.

I will note that I don't think scopes are a factor regarding this issue, as the default scopes used includes https://www.googleapis.com/auth/cloud-platform, which is one of the required for the resource manager's project.list call.

@jdbcode
Copy link
Contributor

jdbcode commented Jan 7, 2025

@naschmitz for awareness. RE project listing and selection.

@naschmitz
Copy link

naschmitz commented Jan 8, 2025

This is something the Earth Engine Python team is thinking about as well.

517222506229 is the ee-api-python-authenticator project. We shouldn't be using that client project for Cloud Resource Manager requests.

I'm unable to reproduce the issue you're seeing, but I have a couple ideas for fixes:

  • We still support the notebook auth mode. Authenticate with ee.Authenticate(auth_mode="notebook") and a project selector appears in the notebook authenticator. The application default credentials will store project information, so no need to specify project in ee.Initialize. I believe this is what the QGIS plugin was doing before we switched the default auth mode but I'm not sure.
  • You could try using the Cloud Resource Manager client library: https://cloud.google.com/python/docs/reference/cloudresourcemanager/0.30.5. It'll be easier and more robust than using the cloudresourcemanager Discovery API.
  • You could also try creating credentials using the google.auth module instead of using the ones created by Earth Engine: import google.auth and credentials, project = google.auth.default().

I'm happy to dig into this problem more later in the week. Let me know whether the suggestions worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants