Skip to content

Commit ee86900

Browse files
committed
feat: get config info from well-known endpoint, rather than hard-coded in library.
1 parent 650a0d1 commit ee86900

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

src/sumo/wrapper/config.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/sumo/wrapper/sumo_client.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import contextlib
33
import logging
4+
import os
45
import re
56
import time
67
from typing import Dict, Optional, Tuple
@@ -16,12 +17,15 @@
1617
)
1718
from ._logging import LogHandlerSumo
1819
from ._retry_strategy import RetryStrategy
19-
from .config import APP_REGISTRATION, AUTHORITY_HOST_URI, TENANT_ID
2020

2121
logger = logging.getLogger("sumo.wrapper")
2222

2323
DEFAULT_TIMEOUT = httpx.Timeout(30.0)
2424

25+
WELL_KNOWN = os.environ.get(
26+
"SUMOCONNECTIONINFO", "https://api.sumo.equinor.com"
27+
)
28+
2529

2630
class SumoClient:
2731
"""Authenticate and perform requests to the Sumo API."""
@@ -54,9 +58,17 @@ def __init__(
5458

5559
logger.setLevel(verbosity)
5660

57-
if env not in APP_REGISTRATION:
61+
well_known = httpx.get(WELL_KNOWN).json()
62+
if env not in well_known["envs"]:
5863
raise ValueError(f"Invalid environment: {env}")
5964

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+
6072
self.env = env
6173
self._verbosity = verbosity
6274

@@ -103,24 +115,17 @@ def __init__(
103115
cleanup_shared_keys()
104116

105117
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,
109121
interactive=interactive,
110122
refresh_token=refresh_token,
111123
access_token=access_token,
112124
devicecode=devicecode,
113125
case_uuid=case_uuid,
114126
)
115127

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
124129
return
125130

126131
def __enter__(self):

0 commit comments

Comments
 (0)