Skip to content

Commit 8c4d4a4

Browse files
authored
Feat/use azure client id to authenticate (#256)
* add .idea to gitignore * add authenticate using azure client id * feat: add client_id to the constructor * feat: change client_id order in __init__
1 parent b0100ed commit 8c4d4a4

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__pycache__/
22
*.py[cod]
33
.DS_Store
4+
.idea*
45
*~
56
_venv
67
venv

src/sumo/wrapper/sumo_client.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SumoClient:
3535

3636
def __init__(
3737
self,
38-
env: str,
38+
env: str = "prod",
3939
token: Optional[str] = None,
4040
interactive: bool = True,
4141
devicecode: bool = False,
@@ -45,15 +45,28 @@ def __init__(
4545
case_uuid=None,
4646
http_client=None,
4747
async_http_client=None,
48+
client_id: Optional[str] = None,
4849
):
4950
"""Initialize a new Sumo object
5051
5152
Args:
52-
env: Sumo environment
53-
token: Access token or refresh token.
54-
interactive: Enable interactive authentication (in browser).
55-
If not enabled, code grant flow will be used.
56-
verbosity: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
53+
env (str): Sumo environment. Defaults to "prod".
54+
token (Optional[str]): Access token or refresh token. Defaults to None.
55+
interactive (bool): Enable interactive authentication (in browser).
56+
If not enabled, code grant flow will be used. Defaults to True.
57+
devicecode (bool): Enable device code flow. Defaults to False.
58+
verbosity (str): Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL).
59+
Defaults to "CRITICAL".
60+
retry_strategy (RetryStrategy): Retry strategy for HTTP requests.
61+
Defaults to RetryStrategy().
62+
timeout (int): Timeout for HTTP requests. Defaults to DEFAULT_TIMEOUT.
63+
case_uuid (Optional[str]): Case UUID for authentication. Defaults to None.
64+
http_client (Optional[httpx.Client]): HTTP client for synchronous requests.
65+
Defaults to None.
66+
async_http_client (Optional[httpx.AsyncClient]): HTTP client for asynchronous requests.
67+
Defaults to None.
68+
client_id (Optional[str]): Client ID for authentication. If None, will use
69+
AZURE_CLIENT_ID from environment variables or the config. Defaults to None.
5770
"""
5871

5972
logger.setLevel(verbosity)
@@ -65,10 +78,13 @@ def __init__(
6578
tenant_id = well_known["tenant_id"]
6679
authority_host = well_known["authority"]
6780
config = well_known["envs"][env]
68-
client_id = config["client_id"]
6981
resource_id = config["resource_id"]
7082
base_url = config["base_url"]
71-
83+
self.client_id = (
84+
client_id
85+
or os.environ.get("AZURE_CLIENT_ID")
86+
or config["client_id"]
87+
)
7288
self.env = env
7389
self._verbosity = verbosity
7490

@@ -113,9 +129,8 @@ def __init__(
113129
pass
114130

115131
cleanup_shared_keys()
116-
117132
self.auth = get_auth_provider(
118-
client_id=client_id,
133+
client_id=self.client_id,
119134
authority=f"{authority_host}{tenant_id}",
120135
resource_id=resource_id,
121136
interactive=interactive,

0 commit comments

Comments
 (0)