Skip to content

Commit 524d806

Browse files
committed
FT-910: Fixed _user_id handling in get_client() method
1 parent 77fe61a commit 524d806

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Diff for: pyatlan/pkg/utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def get_client(impersonate_user_id: str) -> AtlanClient:
8282
elif user_id:
8383
LOGGER.info("No API token found, attempting to impersonate user: %s", user_id)
8484
client = AtlanClient(base_url=base_url, api_key="")
85-
client._user_id = user_id
8685
api_key = client.impersonate.user(user_id=user_id)
8786
else:
8887
LOGGER.info(
@@ -91,7 +90,10 @@ def get_client(impersonate_user_id: str) -> AtlanClient:
9190
client = AtlanClient(base_url=base_url, api_key="")
9291
api_key = client.impersonate.escalate()
9392

94-
return AtlanClient(base_url=base_url, api_key=api_key)
93+
client = AtlanClient(base_url=base_url, api_key=api_key)
94+
if user_id:
95+
client._user_id = user_id
96+
return client
9597

9698

9799
def set_package_ops(run_time_config: RuntimeConfig) -> AtlanClient:

Diff for: tests/integration/custom_package_test.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import pytest
77

88
from pyatlan.client.atlan import AtlanClient
9+
from pyatlan.client.impersonate import ImpersonationClient
910
from pyatlan.pkg.models import CustomPackage, generate
1011
from pyatlan.pkg.ui import UIConfig, UIStep
11-
from pyatlan.pkg.utils import set_package_headers
12+
from pyatlan.pkg.utils import get_client, set_package_headers
1213
from pyatlan.pkg.widgets import TextInput
1314

1415

@@ -21,6 +22,9 @@ def mock_pkg_env():
2122
"X_ATLAN_AGENT_ID": "agent_id_value",
2223
"X_ATLAN_AGENT_PACKAGE_NAME": "package_name_value",
2324
"X_ATLAN_AGENT_WORKFLOW_ID": "workflow_id_value",
25+
"X_ATLAN_AGENT_WORKFLOW_ID": "workflow_id_value",
26+
"CLIENT_ID": "client_id_value",
27+
"CLIENT_SECRET": "client_secret_value",
2428
},
2529
clear=True,
2630
):
@@ -104,3 +108,16 @@ def test_set_package_headers(client: AtlanClient, mock_pkg_env):
104108
}
105109
mock_client.update_headers.assert_called_once_with(expected_headers)
106110
assert updated_client == mock_client
111+
112+
113+
@patch.object(ImpersonationClient, "user", return_value="some-api-key")
114+
def test_get_client_user_id_handling(
115+
mock_impersonate_client,
116+
mock_pkg_env,
117+
client: AtlanClient,
118+
):
119+
updated_client = get_client(impersonate_user_id="test-user-id")
120+
assert updated_client
121+
assert updated_client.base_url
122+
assert updated_client.api_key == "some-api-key"
123+
assert updated_client._user_id == "test-user-id"

0 commit comments

Comments
 (0)