Skip to content

Commit f6e05fc

Browse files
author
Xee authors
committed
Add argument to generate ee credentials on-demand.
PiperOrigin-RevId: 710437577
1 parent 5ce8db6 commit f6e05fc

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

xee/ext.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
from __future__ import annotations
2020

2121
import concurrent.futures
22+
import copy
2223
import functools
2324
import importlib
2425
import itertools
2526
import logging
2627
import math
2728
import os
2829
import sys
29-
from typing import Any, Dict, Iterable, List, Literal, Optional, Sequence, Tuple, Union
30+
from typing import Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple, Union
3031
from urllib import parse
3132
import warnings
3233

@@ -803,7 +804,20 @@ def _ee_init_check(self):
803804
'Attempting to initialize using application default credentials.'
804805
)
805806

806-
ee.Initialize(**(self.store.ee_init_kwargs or {}))
807+
ee_init_kwargs = copy.copy(self.store.ee_init_kwargs) or {}
808+
if (
809+
'credentials' in ee_init_kwargs
810+
and 'credentials_function' in ee_init_kwargs
811+
):
812+
raise ValueError(
813+
'Cannot specify both credentials and credentials_function.'
814+
)
815+
if 'credentials_function' in ee_init_kwargs:
816+
credentials_function: Callable[[], Any] = ee_init_kwargs.pop(
817+
'credentials_function'
818+
)
819+
ee_init_kwargs['credentials'] = credentials_function()
820+
ee.Initialize(**ee_init_kwargs)
807821

808822
def __getitem__(self, key: indexing.ExplicitIndexer) -> np.typing.ArrayLike:
809823
return indexing.explicit_indexing_adapter(

0 commit comments

Comments
 (0)