|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# MIT License |
| 5 | +# |
| 6 | +# Copyright (c) 2022 KuFlow |
| 7 | +# |
| 8 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | +# of this software and associated documentation files (the "Software"), to deal |
| 10 | +# in the Software without restriction, including without limitation the rights |
| 11 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | +# copies of the Software, and to permit persons to whom the Software is |
| 13 | +# furnished to do so, subject to the following conditions: |
| 14 | +# |
| 15 | +# The above copyright notice and this permission notice shall be included in all |
| 16 | +# copies or substantial portions of the Software. |
| 17 | +# |
| 18 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | +# SOFTWARE. |
| 25 | +# |
| 26 | +# -------------------------------------------------------------------------- |
| 27 | +# |
| 28 | +# Code generated by Microsoft (R) AutoRest Code Generator. |
| 29 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 30 | +# |
| 31 | +# -------------------------------------------------------------------------- |
| 32 | +import sys |
| 33 | +from typing import Any, Callable, Dict, List, Optional, TypeVar |
| 34 | + |
| 35 | +from azure.core import AsyncPipelineClient |
| 36 | +from azure.core.exceptions import ( |
| 37 | + ClientAuthenticationError, |
| 38 | + HttpResponseError, |
| 39 | + ResourceExistsError, |
| 40 | + ResourceNotFoundError, |
| 41 | + ResourceNotModifiedError, |
| 42 | + map_error, |
| 43 | +) |
| 44 | +from azure.core.pipeline import PipelineResponse |
| 45 | +from azure.core.rest import AsyncHttpResponse, HttpRequest |
| 46 | +from azure.core.tracing.decorator_async import distributed_trace_async |
| 47 | + |
| 48 | +from ... import models as _models |
| 49 | +from ..._serialization import Deserializer, Serializer |
| 50 | +from ...operations._group_operations import build_find_groups_request |
| 51 | +from .._configuration import KuFlowRestClientConfiguration |
| 52 | + |
| 53 | +if sys.version_info >= (3, 9): |
| 54 | + from collections.abc import MutableMapping |
| 55 | +else: |
| 56 | + from typing import MutableMapping # type: ignore |
| 57 | +T = TypeVar("T") |
| 58 | +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] |
| 59 | + |
| 60 | + |
| 61 | +class GroupOperations: |
| 62 | + """ |
| 63 | + .. warning:: |
| 64 | + **DO NOT** instantiate this class directly. |
| 65 | +
|
| 66 | + Instead, you should access the following operations through |
| 67 | + :class:`~kuflow.rest.aio.KuFlowRestClient`'s |
| 68 | + :attr:`group` attribute. |
| 69 | + """ |
| 70 | + |
| 71 | + models = _models |
| 72 | + |
| 73 | + def __init__(self, *args, **kwargs) -> None: |
| 74 | + input_args = list(args) |
| 75 | + self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client") |
| 76 | + self._config: KuFlowRestClientConfiguration = input_args.pop(0) if input_args else kwargs.pop("config") |
| 77 | + self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer") |
| 78 | + self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer") |
| 79 | + |
| 80 | + @distributed_trace_async |
| 81 | + async def find_groups( |
| 82 | + self, |
| 83 | + *, |
| 84 | + size: int = 25, |
| 85 | + page: int = 0, |
| 86 | + sort: Optional[List[str]] = None, |
| 87 | + tenant_id: Optional[List[str]] = None, |
| 88 | + principal_id: Optional[str] = None, |
| 89 | + **kwargs: Any, |
| 90 | + ) -> _models.GroupPage: |
| 91 | + """Find all accessible Groups. |
| 92 | +
|
| 93 | + List all the Groups that have been created and the used credentials has access. |
| 94 | +
|
| 95 | + Available sort query values: id, name. |
| 96 | +
|
| 97 | + :keyword size: The number of records returned within a single API call. Default value is 25. |
| 98 | + :paramtype size: int |
| 99 | + :keyword page: The page number of the current page in the returned records, 0 is the first |
| 100 | + page. Default value is 0. |
| 101 | + :paramtype page: int |
| 102 | + :keyword sort: Sorting criteria in the format: property{,asc|desc}. Example: createdAt,desc |
| 103 | +
|
| 104 | + Default sort order is ascending. Multiple sort criteria are supported. |
| 105 | +
|
| 106 | + Please refer to the method description for supported properties. Default value is None. |
| 107 | + :paramtype sort: list[str] |
| 108 | + :keyword tenant_id: Filter by tenantId. Default value is None. |
| 109 | + :paramtype tenant_id: list[str] |
| 110 | + :keyword principal_id: Filter by principalId. Default value is None. |
| 111 | + :paramtype principal_id: str |
| 112 | + :return: GroupPage |
| 113 | + :rtype: ~kuflow.rest.models.GroupPage |
| 114 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 115 | + """ |
| 116 | + error_map: MutableMapping = { |
| 117 | + 401: ClientAuthenticationError, |
| 118 | + 404: ResourceNotFoundError, |
| 119 | + 409: ResourceExistsError, |
| 120 | + 304: ResourceNotModifiedError, |
| 121 | + } |
| 122 | + error_map.update(kwargs.pop("error_map", {}) or {}) |
| 123 | + |
| 124 | + _headers = kwargs.pop("headers", {}) or {} |
| 125 | + _params = kwargs.pop("params", {}) or {} |
| 126 | + |
| 127 | + cls: ClsType[_models.GroupPage] = kwargs.pop("cls", None) |
| 128 | + |
| 129 | + _request = build_find_groups_request( |
| 130 | + size=size, |
| 131 | + page=page, |
| 132 | + sort=sort, |
| 133 | + tenant_id=tenant_id, |
| 134 | + principal_id=principal_id, |
| 135 | + headers=_headers, |
| 136 | + params=_params, |
| 137 | + ) |
| 138 | + _request.url = self._client.format_url(_request.url) |
| 139 | + |
| 140 | + _stream = False |
| 141 | + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access |
| 142 | + _request, stream=_stream, **kwargs |
| 143 | + ) |
| 144 | + |
| 145 | + response = pipeline_response.http_response |
| 146 | + |
| 147 | + if response.status_code not in [200]: |
| 148 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 149 | + error = self._deserialize.failsafe_deserialize(_models.DefaultError, pipeline_response) |
| 150 | + raise HttpResponseError(response=response, model=error) |
| 151 | + |
| 152 | + deserialized = self._deserialize("GroupPage", pipeline_response.http_response) |
| 153 | + |
| 154 | + if cls: |
| 155 | + return cls(pipeline_response, deserialized, {}) # type: ignore |
| 156 | + |
| 157 | + return deserialized # type: ignore |
0 commit comments