Debian Codegraph @

src/auth0/management/users/logs/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ...core.api_error import ApiError
7 from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ...core.jsonable_encoder import encode_path_param
9 from ...core.pagination import AsyncPager, SyncPager
10 from ...core.parse_error import ParsingError
11 from ...core.pydantic_utilities import parse_obj_as
12 from ...core.request_options import RequestOptions
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.too_many_requests_error import TooManyRequestsError
16 from ...errors.unauthorized_error import UnauthorizedError
17 from ...types.log import Log
18 from ...types.user_list_log_offset_paginated_response_content import UserListLogOffsetPaginatedResponseContent
19 from pydantic import ValidationError
20
21
22 class RawLogsClient:
23 def __init__(self, *, client_wrapper: SyncClientWrapper):
24 self._client_wrapper = client_wrapper
25
26 def list(
27 self,
28 id: str,
29 *,
30 page: typing.Optional[int] = 0,
31 per_page: typing.Optional[int] = 50,
32 sort: typing.Optional[str] = None,
33 include_totals: typing.Optional[bool] = True,
34 request_options: typing.Optional[RequestOptions] = None,
35 ) -> SyncPager[Log, UserListLogOffsetPaginatedResponseContent]:
36 """
37 Retrieve log events for a specific user.
38
39 Note: For more information on all possible event types, their respective acronyms and descriptions, see <a href="https://auth0.com/docs/logs/log-event-type-codes">Log Event Type Codes</a>.
40
41 For more information on the list of fields that can be used in `sort`, see <a href="https://auth0.com/docs/logs/log-search-query-syntax#searchable-fields">Searchable Fields</a>.
42
43 Auth0 <a href="https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#limitations">limits the number of logs</a> you can return by search criteria to 100 logs per request. Furthermore, you may only paginate through up to 1,000 search results. If you exceed this threshold, please redefine your search.
44
45 Parameters
46 ----------
47 id : str
48 ID of the user of the logs to retrieve
49
50 page : typing.Optional[int]
51 Page index of the results to return. First page is 0.
52
53 per_page : typing.Optional[int]
54 Number of results per page. Paging is disabled if parameter not sent.
55
56 sort : typing.Optional[str]
57 Field to sort by. Use `fieldname:1` for ascending order and `fieldname:-1` for descending.
58
59 include_totals : typing.Optional[bool]
60 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
61
62 request_options : typing.Optional[RequestOptions]
63 Request-specific configuration.
64
65 Returns
66 -------
67 SyncPager[Log, UserListLogOffsetPaginatedResponseContent]
68 Logs successfully retrieved.
69 """
70 page = page if page is not None else 0
71
72 _response = self._client_wrapper.httpx_client.request(
73 f"users/{encode_path_param(id)}/logs",
74 method="GET",
75 params={
76 "page": page,
77 "per_page": per_page,
78 "sort": sort,
79 "include_totals": include_totals,
80 },
81 request_options=request_options,
82 )
83 try:
84 if 200 <= _response.status_code < 300:
85 _parsed_response = typing.cast(
86 UserListLogOffsetPaginatedResponseContent,
87 parse_obj_as(
88 type_=UserListLogOffsetPaginatedResponseContent, # type: ignore
89 object_=_response.json(),
90 ),
91 )
92 _items = _parsed_response.logs
93 _has_next = len(_items or []) > 0
94 _get_next = lambda: self.list(
95 id,
96 page=page + 1,
97 per_page=per_page,
98 sort=sort,
99 include_totals=include_totals,
100 request_options=request_options,
101 )
102 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
103 if _response.status_code == 400:
104 raise BadRequestError(
105 headers=dict(_response.headers),
106 body=typing.cast(
107 typing.Any,
108 parse_obj_as(
109 type_=typing.Any, # type: ignore
110 object_=_response.json(),
111 ),
112 ),
113 )
114 if _response.status_code == 401:
115 raise UnauthorizedError(
116 headers=dict(_response.headers),
117 body=typing.cast(
118 typing.Any,
119 parse_obj_as(
120 type_=typing.Any, # type: ignore
121 object_=_response.json(),
122 ),
123 ),
124 )
125 if _response.status_code == 403:
126 raise ForbiddenError(
127 headers=dict(_response.headers),
128 body=typing.cast(
129 typing.Any,
130 parse_obj_as(
131 type_=typing.Any, # type: ignore
132 object_=_response.json(),
133 ),
134 ),
135 )
136 if _response.status_code == 429:
137 raise TooManyRequestsError(
138 headers=dict(_response.headers),
139 body=typing.cast(
140 typing.Any,
141 parse_obj_as(
142 type_=typing.Any, # type: ignore
143 object_=_response.json(),
144 ),
145 ),
146 )
147 _response_json = _response.json()
148 except JSONDecodeError:
149 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
150 except ValidationError as e:
151 raise ParsingError(
152 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
153 )
154 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
155
156
157 class AsyncRawLogsClient:
158 def __init__(self, *, client_wrapper: AsyncClientWrapper):
159 self._client_wrapper = client_wrapper
160
161 async def list(
162 self,
163 id: str,
164 *,
165 page: typing.Optional[int] = 0,
166 per_page: typing.Optional[int] = 50,
167 sort: typing.Optional[str] = None,
168 include_totals: typing.Optional[bool] = True,
169 request_options: typing.Optional[RequestOptions] = None,
170 ) -> AsyncPager[Log, UserListLogOffsetPaginatedResponseContent]:
171 """
172 Retrieve log events for a specific user.
173
174 Note: For more information on all possible event types, their respective acronyms and descriptions, see <a href="https://auth0.com/docs/logs/log-event-type-codes">Log Event Type Codes</a>.
175
176 For more information on the list of fields that can be used in `sort`, see <a href="https://auth0.com/docs/logs/log-search-query-syntax#searchable-fields">Searchable Fields</a>.
177
178 Auth0 <a href="https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#limitations">limits the number of logs</a> you can return by search criteria to 100 logs per request. Furthermore, you may only paginate through up to 1,000 search results. If you exceed this threshold, please redefine your search.
179
180 Parameters
181 ----------
182 id : str
183 ID of the user of the logs to retrieve
184
185 page : typing.Optional[int]
186 Page index of the results to return. First page is 0.
187
188 per_page : typing.Optional[int]
189 Number of results per page. Paging is disabled if parameter not sent.
190
191 sort : typing.Optional[str]
192 Field to sort by. Use `fieldname:1` for ascending order and `fieldname:-1` for descending.
193
194 include_totals : typing.Optional[bool]
195 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
196
197 request_options : typing.Optional[RequestOptions]
198 Request-specific configuration.
199
200 Returns
201 -------
202 AsyncPager[Log, UserListLogOffsetPaginatedResponseContent]
203 Logs successfully retrieved.
204 """
205 page = page if page is not None else 0
206
207 _response = await self._client_wrapper.httpx_client.request(
208 f"users/{encode_path_param(id)}/logs",
209 method="GET",
210 params={
211 "page": page,
212 "per_page": per_page,
213 "sort": sort,
214 "include_totals": include_totals,
215 },
216 request_options=request_options,
217 )
218 try:
219 if 200 <= _response.status_code < 300:
220 _parsed_response = typing.cast(
221 UserListLogOffsetPaginatedResponseContent,
222 parse_obj_as(
223 type_=UserListLogOffsetPaginatedResponseContent, # type: ignore
224 object_=_response.json(),
225 ),
226 )
227 _items = _parsed_response.logs
228 _has_next = len(_items or []) > 0
229
230 async def _get_next():
231 return await self.list(
232 id,
233 page=page + 1,
234 per_page=per_page,
235 sort=sort,
236 include_totals=include_totals,
237 request_options=request_options,
238 )
239
240 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
241 if _response.status_code == 400:
242 raise BadRequestError(
243 headers=dict(_response.headers),
244 body=typing.cast(
245 typing.Any,
246 parse_obj_as(
247 type_=typing.Any, # type: ignore
248 object_=_response.json(),
249 ),
250 ),
251 )
252 if _response.status_code == 401:
253 raise UnauthorizedError(
254 headers=dict(_response.headers),
255 body=typing.cast(
256 typing.Any,
257 parse_obj_as(
258 type_=typing.Any, # type: ignore
259 object_=_response.json(),
260 ),
261 ),
262 )
263 if _response.status_code == 403:
264 raise ForbiddenError(
265 headers=dict(_response.headers),
266 body=typing.cast(
267 typing.Any,
268 parse_obj_as(
269 type_=typing.Any, # type: ignore
270 object_=_response.json(),
271 ),
272 ),
273 )
274 if _response.status_code == 429:
275 raise TooManyRequestsError(
276 headers=dict(_response.headers),
277 body=typing.cast(
278 typing.Any,
279 parse_obj_as(
280 type_=typing.Any, # type: ignore
281 object_=_response.json(),
282 ),
283 ),
284 )
285 _response_json = _response.json()
286 except JSONDecodeError:
287 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
288 except ValidationError as e:
289 raise ParsingError(
290 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
291 )
292 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)