Skip to content
Merged
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
26 changes: 0 additions & 26 deletions src/sumo/wrapper/config.py

This file was deleted.

31 changes: 18 additions & 13 deletions src/sumo/wrapper/sumo_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import contextlib
import logging
import os
import re
import time
from typing import Dict, Optional, Tuple
Expand All @@ -16,12 +17,15 @@
)
from ._logging import LogHandlerSumo
from ._retry_strategy import RetryStrategy
from .config import APP_REGISTRATION, AUTHORITY_HOST_URI, TENANT_ID

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

DEFAULT_TIMEOUT = httpx.Timeout(30.0)

WELL_KNOWN = os.environ.get(
"SUMOCONNECTIONINFO", "https://api.sumo.equinor.com/well-known"
)


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

logger.setLevel(verbosity)

if env not in APP_REGISTRATION:
well_known = httpx.get(WELL_KNOWN).json()
if env not in well_known["envs"]:
raise ValueError(f"Invalid environment: {env}")

tenant_id = well_known["tenant_id"]
authority_host = well_known["authority"]
config = well_known["envs"][env]
client_id = config["client_id"]
resource_id = config["resource_id"]
base_url = config["base_url"]

self.env = env
self._verbosity = verbosity

Expand Down Expand Up @@ -103,24 +115,17 @@ def __init__(
cleanup_shared_keys()

self.auth = get_auth_provider(
client_id=APP_REGISTRATION[env]["CLIENT_ID"],
authority=f"{AUTHORITY_HOST_URI}/{TENANT_ID}",
resource_id=APP_REGISTRATION[env]["RESOURCE_ID"],
client_id=client_id,
authority=f"{authority_host}{tenant_id}",
resource_id=resource_id,
interactive=interactive,
refresh_token=refresh_token,
access_token=access_token,
devicecode=devicecode,
case_uuid=case_uuid,
)

if env == "prod":
self.base_url = "https://api.sumo.equinor.com/api/v1"
elif env == "localhost":
self.base_url = "http://localhost:8084/api/v1"
else:
self.base_url = (
f"https://main-sumo-core-{env}.c3.radix.equinor.com/api/v1"
)
self.base_url = base_url
return

def __enter__(self):
Expand Down