Skip to content

Commit 3885a46

Browse files
committed
Added iterative pagination and removed get_all() method
1 parent d332b8a commit 3885a46

9 files changed

Lines changed: 214 additions & 119 deletions

File tree

pyatlan/client/aio/oauth_client.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
AsyncApiCaller,
1212
OAuthClientCreate,
1313
OAuthClientGet,
14-
OAuthClientGetAll,
1514
OAuthClientGetById,
1615
OAuthClientPurge,
1716
OAuthClientUpdate,
1817
RoleGet,
1918
)
2019
from pyatlan.errors import ErrorCode
20+
from pyatlan.model.aio.oauth_client import AsyncOAuthClientListResponse
2121
from pyatlan.model.oauth_client import (
2222
OAuthClientCreateResponse,
23-
OAuthClientListResponse,
2423
OAuthClientResponse,
2524
)
2625

@@ -37,36 +36,32 @@ def __init__(self, client: AsyncApiCaller):
3736
)
3837
self._client = client
3938

40-
async def get_all(self) -> OAuthClientListResponse:
41-
"""
42-
Retrieves all OAuth clients defined in Atlan.
43-
44-
:returns: an OAuthClientListResponse containing all OAuth clients
45-
:raises AtlanError: on any API communication issue
46-
"""
47-
endpoint, query_params = OAuthClientGetAll.prepare_request()
48-
raw_json = await self._client._call_api(endpoint, query_params)
49-
return OAuthClientGetAll.process_response(raw_json)
50-
5139
@validate_arguments
5240
async def get(
5341
self,
54-
limit: Optional[int] = None,
42+
limit: int = 20,
5543
offset: int = 0,
5644
sort: Optional[str] = None,
57-
) -> OAuthClientListResponse:
45+
) -> AsyncOAuthClientListResponse:
5846
"""
5947
Retrieves OAuth clients defined in Atlan with pagination support.
6048
61-
:param limit: maximum number of results to be returned
49+
:param limit: maximum number of results to be returned per page (default: 20)
6250
:param offset: starting point for results to return, for paging
6351
:param sort: property by which to sort the results (e.g., 'createdAt' for descending)
64-
:returns: an OAuthClientListResponse containing records and pagination info
52+
:returns: an AsyncOAuthClientListResponse containing records and pagination info
6553
:raises AtlanError: on any API communication issue
6654
"""
6755
endpoint, query_params = OAuthClientGet.prepare_request(limit, offset, sort)
6856
raw_json = await self._client._call_api(endpoint, query_params)
69-
return OAuthClientGet.process_response(raw_json)
57+
return AsyncOAuthClientListResponse(
58+
**raw_json,
59+
endpoint=endpoint,
60+
client=self._client,
61+
size=limit,
62+
start=offset,
63+
sort=sort,
64+
)
7065

7166
@validate_arguments
7267
async def get_by_id(self, client_id: str) -> OAuthClientResponse:

pyatlan/client/common/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
from .oauth_client import (
102102
OAuthClientCreate,
103103
OAuthClientGet,
104-
OAuthClientGetAll,
105104
OAuthClientGetById,
106105
OAuthClientPurge,
107106
OAuthClientUpdate,
@@ -268,7 +267,6 @@
268267
# OAuth client shared logic classes
269268
"OAuthClientCreate",
270269
"OAuthClientGet",
271-
"OAuthClientGetAll",
272270
"OAuthClientGetById",
273271
"OAuthClientPurge",
274272
"OAuthClientUpdate",

pyatlan/client/common/oauth_client.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,18 @@
1616
from pyatlan.errors import ErrorCode
1717
from pyatlan.model.oauth_client import (
1818
OAuthClientCreateResponse,
19-
OAuthClientListResponse,
2019
OAuthClientRequest,
2120
OAuthClientResponse,
2221
)
2322
from pyatlan.model.role import AtlanRole
2423

2524

26-
class OAuthClientGetAll:
27-
"""Shared logic for getting all OAuth clients without pagination."""
28-
29-
@staticmethod
30-
def prepare_request() -> tuple:
31-
"""
32-
Prepare the request for getting all OAuth clients.
33-
34-
:returns: tuple of (endpoint, query_params)
35-
"""
36-
return GET_OAUTH_CLIENTS.format_path_with_params(), None
37-
38-
@staticmethod
39-
def process_response(raw_json: Dict) -> OAuthClientListResponse:
40-
"""
41-
Process the API response into an OAuthClientListResponse object.
42-
43-
:param raw_json: raw response from the API
44-
:returns: OAuthClientListResponse with pagination info and records
45-
"""
46-
return OAuthClientListResponse(**raw_json)
47-
48-
4925
class OAuthClientGet:
5026
"""Shared logic for getting OAuth clients with pagination."""
5127

5228
@staticmethod
5329
def prepare_request(
54-
limit: Optional[int] = None,
30+
limit: int = 20,
5531
offset: int = 0,
5632
sort: Optional[str] = None,
5733
) -> tuple:
@@ -66,23 +42,12 @@ def prepare_request(
6642
query_params: Dict[str, str] = {
6743
"count": "true",
6844
"offset": str(offset),
45+
"limit": str(limit),
6946
}
70-
if limit is not None:
71-
query_params["limit"] = str(limit)
7247
if sort is not None:
7348
query_params["sort"] = sort
7449

75-
return GET_OAUTH_CLIENTS.format_path_with_params(), query_params
76-
77-
@staticmethod
78-
def process_response(raw_json: Dict) -> OAuthClientListResponse:
79-
"""
80-
Process the API response into an OAuthClientListResponse object.
81-
82-
:param raw_json: raw response from the API
83-
:returns: OAuthClientListResponse with pagination info and records
84-
"""
85-
return OAuthClientListResponse(**raw_json)
50+
return GET_OAUTH_CLIENTS, query_params
8651

8752

8853
class OAuthClientGetById:

pyatlan/client/oauth_client.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
ApiCaller,
1111
OAuthClientCreate,
1212
OAuthClientGet,
13-
OAuthClientGetAll,
1413
OAuthClientGetById,
1514
OAuthClientPurge,
1615
OAuthClientUpdate,
@@ -38,36 +37,32 @@ def __init__(self, client: ApiCaller):
3837
)
3938
self._client = client
4039

41-
def get_all(self) -> OAuthClientListResponse:
42-
"""
43-
Retrieves all OAuth clients defined in Atlan.
44-
45-
:returns: an OAuthClientListResponse containing all OAuth clients
46-
:raises AtlanError: on any API communication issue
47-
"""
48-
endpoint, query_params = OAuthClientGetAll.prepare_request()
49-
raw_json = self._client._call_api(endpoint, query_params)
50-
return OAuthClientGetAll.process_response(raw_json)
51-
5240
@validate_arguments
5341
def get(
5442
self,
55-
limit: Optional[int] = None,
43+
limit: int = 20,
5644
offset: int = 0,
5745
sort: Optional[str] = None,
5846
) -> OAuthClientListResponse:
5947
"""
6048
Retrieves OAuth clients defined in Atlan with pagination support.
6149
62-
:param limit: maximum number of results to be returned
50+
:param limit: maximum number of results to be returned per page (default: 20)
6351
:param offset: starting point for results to return, for paging
6452
:param sort: property by which to sort the results (e.g., 'createdAt' for descending)
6553
:returns: an OAuthClientListResponse containing records and pagination info
6654
:raises AtlanError: on any API communication issue
6755
"""
6856
endpoint, query_params = OAuthClientGet.prepare_request(limit, offset, sort)
6957
raw_json = self._client._call_api(endpoint, query_params)
70-
return OAuthClientGet.process_response(raw_json)
58+
return OAuthClientListResponse(
59+
**raw_json,
60+
endpoint=endpoint,
61+
client=self._client,
62+
size=limit,
63+
start=offset,
64+
sort=sort,
65+
)
7166

7267
@validate_arguments
7368
def get_by_id(self, client_id: str) -> OAuthClientResponse:

pyatlan/model/aio/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .group import AsyncGroupResponse
1717
from .keycloak_events import AsyncAdminEventResponse, AsyncKeycloakEventResponse
1818
from .lineage import AsyncLineageListResults
19+
from .oauth_client import AsyncOAuthClientListResponse
1920
from .retranslators import AsyncAtlanTagRetranslator, AsyncBaseRetranslator
2021
from .search_log import AsyncSearchLogResults
2122
from .task import AsyncTaskSearchResponse
@@ -37,6 +38,8 @@
3738
"AsyncAtlanResponse",
3839
# Lineage results
3940
"AsyncLineageListResults",
41+
# OAuth client response
42+
"AsyncOAuthClientListResponse",
4043
# Search log results
4144
"AsyncSearchLogResults",
4245
# User response

pyatlan/model/aio/oauth_client.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2026 Atlan Pte. Ltd.
3+
4+
from __future__ import annotations
5+
6+
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, List, Optional
7+
8+
from pydantic.v1 import Field, PrivateAttr, ValidationError, parse_obj_as
9+
10+
from pyatlan.errors import ErrorCode
11+
from pyatlan.model.core import AtlanObject
12+
from pyatlan.model.oauth_client import OAuthClientResponse
13+
14+
if TYPE_CHECKING:
15+
from pyatlan.client.aio.client import AsyncAtlanClient
16+
from pyatlan.client.constants import API
17+
18+
19+
class AsyncOAuthClientListResponse(AtlanObject):
20+
"""Async version of OAuthClientListResponse with async pagination support."""
21+
22+
_size: int = PrivateAttr()
23+
_start: int = PrivateAttr()
24+
_endpoint: API = PrivateAttr()
25+
_client: AsyncAtlanClient = PrivateAttr()
26+
_sort: Optional[str] = PrivateAttr()
27+
28+
total_record: Optional[int] = Field(
29+
default=None, description="Total number of OAuth clients."
30+
)
31+
filter_record: Optional[int] = Field(
32+
default=None,
33+
description="Number of OAuth clients that matched the specified filters.",
34+
)
35+
records: Optional[List[OAuthClientResponse]] = Field(
36+
default=None, description="List of OAuth clients."
37+
)
38+
39+
def __init__(self, **data: Any):
40+
super().__init__(**data)
41+
self._endpoint = data.get("endpoint") # type: ignore[assignment]
42+
self._client = data.get("client") # type: ignore[assignment]
43+
self._size = data.get("size") or 20 # type: ignore[assignment]
44+
self._start = data.get("start") or 0 # type: ignore[assignment]
45+
self._sort = data.get("sort") # type: ignore[assignment]
46+
47+
def current_page(self) -> Optional[List[OAuthClientResponse]]:
48+
"""Get the current page of OAuth clients."""
49+
return self.records
50+
51+
async def next_page(
52+
self, start: Optional[int] = None, size: Optional[int] = None
53+
) -> bool:
54+
"""
55+
Retrieve the next page of results.
56+
57+
:param start: starting point for the next page
58+
:param size: page size for the next page
59+
:returns: True if there was a next page, False otherwise
60+
"""
61+
self._start = start or self._start + self._size
62+
if size:
63+
self._size = size
64+
return await self._get_next_page() if self.records else False
65+
66+
async def _get_next_page(self) -> bool:
67+
"""Fetch the next page of results."""
68+
query_params: Dict[str, str] = {
69+
"count": "true",
70+
"offset": str(self._start),
71+
"limit": str(self._size),
72+
}
73+
if self._sort is not None:
74+
query_params["sort"] = self._sort
75+
raw_json = await self._client._call_api(
76+
api=self._endpoint,
77+
query_params=query_params,
78+
)
79+
if not raw_json.get("records"):
80+
self.records = []
81+
return False
82+
try:
83+
self.records = parse_obj_as(
84+
List[OAuthClientResponse], raw_json.get("records")
85+
)
86+
except ValidationError as err:
87+
raise ErrorCode.JSON_ERROR.exception_with_parameters(
88+
raw_json, 200, str(err)
89+
) from err
90+
return True
91+
92+
async def __aiter__(self) -> AsyncGenerator[OAuthClientResponse, None]:
93+
"""Async iterator for OAuth clients across all pages."""
94+
while self.records:
95+
for oauth_client in self.records:
96+
yield oauth_client
97+
if not await self.next_page():
98+
break

0 commit comments

Comments
 (0)