|
5 | 5 | from collections.abc import Sequence |
6 | 6 | from datetime import datetime |
7 | 7 | from datetime import timedelta |
8 | | -from enum import Enum |
9 | 8 | from functools import lru_cache |
10 | 9 | from functools import partial |
11 | 10 | from typing import Any |
|
19 | 18 | from IPython.display import display |
20 | 19 | from jupyterhub.services.auth import HubAuth |
21 | 20 |
|
| 21 | +from dapla.const import DaplaEnvironment |
| 22 | +from dapla.const import DaplaRegion |
| 23 | +from dapla.const import DaplaService |
| 24 | + |
22 | 25 | logger = logging.getLogger(__name__) |
23 | 26 |
|
24 | 27 | # Refresh window was modified in: https://github.com/googleapis/google-auth-library-python/commit/c6af1d692b43833baca978948376739547cf685a |
|
29 | 32 | google.auth._helpers.REFRESH_THRESHOLD = timedelta(seconds=20) |
30 | 33 |
|
31 | 34 |
|
32 | | -class DaplaEnvironment(Enum): |
33 | | - """Represents the 'DAPLA_ENVIRONMENT' environment variable.""" |
34 | | - |
35 | | - DEV = "DEV" |
36 | | - STAGING = "STAGING" |
37 | | - TEST = "TEST" |
38 | | - PROD = "PROD" |
39 | | - |
40 | | - |
41 | | -class DaplaService(Enum): |
42 | | - """Represents the 'DAPLA_SERVICE' environment variable.""" |
43 | | - |
44 | | - JUPYTERLAB = "JUPYTERLAB" |
45 | | - VS_CODE = "VS_CODE" |
46 | | - R_STUDIO = "R_STUDIO" |
47 | | - CLOUD_RUN = "CLOUD_RUN" |
48 | | - |
49 | | - |
50 | | -class DaplaRegion(Enum): |
51 | | - """Represents the 'DAPLA_REGION' environment variable.""" |
52 | | - |
53 | | - ON_PREM = "ON_PREM" |
54 | | - DAPLA_LAB = "DAPLA_LAB" |
55 | | - BIP = "BIP" |
56 | | - CLOUD_RUN = "CLOUD_RUN" |
57 | | - |
58 | | - |
59 | 35 | class AuthClient: |
60 | 36 | """Client for retrieving authentication information.""" |
61 | 37 |
|
@@ -347,6 +323,9 @@ def fetch_personal_token() -> str: |
347 | 323 | @lru_cache(maxsize=1) |
348 | 324 | def fetch_email_from_credentials() -> Optional[str]: |
349 | 325 | """Retrieves an e-mail based on current Google Credentials. Potentially makes a Google API call.""" |
| 326 | + if os.getenv("DAPLA_REGION") == str(DaplaRegion.DAPLA_LAB): |
| 327 | + return os.getenv("DAPLA_USER") |
| 328 | + |
350 | 329 | credentials = AuthClient.fetch_google_credentials() |
351 | 330 | response = requests.get( |
352 | 331 | url=f"https://oauth2.googleapis.com/tokeninfo?access_token={credentials.token}" |
|
0 commit comments