Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3299,7 +3299,7 @@ def ee_to_xarray(
f"Failed to access Earth Engine internal state for current project: {e}\n"
"Please provide the 'project' parameter explicitly or ensure Earth Engine is properly initialized."
)

# Use current_project if available, otherwise use provided project
if current_project is not None:
ee.Initialize(project=current_project, opt_url=opt_url)
Expand Down
14 changes: 14 additions & 0 deletions geemap/coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ def ee_initialize(
if ee.data._get_state().credentials is not None:
return

if get_env_var("EE_SERVICE_ACCOUNT") is not None:

key_data = get_env_var("EE_SERVICE_ACCOUNT")

Comment on lines +79 to +82
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable key_data is redundantly assigned. Line 79 already checks that get_env_var("EE_SERVICE_ACCOUNT") is not None, so the result can be stored directly without calling get_env_var again. Consider storing it in a variable on line 79 to avoid the duplicate call.

Suggested change
if get_env_var("EE_SERVICE_ACCOUNT") is not None:
key_data = get_env_var("EE_SERVICE_ACCOUNT")
key_data = get_env_var("EE_SERVICE_ACCOUNT")
if key_data is not None:

Copilot uses AI. Check for mistakes.
try:
email = json.loads(key_data)["client_email"]
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON for key_data: {e}")
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message references key_data which is an internal variable name. For better user experience, consider referencing the environment variable name instead: "Invalid JSON in EE_SERVICE_ACCOUNT environment variable: {e}"

Suggested change
raise ValueError(f"Invalid JSON for key_data: {e}")
raise ValueError(f"Invalid JSON in EE_SERVICE_ACCOUNT environment variable: {e}")

Copilot uses AI. Check for mistakes.
except KeyError:
raise ValueError("key_data JSON does not contain 'client_email'")
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message references key_data which is an internal variable name. For better user experience, consider referencing the environment variable name instead: "EE_SERVICE_ACCOUNT JSON does not contain 'client_email'"

Suggested change
raise ValueError("key_data JSON does not contain 'client_email'")
raise ValueError("EE_SERVICE_ACCOUNT JSON does not contain 'client_email'")

Copilot uses AI. Check for mistakes.
credentials = ee.ServiceAccountCredentials(email=email, key_data=key_data)
ee.Initialize(credentials)
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ee.Initialize() call doesn't pass the **kwargs parameter, unlike the other authentication paths (e.g., line 106). This means users cannot pass additional parameters like opt_url for the High-Volume platform when using service account authentication. Consider changing to ee.Initialize(credentials, **kwargs) for consistency.

Suggested change
ee.Initialize(credentials)
ee.Initialize(credentials, **kwargs)

Copilot uses AI. Check for mistakes.
return

ee_token = get_env_var(token_name)
if ee_token is not None:

Expand Down