Debian Codegraph @

src/auth0/management/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.http_response import AsyncHttpResponse, HttpResponse
9 from ..core.jsonable_encoder import encode_path_param
10 from ..core.pagination import AsyncPager, SyncPager
11 from ..core.parse_error import ParsingError
12 from ..core.pydantic_utilities import parse_obj_as
13 from ..core.request_options import RequestOptions
14 from ..errors.bad_request_error import BadRequestError
15 from ..errors.forbidden_error import ForbiddenError
16 from ..errors.not_found_error import NotFoundError
17 from ..errors.too_many_requests_error import TooManyRequestsError
18 from ..errors.unauthorized_error import UnauthorizedError
19 from ..types.get_log_response_content import GetLogResponseContent
20 from ..types.list_log_offset_paginated_response_content import ListLogOffsetPaginatedResponseContent
21 from ..types.log import Log
22 from pydantic import ValidationError
23
24
25 class RawLogsClient:
26 def __init__(self, *, client_wrapper: SyncClientWrapper):
27 self._client_wrapper = client_wrapper
28
29 def list(
30 self,
31 *,
32 page: typing.Optional[int] = 0,
33 per_page: typing.Optional[int] = 50,
34 sort: typing.Optional[str] = None,
35 fields: typing.Optional[str] = None,
36 include_fields: typing.Optional[bool] = None,
37 include_totals: typing.Optional[bool] = True,
38 search: typing.Optional[str] = None,
39 request_options: typing.Optional[RequestOptions] = None,
40 ) -> SyncPager[Log, ListLogOffsetPaginatedResponseContent]:
41 """
42 Retrieve log entries that match the specified search criteria (or all log entries if no criteria specified).
43
44 Set custom search criteria using the `q` parameter, or search from a specific log ID (_"search from checkpoint"_).
45
46 For more information on all possible event types, their respective acronyms, and descriptions, see [Log Event Type Codes](https://auth0.com/docs/logs/log-event-type-codes).
47
48 **To set custom search criteria, use the following parameters:**
49
50 - **q:** Search Criteria using [Query String Syntax](https://auth0.com/docs/logs/log-search-query-syntax)
51 - **page:** Page index of the results to return. First page is 0.
52 - **per_page:** Number of results per page.
53 - **sort:** Field to use for sorting appended with `:1` for ascending and `:-1` for descending. e.g. `date:-1`
54 - **fields:** Comma-separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields.
55 - **include_fields:** Whether specified fields are to be included (true) or excluded (false).
56 - **include_totals:** Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). **Deprecated:** this field is deprecated and should be removed from use. See [Search Engine V3 Breaking Changes](https://auth0.com/docs/product-lifecycle/deprecations-and-migrations/migrate-to-tenant-log-search-v3#pagination)
57
58 For more information on the list of fields that can be used in `fields` and `sort`, see [Searchable Fields](https://auth0.com/docs/logs/log-search-query-syntax#searchable-fields).
59
60 Auth0 [limits the number of logs](https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#limitations) you can return by search criteria to 100 logs per request. Furthermore, you may paginate only through 1,000 search results. If you exceed this threshold, please redefine your search or use the [get logs by checkpoint method](https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#retrieve-logs-by-checkpoint).
61
62 **To search from a checkpoint log ID, use the following parameters:**
63
64 - **from:** Log Event ID from which to start retrieving logs. You can limit the number of logs returned using the `take` parameter. If you use `from` at the same time as `q`, `from` takes precedence and `q` is ignored.
65 - **take:** Number of entries to retrieve when using the `from` parameter.
66
67 **Important:** When fetching logs from a checkpoint log ID, any parameter other than `from` and `take` will be ignored, and date ordering is not guaranteed.
68
69 Parameters
70 ----------
71 page : typing.Optional[int]
72 Page index of the results to return. First page is 0.
73
74 per_page : typing.Optional[int]
75 Number of results per page. Paging is disabled if parameter not sent. Default: <code>50</code>. Max value: <code>100</code>
76
77 sort : typing.Optional[str]
78 Field to use for sorting appended with <code>:1</code> for ascending and <code>:-1</code> for descending. e.g. <code>date:-1</code>
79
80 fields : typing.Optional[str]
81 Comma-separated list of fields to include or exclude (based on value provided for <code>include_fields</code>) in the result. Leave empty to retrieve all fields.
82
83 include_fields : typing.Optional[bool]
84 Whether specified fields are to be included (<code>true</code>) or excluded (<code>false</code>)
85
86 include_totals : typing.Optional[bool]
87 Return results as an array when false (default). Return results inside an object that also contains a total result count when true.
88
89 search : typing.Optional[str]
90 Retrieves logs that match the specified search criteria. This parameter can be combined with all the others in the /api/logs endpoint but is specified separately for clarity.
91 If no fields are provided a case insensitive 'starts with' search is performed on all of the following fields: client_name, connection, user_name. Otherwise, you can specify multiple fields and specify the search using the %field%:%search%, for example: application:node user:"[email protected]".
92 Values specified without quotes are matched using a case insensitive 'starts with' search. If quotes are used a case insensitve exact search is used. If multiple fields are used, the AND operator is used to join the clauses.
93
94 request_options : typing.Optional[RequestOptions]
95 Request-specific configuration.
96
97 Returns
98 -------
99 SyncPager[Log, ListLogOffsetPaginatedResponseContent]
100 Logs successfully retrieved.
101 """
102 page = page if page is not None else 0
103
104 _response = self._client_wrapper.httpx_client.request(
105 "logs",
106 method="GET",
107 params={
108 "page": page,
109 "per_page": per_page,
110 "sort": sort,
111 "fields": fields,
112 "include_fields": include_fields,
113 "include_totals": include_totals,
114 "search": search,
115 },
116 request_options=request_options,
117 )
118 try:
119 if 200 <= _response.status_code < 300:
120 _parsed_response = typing.cast(
121 ListLogOffsetPaginatedResponseContent,
122 parse_obj_as(
123 type_=ListLogOffsetPaginatedResponseContent, # type: ignore
124 object_=_response.json(),
125 ),
126 )
127 _items = _parsed_response.logs
128 _has_next = len(_items or []) > 0
129 _get_next = lambda: self.list(
130 page=page + 1,
131 per_page=per_page,
132 sort=sort,
133 fields=fields,
134 include_fields=include_fields,
135 include_totals=include_totals,
136 search=search,
137 request_options=request_options,
138 )
139 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
140 if _response.status_code == 400:
141 raise BadRequestError(
142 headers=dict(_response.headers),
143 body=typing.cast(
144 typing.Any,
145 parse_obj_as(
146 type_=typing.Any, # type: ignore
147 object_=_response.json(),
148 ),
149 ),
150 )
151 if _response.status_code == 401:
152 raise UnauthorizedError(
153 headers=dict(_response.headers),
154 body=typing.cast(
155 typing.Any,
156 parse_obj_as(
157 type_=typing.Any, # type: ignore
158 object_=_response.json(),
159 ),
160 ),
161 )
162 if _response.status_code == 403:
163 raise ForbiddenError(
164 headers=dict(_response.headers),
165 body=typing.cast(
166 typing.Any,
167 parse_obj_as(
168 type_=typing.Any, # type: ignore
169 object_=_response.json(),
170 ),
171 ),
172 )
173 if _response.status_code == 429:
174 raise TooManyRequestsError(
175 headers=dict(_response.headers),
176 body=typing.cast(
177 typing.Any,
178 parse_obj_as(
179 type_=typing.Any, # type: ignore
180 object_=_response.json(),
181 ),
182 ),
183 )
184 _response_json = _response.json()
185 except JSONDecodeError:
186 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
187 except ValidationError as e:
188 raise ParsingError(
189 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
190 )
191 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
192
193 def get(
194 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
195 ) -> HttpResponse[GetLogResponseContent]:
196 """
197 Retrieve an individual log event.
198
199 Parameters
200 ----------
201 id : str
202 log_id of the log to retrieve.
203
204 request_options : typing.Optional[RequestOptions]
205 Request-specific configuration.
206
207 Returns
208 -------
209 HttpResponse[GetLogResponseContent]
210 Log successfully retrieved.
211 """
212 _response = self._client_wrapper.httpx_client.request(
213 f"logs/{encode_path_param(id)}",
214 method="GET",
215 request_options=request_options,
216 )
217 try:
218 if 200 <= _response.status_code < 300:
219 _data = typing.cast(
220 GetLogResponseContent,
221 parse_obj_as(
222 type_=GetLogResponseContent, # type: ignore
223 object_=_response.json(),
224 ),
225 )
226 return HttpResponse(response=_response, data=_data)
227 if _response.status_code == 400:
228 raise BadRequestError(
229 headers=dict(_response.headers),
230 body=typing.cast(
231 typing.Any,
232 parse_obj_as(
233 type_=typing.Any, # type: ignore
234 object_=_response.json(),
235 ),
236 ),
237 )
238 if _response.status_code == 401:
239 raise UnauthorizedError(
240 headers=dict(_response.headers),
241 body=typing.cast(
242 typing.Any,
243 parse_obj_as(
244 type_=typing.Any, # type: ignore
245 object_=_response.json(),
246 ),
247 ),
248 )
249 if _response.status_code == 403:
250 raise ForbiddenError(
251 headers=dict(_response.headers),
252 body=typing.cast(
253 typing.Any,
254 parse_obj_as(
255 type_=typing.Any, # type: ignore
256 object_=_response.json(),
257 ),
258 ),
259 )
260 if _response.status_code == 404:
261 raise NotFoundError(
262 headers=dict(_response.headers),
263 body=typing.cast(
264 typing.Any,
265 parse_obj_as(
266 type_=typing.Any, # type: ignore
267 object_=_response.json(),
268 ),
269 ),
270 )
271 if _response.status_code == 429:
272 raise TooManyRequestsError(
273 headers=dict(_response.headers),
274 body=typing.cast(
275 typing.Any,
276 parse_obj_as(
277 type_=typing.Any, # type: ignore
278 object_=_response.json(),
279 ),
280 ),
281 )
282 _response_json = _response.json()
283 except JSONDecodeError:
284 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
285 except ValidationError as e:
286 raise ParsingError(
287 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
288 )
289 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
290
291
292 class AsyncRawLogsClient:
293 def __init__(self, *, client_wrapper: AsyncClientWrapper):
294 self._client_wrapper = client_wrapper
295
296 async def list(
297 self,
298 *,
299 page: typing.Optional[int] = 0,
300 per_page: typing.Optional[int] = 50,
301 sort: typing.Optional[str] = None,
302 fields: typing.Optional[str] = None,
303 include_fields: typing.Optional[bool] = None,
304 include_totals: typing.Optional[bool] = True,
305 search: typing.Optional[str] = None,
306 request_options: typing.Optional[RequestOptions] = None,
307 ) -> AsyncPager[Log, ListLogOffsetPaginatedResponseContent]:
308 """
309 Retrieve log entries that match the specified search criteria (or all log entries if no criteria specified).
310
311 Set custom search criteria using the `q` parameter, or search from a specific log ID (_"search from checkpoint"_).
312
313 For more information on all possible event types, their respective acronyms, and descriptions, see [Log Event Type Codes](https://auth0.com/docs/logs/log-event-type-codes).
314
315 **To set custom search criteria, use the following parameters:**
316
317 - **q:** Search Criteria using [Query String Syntax](https://auth0.com/docs/logs/log-search-query-syntax)
318 - **page:** Page index of the results to return. First page is 0.
319 - **per_page:** Number of results per page.
320 - **sort:** Field to use for sorting appended with `:1` for ascending and `:-1` for descending. e.g. `date:-1`
321 - **fields:** Comma-separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields.
322 - **include_fields:** Whether specified fields are to be included (true) or excluded (false).
323 - **include_totals:** Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). **Deprecated:** this field is deprecated and should be removed from use. See [Search Engine V3 Breaking Changes](https://auth0.com/docs/product-lifecycle/deprecations-and-migrations/migrate-to-tenant-log-search-v3#pagination)
324
325 For more information on the list of fields that can be used in `fields` and `sort`, see [Searchable Fields](https://auth0.com/docs/logs/log-search-query-syntax#searchable-fields).
326
327 Auth0 [limits the number of logs](https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#limitations) you can return by search criteria to 100 logs per request. Furthermore, you may paginate only through 1,000 search results. If you exceed this threshold, please redefine your search or use the [get logs by checkpoint method](https://auth0.com/docs/logs/retrieve-log-events-using-mgmt-api#retrieve-logs-by-checkpoint).
328
329 **To search from a checkpoint log ID, use the following parameters:**
330
331 - **from:** Log Event ID from which to start retrieving logs. You can limit the number of logs returned using the `take` parameter. If you use `from` at the same time as `q`, `from` takes precedence and `q` is ignored.
332 - **take:** Number of entries to retrieve when using the `from` parameter.
333
334 **Important:** When fetching logs from a checkpoint log ID, any parameter other than `from` and `take` will be ignored, and date ordering is not guaranteed.
335
336 Parameters
337 ----------
338 page : typing.Optional[int]
339 Page index of the results to return. First page is 0.
340
341 per_page : typing.Optional[int]
342 Number of results per page. Paging is disabled if parameter not sent. Default: <code>50</code>. Max value: <code>100</code>
343
344 sort : typing.Optional[str]
345 Field to use for sorting appended with <code>:1</code> for ascending and <code>:-1</code> for descending. e.g. <code>date:-1</code>
346
347 fields : typing.Optional[str]
348 Comma-separated list of fields to include or exclude (based on value provided for <code>include_fields</code>) in the result. Leave empty to retrieve all fields.
349
350 include_fields : typing.Optional[bool]
351 Whether specified fields are to be included (<code>true</code>) or excluded (<code>false</code>)
352
353 include_totals : typing.Optional[bool]
354 Return results as an array when false (default). Return results inside an object that also contains a total result count when true.
355
356 search : typing.Optional[str]
357 Retrieves logs that match the specified search criteria. This parameter can be combined with all the others in the /api/logs endpoint but is specified separately for clarity.
358 If no fields are provided a case insensitive 'starts with' search is performed on all of the following fields: client_name, connection, user_name. Otherwise, you can specify multiple fields and specify the search using the %field%:%search%, for example: application:node user:"[email protected]".
359 Values specified without quotes are matched using a case insensitive 'starts with' search. If quotes are used a case insensitve exact search is used. If multiple fields are used, the AND operator is used to join the clauses.
360
361 request_options : typing.Optional[RequestOptions]
362 Request-specific configuration.
363
364 Returns
365 -------
366 AsyncPager[Log, ListLogOffsetPaginatedResponseContent]
367 Logs successfully retrieved.
368 """
369 page = page if page is not None else 0
370
371 _response = await self._client_wrapper.httpx_client.request(
372 "logs",
373 method="GET",
374 params={
375 "page": page,
376 "per_page": per_page,
377 "sort": sort,
378 "fields": fields,
379 "include_fields": include_fields,
380 "include_totals": include_totals,
381 "search": search,
382 },
383 request_options=request_options,
384 )
385 try:
386 if 200 <= _response.status_code < 300:
387 _parsed_response = typing.cast(
388 ListLogOffsetPaginatedResponseContent,
389 parse_obj_as(
390 type_=ListLogOffsetPaginatedResponseContent, # type: ignore
391 object_=_response.json(),
392 ),
393 )
394 _items = _parsed_response.logs
395 _has_next = len(_items or []) > 0
396
397 async def _get_next():
398 return await self.list(
399 page=page + 1,
400 per_page=per_page,
401 sort=sort,
402 fields=fields,
403 include_fields=include_fields,
404 include_totals=include_totals,
405 search=search,
406 request_options=request_options,
407 )
408
409 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
410 if _response.status_code == 400:
411 raise BadRequestError(
412 headers=dict(_response.headers),
413 body=typing.cast(
414 typing.Any,
415 parse_obj_as(
416 type_=typing.Any, # type: ignore
417 object_=_response.json(),
418 ),
419 ),
420 )
421 if _response.status_code == 401:
422 raise UnauthorizedError(
423 headers=dict(_response.headers),
424 body=typing.cast(
425 typing.Any,
426 parse_obj_as(
427 type_=typing.Any, # type: ignore
428 object_=_response.json(),
429 ),
430 ),
431 )
432 if _response.status_code == 403:
433 raise ForbiddenError(
434 headers=dict(_response.headers),
435 body=typing.cast(
436 typing.Any,
437 parse_obj_as(
438 type_=typing.Any, # type: ignore
439 object_=_response.json(),
440 ),
441 ),
442 )
443 if _response.status_code == 429:
444 raise TooManyRequestsError(
445 headers=dict(_response.headers),
446 body=typing.cast(
447 typing.Any,
448 parse_obj_as(
449 type_=typing.Any, # type: ignore
450 object_=_response.json(),
451 ),
452 ),
453 )
454 _response_json = _response.json()
455 except JSONDecodeError:
456 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
457 except ValidationError as e:
458 raise ParsingError(
459 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
460 )
461 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
462
463 async def get(
464 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
465 ) -> AsyncHttpResponse[GetLogResponseContent]:
466 """
467 Retrieve an individual log event.
468
469 Parameters
470 ----------
471 id : str
472 log_id of the log to retrieve.
473
474 request_options : typing.Optional[RequestOptions]
475 Request-specific configuration.
476
477 Returns
478 -------
479 AsyncHttpResponse[GetLogResponseContent]
480 Log successfully retrieved.
481 """
482 _response = await self._client_wrapper.httpx_client.request(
483 f"logs/{encode_path_param(id)}",
484 method="GET",
485 request_options=request_options,
486 )
487 try:
488 if 200 <= _response.status_code < 300:
489 _data = typing.cast(
490 GetLogResponseContent,
491 parse_obj_as(
492 type_=GetLogResponseContent, # type: ignore
493 object_=_response.json(),
494 ),
495 )
496 return AsyncHttpResponse(response=_response, data=_data)
497 if _response.status_code == 400:
498 raise BadRequestError(
499 headers=dict(_response.headers),
500 body=typing.cast(
501 typing.Any,
502 parse_obj_as(
503 type_=typing.Any, # type: ignore
504 object_=_response.json(),
505 ),
506 ),
507 )
508 if _response.status_code == 401:
509 raise UnauthorizedError(
510 headers=dict(_response.headers),
511 body=typing.cast(
512 typing.Any,
513 parse_obj_as(
514 type_=typing.Any, # type: ignore
515 object_=_response.json(),
516 ),
517 ),
518 )
519 if _response.status_code == 403:
520 raise ForbiddenError(
521 headers=dict(_response.headers),
522 body=typing.cast(
523 typing.Any,
524 parse_obj_as(
525 type_=typing.Any, # type: ignore
526 object_=_response.json(),
527 ),
528 ),
529 )
530 if _response.status_code == 404:
531 raise NotFoundError(
532 headers=dict(_response.headers),
533 body=typing.cast(
534 typing.Any,
535 parse_obj_as(
536 type_=typing.Any, # type: ignore
537 object_=_response.json(),
538 ),
539 ),
540 )
541 if _response.status_code == 429:
542 raise TooManyRequestsError(
543 headers=dict(_response.headers),
544 body=typing.cast(
545 typing.Any,
546 parse_obj_as(
547 type_=typing.Any, # type: ignore
548 object_=_response.json(),
549 ),
550 ),
551 )
552 _response_json = _response.json()
553 except JSONDecodeError:
554 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
555 except ValidationError as e:
556 raise ParsingError(
557 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
558 )
559 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)