Skip to content

Commit b1f17a8

Browse files
committed
[refactor] Migrated other clients to use common operations
1 parent 8ac1df8 commit b1f17a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+8951
-1680
lines changed

pyatlan/client/admin.py

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright 2022 Atlan Pte. Ltd.
2+
# Copyright 2025 Atlan Pte. Ltd.
33

4-
from typing import List
4+
from pydantic.v1 import validate_arguments
55

6-
from pydantic.v1 import ValidationError, parse_obj_as, validate_arguments
7-
8-
from pyatlan.client.common import ApiCaller
9-
from pyatlan.client.constants import ADMIN_EVENTS, KEYCLOAK_EVENTS
6+
from pyatlan.client.common import AdminGetAdminEvents, AdminGetKeycloakEvents, ApiCaller
107
from pyatlan.errors import ErrorCode
118
from pyatlan.model.keycloak_events import (
12-
AdminEvent,
139
AdminEventRequest,
1410
AdminEventResponse,
15-
KeycloakEvent,
1611
KeycloakEventRequest,
1712
KeycloakEventResponse,
1813
)
@@ -42,27 +37,20 @@ def get_keycloak_events(
4237
:returns: the events that match the supplied filters
4338
:raises AtlanError: on any API communication issue
4439
"""
45-
if raw_json := self._client._call_api(
46-
KEYCLOAK_EVENTS,
47-
query_params=keycloak_request.query_params,
40+
endpoint, query_params = AdminGetKeycloakEvents.prepare_request(
41+
keycloak_request
42+
)
43+
raw_json = self._client._call_api(
44+
endpoint,
45+
query_params=query_params,
4846
exclude_unset=True,
49-
):
50-
try:
51-
events = parse_obj_as(List[KeycloakEvent], raw_json)
52-
except ValidationError as err:
53-
raise ErrorCode.JSON_ERROR.exception_with_parameters(
54-
raw_json, 200, str(err)
55-
) from err
56-
else:
57-
events = []
58-
return KeycloakEventResponse(
59-
client=self._client,
60-
criteria=keycloak_request,
61-
start=keycloak_request.offset or 0,
62-
size=keycloak_request.size or 100,
63-
events=events,
47+
)
48+
response_data = AdminGetKeycloakEvents.process_response(
49+
raw_json, keycloak_request
6450
)
6551

52+
return KeycloakEventResponse(client=self._client, **response_data)
53+
6654
@validate_arguments
6755
def get_admin_events(self, admin_request: AdminEventRequest) -> AdminEventResponse:
6856
"""
@@ -72,21 +60,10 @@ def get_admin_events(self, admin_request: AdminEventRequest) -> AdminEventRespon
7260
:returns: the admin events that match the supplied filters
7361
:raises AtlanError: on any API communication issue
7462
"""
75-
if raw_json := self._client._call_api(
76-
ADMIN_EVENTS, query_params=admin_request.query_params, exclude_unset=True
77-
):
78-
try:
79-
events = parse_obj_as(List[AdminEvent], raw_json)
80-
except ValidationError as err:
81-
raise ErrorCode.JSON_ERROR.exception_with_parameters(
82-
raw_json, 200, str(err)
83-
) from err
84-
else:
85-
events = []
86-
return AdminEventResponse(
87-
client=self._client,
88-
criteria=admin_request,
89-
start=admin_request.offset or 0,
90-
size=admin_request.size or 100,
91-
events=events,
63+
endpoint, query_params = AdminGetAdminEvents.prepare_request(admin_request)
64+
raw_json = self._client._call_api(
65+
endpoint, query_params=query_params, exclude_unset=True
9266
)
67+
response_data = AdminGetAdminEvents.process_response(raw_json, admin_request)
68+
69+
return AdminEventResponse(client=self._client, **response_data)

pyatlan/client/aio/__init__.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This module provides async versions of all Atlan client functionality
66
with the same API as the sync versions, just requiring await.
77
8-
Pattern: All async methods reuse shared business logic from pyatlan.client.shared
8+
Pattern: All async methods reuse shared business logic from pyatlan.client.common
99
to ensure identical behavior with sync clients.
1010
1111
Usage:
@@ -19,20 +19,61 @@
1919
print(asset.name)
2020
"""
2121

22-
from .asset import AsyncAssetClient
23-
from .client import AsyncAtlanClient
24-
from .results import (
22+
from pyatlan.model.aio import (
2523
AsyncIndexSearchResults,
2624
AsyncLineageListResults,
2725
AsyncSearchResults,
2826
SimpleConcurrentAsyncIndexSearchResults,
2927
)
3028

29+
from .admin import AsyncAdminClient
30+
from .asset import AsyncAssetClient
31+
from .audit import AsyncAuditClient
32+
from .client import AsyncAtlanClient
33+
from .contract import AsyncContractClient
34+
from .credential import AsyncCredentialClient
35+
from .file import AsyncFileClient
36+
from .group import AsyncGroupClient
37+
from .impersonate import AsyncImpersonationClient
38+
from .open_lineage import AsyncOpenLineageClient
39+
from .query import AsyncQueryClient
40+
from .role import AsyncRoleClient
41+
from .search_log import AsyncSearchLogClient
42+
from .sso import AsyncSSOClient
43+
from .task import AsyncTaskClient
44+
from .token import AsyncTokenClient
45+
from .typedef import AsyncTypeDefClient
46+
from .user import AsyncUserClient
47+
from .workflow import AsyncWorkflowClient
48+
3149
__all__ = [
3250
"AsyncAtlanClient",
51+
"AsyncAdminClient",
3352
"AsyncAssetClient",
53+
"AsyncAuditClient",
54+
"AsyncAuditSearchResults",
55+
"AsyncContractClient",
56+
"AsyncCredentialClient",
57+
"AsyncFileClient",
58+
"AsyncGroupClient",
59+
"AsyncGroupResponse",
60+
"AsyncImpersonationClient",
3461
"AsyncIndexSearchResults",
3562
"AsyncLineageListResults",
63+
"AsyncOpenLineageClient",
64+
"AsyncQueryClient",
65+
"AsyncRoleClient",
66+
"AsyncSearchLogClient",
67+
"AsyncSearchLogResults",
3668
"AsyncSearchResults",
69+
"AsyncSSOClient",
70+
"AsyncTaskClient",
71+
"AsyncTaskSearchResponse",
72+
"AsyncTokenClient",
73+
"AsyncTypeDefClient",
74+
"AsyncUserClient",
75+
"AsyncUserResponse",
76+
"AsyncWorkflowClient",
77+
"AsyncWorkflowSearchResponse",
3778
"SimpleConcurrentAsyncIndexSearchResults",
3879
]

pyatlan/client/aio/admin.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2025 Atlan Pte. Ltd.
3+
4+
from pydantic.v1 import validate_arguments
5+
6+
from pyatlan.client.common import AdminGetAdminEvents, AdminGetKeycloakEvents, ApiCaller
7+
from pyatlan.errors import ErrorCode
8+
from pyatlan.model.aio.keycloak_events import (
9+
AsyncAdminEventResponse,
10+
AsyncKeycloakEventResponse,
11+
)
12+
from pyatlan.model.keycloak_events import AdminEventRequest, KeycloakEventRequest
13+
14+
15+
class AsyncAdminClient:
16+
"""
17+
Async version of AdminClient for retrieving keycloak and admin events. This class does not need to be instantiated
18+
directly but can be obtained through the admin property of AsyncAtlanClient.
19+
"""
20+
21+
def __init__(self, client: ApiCaller):
22+
if not isinstance(client, ApiCaller):
23+
raise ErrorCode.INVALID_PARAMETER_TYPE.exception_with_parameters(
24+
"client", "ApiCaller"
25+
)
26+
self._client = client
27+
28+
@validate_arguments
29+
async def get_keycloak_events(
30+
self, keycloak_request: KeycloakEventRequest
31+
) -> AsyncKeycloakEventResponse:
32+
"""
33+
Retrieve all events, based on the supplied filters.
34+
35+
:param keycloak_request: details of the filters to apply when retrieving events
36+
:returns: the events that match the supplied filters
37+
:raises AtlanError: on any API communication issue
38+
"""
39+
endpoint, query_params = AdminGetKeycloakEvents.prepare_request(
40+
keycloak_request
41+
)
42+
raw_json = await self._client._call_api(
43+
endpoint,
44+
query_params=query_params,
45+
exclude_unset=True,
46+
)
47+
response_data = AdminGetKeycloakEvents.process_response(
48+
raw_json, keycloak_request
49+
)
50+
51+
return AsyncKeycloakEventResponse(client=self._client, **response_data)
52+
53+
@validate_arguments
54+
async def get_admin_events(
55+
self, admin_request: AdminEventRequest
56+
) -> AsyncAdminEventResponse:
57+
"""
58+
Retrieve admin events based on the supplied filters.
59+
60+
:param admin_request: details of the filters to apply when retrieving admin events
61+
:returns: the admin events that match the supplied filters
62+
:raises AtlanError: on any API communication issue
63+
"""
64+
endpoint, query_params = AdminGetAdminEvents.prepare_request(admin_request)
65+
raw_json = await self._client._call_api(
66+
endpoint, query_params=query_params, exclude_unset=True
67+
)
68+
response_data = AdminGetAdminEvents.process_response(raw_json, admin_request)
69+
70+
return AsyncAdminEventResponse(client=self._client, **response_data)

0 commit comments

Comments
 (0)