|
1 | 1 | import asyncio |
2 | 2 | import contextlib |
3 | 3 | import logging |
| 4 | +import os |
4 | 5 | import re |
5 | 6 | import time |
6 | 7 | from typing import Dict, Optional, Tuple |
|
16 | 17 | ) |
17 | 18 | from ._logging import LogHandlerSumo |
18 | 19 | from ._retry_strategy import RetryStrategy |
19 | | -from .config import APP_REGISTRATION, AUTHORITY_HOST_URI, TENANT_ID |
20 | 20 |
|
21 | 21 | logger = logging.getLogger("sumo.wrapper") |
22 | 22 |
|
23 | 23 | DEFAULT_TIMEOUT = httpx.Timeout(30.0) |
24 | 24 |
|
| 25 | +WELL_KNOWN = os.environ.get( |
| 26 | + "SUMOCONNECTIONINFO", "https://api.sumo.equinor.com" |
| 27 | +) |
| 28 | + |
25 | 29 |
|
26 | 30 | class SumoClient: |
27 | 31 | """Authenticate and perform requests to the Sumo API.""" |
@@ -54,9 +58,17 @@ def __init__( |
54 | 58 |
|
55 | 59 | logger.setLevel(verbosity) |
56 | 60 |
|
57 | | - if env not in APP_REGISTRATION: |
| 61 | + well_known = httpx.get(WELL_KNOWN).json() |
| 62 | + if env not in well_known["envs"]: |
58 | 63 | raise ValueError(f"Invalid environment: {env}") |
59 | 64 |
|
| 65 | + tenant_id = well_known["tenant_id"] |
| 66 | + authority_host = well_known["authority"] |
| 67 | + config = well_known["envs"][env] |
| 68 | + client_id = config["client_id"] |
| 69 | + resource_id = config["resource_id"] |
| 70 | + base_url = config["base_url"] |
| 71 | + |
60 | 72 | self.env = env |
61 | 73 | self._verbosity = verbosity |
62 | 74 |
|
@@ -103,24 +115,17 @@ def __init__( |
103 | 115 | cleanup_shared_keys() |
104 | 116 |
|
105 | 117 | self.auth = get_auth_provider( |
106 | | - client_id=APP_REGISTRATION[env]["CLIENT_ID"], |
107 | | - authority=f"{AUTHORITY_HOST_URI}/{TENANT_ID}", |
108 | | - resource_id=APP_REGISTRATION[env]["RESOURCE_ID"], |
| 118 | + client_id=client_id, |
| 119 | + authority=f"{authority_host}{tenant_id}", |
| 120 | + resource_id=resource_id, |
109 | 121 | interactive=interactive, |
110 | 122 | refresh_token=refresh_token, |
111 | 123 | access_token=access_token, |
112 | 124 | devicecode=devicecode, |
113 | 125 | case_uuid=case_uuid, |
114 | 126 | ) |
115 | 127 |
|
116 | | - if env == "prod": |
117 | | - self.base_url = "https://api.sumo.equinor.com/api/v1" |
118 | | - elif env == "localhost": |
119 | | - self.base_url = "http://localhost:8084/api/v1" |
120 | | - else: |
121 | | - self.base_url = ( |
122 | | - f"https://main-sumo-core-{env}.c3.radix.equinor.com/api/v1" |
123 | | - ) |
| 128 | + self.base_url = base_url |
124 | 129 | return |
125 | 130 |
|
126 | 131 | def __enter__(self): |
|
0 commit comments