|
3 | 3 | # Copyright 2019-Present Datadog, Inc.
|
4 | 4 | from __future__ import annotations
|
5 | 5 |
|
| 6 | +import collections |
6 | 7 | from typing import Any, Dict, Union
|
7 | 8 |
|
8 | 9 | from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
|
9 | 10 | from datadog_api_client.configuration import Configuration
|
10 | 11 | from datadog_api_client.model_utils import (
|
| 12 | + set_attribute_from_path, |
| 13 | + get_attribute_from_path, |
11 | 14 | UnsetType,
|
12 | 15 | unset,
|
13 | 16 | )
|
|
16 | 19 | from datadog_api_client.v2.model.user_invitation_response import UserInvitationResponse
|
17 | 20 | from datadog_api_client.v2.model.users_response import UsersResponse
|
18 | 21 | from datadog_api_client.v2.model.query_sort_order import QuerySortOrder
|
| 22 | +from datadog_api_client.v2.model.user import User |
19 | 23 | from datadog_api_client.v2.model.user_response import UserResponse
|
20 | 24 | from datadog_api_client.v2.model.user_create_request import UserCreateRequest
|
21 | 25 | from datadog_api_client.v2.model.user_update_request import UserUpdateRequest
|
@@ -419,6 +423,72 @@ def list_users(
|
419 | 423 |
|
420 | 424 | return self._list_users_endpoint.call_with_http_info(**kwargs)
|
421 | 425 |
|
| 426 | + def list_users_with_pagination( |
| 427 | + self, |
| 428 | + *, |
| 429 | + page_size: Union[int, UnsetType] = unset, |
| 430 | + page_number: Union[int, UnsetType] = unset, |
| 431 | + sort: Union[str, UnsetType] = unset, |
| 432 | + sort_dir: Union[QuerySortOrder, UnsetType] = unset, |
| 433 | + filter: Union[str, UnsetType] = unset, |
| 434 | + filter_status: Union[str, UnsetType] = unset, |
| 435 | + ) -> collections.abc.Iterable[User]: |
| 436 | + """List all users. |
| 437 | +
|
| 438 | + Provide a paginated version of :meth:`list_users`, returning all items. |
| 439 | +
|
| 440 | + :param page_size: Size for a given page. The maximum allowed value is 100. |
| 441 | + :type page_size: int, optional |
| 442 | + :param page_number: Specific page number to return. |
| 443 | + :type page_number: int, optional |
| 444 | + :param sort: User attribute to order results by. Sort order is ascending by default. |
| 445 | + Sort order is descending if the field |
| 446 | + is prefixed by a negative sign, for example ``sort=-name``. Options: ``name`` , |
| 447 | + ``modified_at`` , ``user_count``. |
| 448 | + :type sort: str, optional |
| 449 | + :param sort_dir: Direction of sort. Options: ``asc`` , ``desc``. |
| 450 | + :type sort_dir: QuerySortOrder, optional |
| 451 | + :param filter: Filter all users by the given string. Defaults to no filtering. |
| 452 | + :type filter: str, optional |
| 453 | + :param filter_status: Filter on status attribute. |
| 454 | + Comma separated list, with possible values ``Active`` , ``Pending`` , and ``Disabled``. |
| 455 | + Defaults to no filtering. |
| 456 | + :type filter_status: str, optional |
| 457 | +
|
| 458 | + :return: A generator of paginated results. |
| 459 | + :rtype: collections.abc.Iterable[User] |
| 460 | + """ |
| 461 | + kwargs: Dict[str, Any] = {} |
| 462 | + if page_size is not unset: |
| 463 | + kwargs["page_size"] = page_size |
| 464 | + |
| 465 | + if page_number is not unset: |
| 466 | + kwargs["page_number"] = page_number |
| 467 | + |
| 468 | + if sort is not unset: |
| 469 | + kwargs["sort"] = sort |
| 470 | + |
| 471 | + if sort_dir is not unset: |
| 472 | + kwargs["sort_dir"] = sort_dir |
| 473 | + |
| 474 | + if filter is not unset: |
| 475 | + kwargs["filter"] = filter |
| 476 | + |
| 477 | + if filter_status is not unset: |
| 478 | + kwargs["filter_status"] = filter_status |
| 479 | + |
| 480 | + local_page_size = get_attribute_from_path(kwargs, "page_size", 10) |
| 481 | + endpoint = self._list_users_endpoint |
| 482 | + set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map) |
| 483 | + pagination = { |
| 484 | + "limit_value": local_page_size, |
| 485 | + "results_path": "data", |
| 486 | + "page_param": "page_number", |
| 487 | + "endpoint": endpoint, |
| 488 | + "kwargs": kwargs, |
| 489 | + } |
| 490 | + return endpoint.call_with_http_info_paginated(pagination) |
| 491 | + |
422 | 492 | def send_invitations(
|
423 | 493 | self,
|
424 | 494 | body: UserInvitationsRequest,
|
|
0 commit comments