| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 6 |
from ..core.pagination import AsyncPager, SyncPager |
| 7 |
from ..core.request_options import RequestOptions |
| 8 |
from ..types.get_log_response_content import GetLogResponseContent |
| 9 |
from ..types.list_log_offset_paginated_response_content import ListLogOffsetPaginatedResponseContent |
| 10 |
from ..types.log import Log |
| 11 |
from .raw_client import AsyncRawLogsClient, RawLogsClient |
| 12 |
|
| 13 |
|
| 14 |
class LogsClient: |
| 15 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 16 |
self._raw_client = RawLogsClient(client_wrapper=client_wrapper) |
| 17 |
|
| 18 |
@property |
| 19 |
def with_raw_response(self) -> RawLogsClient: |
| 20 |
""" |
| 21 |
Retrieves a raw implementation of this client that returns raw responses. |
| 22 |
|
| 23 |
Returns |
| 24 |
------- |
| 25 |
RawLogsClient |
| 26 |
""" |
| 27 |
return self._raw_client |
| 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 |
Examples |
| 103 |
-------- |
| 104 |
from auth0 import Auth0 |
| 105 |
|
| 106 |
client = Auth0( |
| 107 |
token="YOUR_TOKEN", |
| 108 |
) |
| 109 |
response = client.logs.list( |
| 110 |
page=1, |
| 111 |
per_page=1, |
| 112 |
sort="sort", |
| 113 |
fields="fields", |
| 114 |
include_fields=True, |
| 115 |
include_totals=True, |
| 116 |
search="search", |
| 117 |
) |
| 118 |
for item in response: |
| 119 |
yield item |
| 120 |
# alternatively, you can paginate page-by-page |
| 121 |
for page in response.iter_pages(): |
| 122 |
yield page |
| 123 |
""" |
| 124 |
return self._raw_client.list( |
| 125 |
page=page, |
| 126 |
per_page=per_page, |
| 127 |
sort=sort, |
| 128 |
fields=fields, |
| 129 |
include_fields=include_fields, |
| 130 |
include_totals=include_totals, |
| 131 |
search=search, |
| 132 |
request_options=request_options, |
| 133 |
) |
| 134 |
|
| 135 |
def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetLogResponseContent: |
| 136 |
""" |
| 137 |
Retrieve an individual log event. |
| 138 |
|
| 139 |
Parameters |
| 140 |
---------- |
| 141 |
id : str |
| 142 |
log_id of the log to retrieve. |
| 143 |
|
| 144 |
request_options : typing.Optional[RequestOptions] |
| 145 |
Request-specific configuration. |
| 146 |
|
| 147 |
Returns |
| 148 |
------- |
| 149 |
GetLogResponseContent |
| 150 |
Log successfully retrieved. |
| 151 |
|
| 152 |
Examples |
| 153 |
-------- |
| 154 |
from auth0 import Auth0 |
| 155 |
|
| 156 |
client = Auth0( |
| 157 |
token="YOUR_TOKEN", |
| 158 |
) |
| 159 |
client.logs.get( |
| 160 |
id="id", |
| 161 |
) |
| 162 |
""" |
| 163 |
_response = self._raw_client.get(id, request_options=request_options) |
| 164 |
return _response.data |
| 165 |
|
| 166 |
|
| 167 |
class AsyncLogsClient: |
| 168 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 169 |
self._raw_client = AsyncRawLogsClient(client_wrapper=client_wrapper) |
| 170 |
|
| 171 |
@property |
| 172 |
def with_raw_response(self) -> AsyncRawLogsClient: |
| 173 |
""" |
| 174 |
Retrieves a raw implementation of this client that returns raw responses. |
| 175 |
|
| 176 |
Returns |
| 177 |
------- |
| 178 |
AsyncRawLogsClient |
| 179 |
""" |
| 180 |
return self._raw_client |
| 181 |
|
| 182 |
async def list( |
| 183 |
self, |
| 184 |
*, |
| 185 |
page: typing.Optional[int] = 0, |
| 186 |
per_page: typing.Optional[int] = 50, |
| 187 |
sort: typing.Optional[str] = None, |
| 188 |
fields: typing.Optional[str] = None, |
| 189 |
include_fields: typing.Optional[bool] = None, |
| 190 |
include_totals: typing.Optional[bool] = True, |
| 191 |
search: typing.Optional[str] = None, |
| 192 |
request_options: typing.Optional[RequestOptions] = None, |
| 193 |
) -> AsyncPager[Log, ListLogOffsetPaginatedResponseContent]: |
| 194 |
""" |
| 195 |
Retrieve log entries that match the specified search criteria (or all log entries if no criteria specified). |
| 196 |
|
| 197 |
Set custom search criteria using the `q` parameter, or search from a specific log ID (_"search from checkpoint"_). |
| 198 |
|
| 199 |
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). |
| 200 |
|
| 201 |
**To set custom search criteria, use the following parameters:** |
| 202 |
|
| 203 |
- **q:** Search Criteria using [Query String Syntax](https://auth0.com/docs/logs/log-search-query-syntax) |
| 204 |
- **page:** Page index of the results to return. First page is 0. |
| 205 |
- **per_page:** Number of results per page. |
| 206 |
- **sort:** Field to use for sorting appended with `:1` for ascending and `:-1` for descending. e.g. `date:-1` |
| 207 |
- **fields:** Comma-separated list of fields to include or exclude (depending on include_fields) from the result, empty to retrieve all fields. |
| 208 |
- **include_fields:** Whether specified fields are to be included (true) or excluded (false). |
| 209 |
- **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) |
| 210 |
|
| 211 |
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). |
| 212 |
|
| 213 |
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). |
| 214 |
|
| 215 |
**To search from a checkpoint log ID, use the following parameters:** |
| 216 |
|
| 217 |
- **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. |
| 218 |
- **take:** Number of entries to retrieve when using the `from` parameter. |
| 219 |
|
| 220 |
**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. |
| 221 |
|
| 222 |
Parameters |
| 223 |
---------- |
| 224 |
page : typing.Optional[int] |
| 225 |
Page index of the results to return. First page is 0. |
| 226 |
|
| 227 |
per_page : typing.Optional[int] |
| 228 |
Number of results per page. Paging is disabled if parameter not sent. Default: <code>50</code>. Max value: <code>100</code> |
| 229 |
|
| 230 |
sort : typing.Optional[str] |
| 231 |
Field to use for sorting appended with <code>:1</code> for ascending and <code>:-1</code> for descending. e.g. <code>date:-1</code> |
| 232 |
|
| 233 |
fields : typing.Optional[str] |
| 234 |
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. |
| 235 |
|
| 236 |
include_fields : typing.Optional[bool] |
| 237 |
Whether specified fields are to be included (<code>true</code>) or excluded (<code>false</code>) |
| 238 |
|
| 239 |
include_totals : typing.Optional[bool] |
| 240 |
Return results as an array when false (default). Return results inside an object that also contains a total result count when true. |
| 241 |
|
| 242 |
search : typing.Optional[str] |
| 243 |
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. |
| 244 |
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]". |
| 245 |
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. |
| 246 |
|
| 247 |
request_options : typing.Optional[RequestOptions] |
| 248 |
Request-specific configuration. |
| 249 |
|
| 250 |
Returns |
| 251 |
------- |
| 252 |
AsyncPager[Log, ListLogOffsetPaginatedResponseContent] |
| 253 |
Logs successfully retrieved. |
| 254 |
|
| 255 |
Examples |
| 256 |
-------- |
| 257 |
import asyncio |
| 258 |
|
| 259 |
from auth0 import AsyncAuth0 |
| 260 |
|
| 261 |
client = AsyncAuth0( |
| 262 |
token="YOUR_TOKEN", |
| 263 |
) |
| 264 |
|
| 265 |
|
| 266 |
async def main() -> None: |
| 267 |
response = await client.logs.list( |
| 268 |
page=1, |
| 269 |
per_page=1, |
| 270 |
sort="sort", |
| 271 |
fields="fields", |
| 272 |
include_fields=True, |
| 273 |
include_totals=True, |
| 274 |
search="search", |
| 275 |
) |
| 276 |
async for item in response: |
| 277 |
yield item |
| 278 |
|
| 279 |
# alternatively, you can paginate page-by-page |
| 280 |
async for page in response.iter_pages(): |
| 281 |
yield page |
| 282 |
|
| 283 |
|
| 284 |
asyncio.run(main()) |
| 285 |
""" |
| 286 |
return await self._raw_client.list( |
| 287 |
page=page, |
| 288 |
per_page=per_page, |
| 289 |
sort=sort, |
| 290 |
fields=fields, |
| 291 |
include_fields=include_fields, |
| 292 |
include_totals=include_totals, |
| 293 |
search=search, |
| 294 |
request_options=request_options, |
| 295 |
) |
| 296 |
|
| 297 |
async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetLogResponseContent: |
| 298 |
""" |
| 299 |
Retrieve an individual log event. |
| 300 |
|
| 301 |
Parameters |
| 302 |
---------- |
| 303 |
id : str |
| 304 |
log_id of the log to retrieve. |
| 305 |
|
| 306 |
request_options : typing.Optional[RequestOptions] |
| 307 |
Request-specific configuration. |
| 308 |
|
| 309 |
Returns |
| 310 |
------- |
| 311 |
GetLogResponseContent |
| 312 |
Log successfully retrieved. |
| 313 |
|
| 314 |
Examples |
| 315 |
-------- |
| 316 |
import asyncio |
| 317 |
|
| 318 |
from auth0 import AsyncAuth0 |
| 319 |
|
| 320 |
client = AsyncAuth0( |
| 321 |
token="YOUR_TOKEN", |
| 322 |
) |
| 323 |
|
| 324 |
|
| 325 |
async def main() -> None: |
| 326 |
await client.logs.get( |
| 327 |
id="id", |
| 328 |
) |
| 329 |
|
| 330 |
|
| 331 |
asyncio.run(main()) |
| 332 |
""" |
| 333 |
_response = await self._raw_client.get(id, request_options=request_options) |
| 334 |
return _response.data |