Skip to content

Commit 2b02771

Browse files
authored
Merge branch 'main' into APP-5243
2 parents 6fdcc42 + fcefbdc commit 2b02771

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pyatlan/client/atlan.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,13 @@ def dq_template_config_cache(self) -> DQTemplateConfigCache:
350350
return self._dq_template_config_cache
351351

352352
@classmethod
353-
def from_token_guid(cls, guid: str) -> AtlanClient:
353+
def from_token_guid(
354+
cls,
355+
guid: str,
356+
base_url: Optional[str] = None,
357+
client_id: Optional[str] = None,
358+
client_secret: Optional[str] = None,
359+
) -> AtlanClient:
354360
"""
355361
Create an AtlanClient instance using an API token GUID.
356362
@@ -361,16 +367,20 @@ def from_token_guid(cls, guid: str) -> AtlanClient:
361367
4. Returns a new AtlanClient authenticated with the resolved token
362368
363369
:param guid: API token GUID to resolve
370+
:param base_url: Optional base URL for the Atlan service(overrides ATLAN_BASE_URL environment variable)
371+
:param client_id: Optional client ID for authentication (overrides CLIENT_ID environment variable)
372+
:param client_secret: Optional client secret for authentication (overrides CLIENT_SECRET environment variable)
364373
:returns: a new client instance authenticated with the resolved token
365374
:raises: ErrorCode.UNABLE_TO_ESCALATE_WITH_PARAM: If any step in the token resolution fails
366375
"""
367-
base_url = os.environ.get("ATLAN_BASE_URL", "INTERNAL")
376+
final_base_url = base_url or os.environ.get("ATLAN_BASE_URL", "INTERNAL")
368377

369378
# Step 1: Initialize base client and get Atlan-Argo credentials
370379
# Note: Using empty api_key as we're bootstrapping authentication
371-
client = AtlanClient(base_url=base_url)
372-
client.api_key = ""
373-
client_info = ImpersonateUser.get_client_info()
380+
client = AtlanClient(base_url=final_base_url, api_key="")
381+
client_info = client.impersonate._get_client_info(
382+
client_id=client_id, client_secret=client_secret
383+
)
374384

375385
# Prepare credentials for Atlan-Argo token request
376386
argo_credentials = {
@@ -384,7 +394,7 @@ def from_token_guid(cls, guid: str) -> AtlanClient:
384394
try:
385395
raw_json = client._call_api(GET_TOKEN, request_obj=argo_credentials)
386396
argo_token = AccessTokenResponse(**raw_json).access_token
387-
temp_argo_client = AtlanClient(base_url=base_url, api_key=argo_token)
397+
temp_argo_client = AtlanClient(base_url=final_base_url, api_key=argo_token)
388398
except AtlanError as atlan_err:
389399
raise ErrorCode.UNABLE_TO_ESCALATE_WITH_PARAM.exception_with_parameters(
390400
"Failed to obtain Atlan-Argo token"
@@ -410,7 +420,7 @@ def from_token_guid(cls, guid: str) -> AtlanClient:
410420
token_api_key = AccessTokenResponse(**raw_json).access_token
411421

412422
# Step 5: Create and return the authenticated client
413-
return AtlanClient(base_url=base_url, api_key=token_api_key)
423+
return AtlanClient(base_url=final_base_url, api_key=token_api_key)
414424
except AtlanError as atlan_err:
415425
raise ErrorCode.UNABLE_TO_ESCALATE_WITH_PARAM.exception_with_parameters(
416426
"Failed to obtain access token for API token"

pyatlan/client/impersonate.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ def user(self, user_id: str) -> str:
6161
except AtlanError as atlan_err:
6262
raise ErrorCode.UNABLE_TO_IMPERSONATE.exception_with_parameters() from atlan_err
6363

64+
65+
def _get_client_info(
66+
self, client_id: Optional[str] = None, client_secret: Optional[str] = None
67+
) -> ClientInfo:
68+
final_client_id = client_id or os.getenv("CLIENT_ID")
69+
final_client_secret = client_secret or os.getenv("CLIENT_SECRET")
70+
if not final_client_id or not final_client_secret:
71+
raise ErrorCode.MISSING_CREDENTIALS.exception_with_parameters()
72+
client_info = ClientInfo(
73+
client_id=final_client_id, client_secret=final_client_secret
74+
)
75+
return client_info
76+
6477
def escalate(self) -> str:
6578
"""
6679
Escalate to a privileged user on a short-term basis.

0 commit comments

Comments
 (0)