|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, cast |
| 3 | +from uuid import UUID |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ... import errors |
| 8 | +from ...client import AuthenticatedClient, Client |
| 9 | +from ...models.environment_discovery_settings_response import EnvironmentDiscoverySettingsResponse |
| 10 | +from ...models.environment_discovery_settings_update import EnvironmentDiscoverySettingsUpdate |
| 11 | +from ...models.http_validation_error import HTTPValidationError |
| 12 | +from ...types import Response |
| 13 | + |
| 14 | + |
| 15 | +def _get_kwargs( |
| 16 | + env_id: UUID, |
| 17 | + *, |
| 18 | + body: EnvironmentDiscoverySettingsUpdate, |
| 19 | +) -> dict[str, Any]: |
| 20 | + headers: dict[str, Any] = {} |
| 21 | + |
| 22 | + _kwargs: dict[str, Any] = { |
| 23 | + "method": "patch", |
| 24 | + "url": f"/api/v1/environments/{env_id}/discovery-settings", |
| 25 | + } |
| 26 | + |
| 27 | + _kwargs["json"] = body.to_dict() |
| 28 | + |
| 29 | + headers["Content-Type"] = "application/json" |
| 30 | + |
| 31 | + _kwargs["headers"] = headers |
| 32 | + return _kwargs |
| 33 | + |
| 34 | + |
| 35 | +def _parse_response( |
| 36 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 37 | +) -> Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError | None: |
| 38 | + if response.status_code == 200: |
| 39 | + response_200 = EnvironmentDiscoverySettingsResponse.from_dict(response.json()) |
| 40 | + |
| 41 | + return response_200 |
| 42 | + |
| 43 | + if response.status_code == 404: |
| 44 | + response_404 = cast(Any, None) |
| 45 | + return response_404 |
| 46 | + |
| 47 | + if response.status_code == 422: |
| 48 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 49 | + |
| 50 | + return response_422 |
| 51 | + |
| 52 | + if client.raise_on_unexpected_status: |
| 53 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 54 | + else: |
| 55 | + return None |
| 56 | + |
| 57 | + |
| 58 | +def _build_response( |
| 59 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 60 | +) -> Response[Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError]: |
| 61 | + return Response( |
| 62 | + status_code=HTTPStatus(response.status_code), |
| 63 | + content=response.content, |
| 64 | + headers=response.headers, |
| 65 | + parsed=_parse_response(client=client, response=response), |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def sync_detailed( |
| 70 | + env_id: UUID, |
| 71 | + *, |
| 72 | + client: AuthenticatedClient, |
| 73 | + body: EnvironmentDiscoverySettingsUpdate, |
| 74 | +) -> Response[Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError]: |
| 75 | + """Update Environment Discovery Settings |
| 76 | +
|
| 77 | + Update discovery settings for an environment |
| 78 | +
|
| 79 | + Args: |
| 80 | + env_id (UUID): |
| 81 | + body (EnvironmentDiscoverySettingsUpdate): |
| 82 | +
|
| 83 | + Raises: |
| 84 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 85 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 86 | +
|
| 87 | + Returns: |
| 88 | + Response[Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError] |
| 89 | + """ |
| 90 | + |
| 91 | + kwargs = _get_kwargs( |
| 92 | + env_id=env_id, |
| 93 | + body=body, |
| 94 | + ) |
| 95 | + |
| 96 | + response = client.get_httpx_client().request( |
| 97 | + **kwargs, |
| 98 | + ) |
| 99 | + |
| 100 | + return _build_response(client=client, response=response) |
| 101 | + |
| 102 | + |
| 103 | +def sync( |
| 104 | + env_id: UUID, |
| 105 | + *, |
| 106 | + client: AuthenticatedClient, |
| 107 | + body: EnvironmentDiscoverySettingsUpdate, |
| 108 | +) -> Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError | None: |
| 109 | + """Update Environment Discovery Settings |
| 110 | +
|
| 111 | + Update discovery settings for an environment |
| 112 | +
|
| 113 | + Args: |
| 114 | + env_id (UUID): |
| 115 | + body (EnvironmentDiscoverySettingsUpdate): |
| 116 | +
|
| 117 | + Raises: |
| 118 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 119 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 120 | +
|
| 121 | + Returns: |
| 122 | + Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError |
| 123 | + """ |
| 124 | + |
| 125 | + return sync_detailed( |
| 126 | + env_id=env_id, |
| 127 | + client=client, |
| 128 | + body=body, |
| 129 | + ).parsed |
| 130 | + |
| 131 | + |
| 132 | +async def asyncio_detailed( |
| 133 | + env_id: UUID, |
| 134 | + *, |
| 135 | + client: AuthenticatedClient, |
| 136 | + body: EnvironmentDiscoverySettingsUpdate, |
| 137 | +) -> Response[Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError]: |
| 138 | + """Update Environment Discovery Settings |
| 139 | +
|
| 140 | + Update discovery settings for an environment |
| 141 | +
|
| 142 | + Args: |
| 143 | + env_id (UUID): |
| 144 | + body (EnvironmentDiscoverySettingsUpdate): |
| 145 | +
|
| 146 | + Raises: |
| 147 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 148 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 149 | +
|
| 150 | + Returns: |
| 151 | + Response[Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError] |
| 152 | + """ |
| 153 | + |
| 154 | + kwargs = _get_kwargs( |
| 155 | + env_id=env_id, |
| 156 | + body=body, |
| 157 | + ) |
| 158 | + |
| 159 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 160 | + |
| 161 | + return _build_response(client=client, response=response) |
| 162 | + |
| 163 | + |
| 164 | +async def asyncio( |
| 165 | + env_id: UUID, |
| 166 | + *, |
| 167 | + client: AuthenticatedClient, |
| 168 | + body: EnvironmentDiscoverySettingsUpdate, |
| 169 | +) -> Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError | None: |
| 170 | + """Update Environment Discovery Settings |
| 171 | +
|
| 172 | + Update discovery settings for an environment |
| 173 | +
|
| 174 | + Args: |
| 175 | + env_id (UUID): |
| 176 | + body (EnvironmentDiscoverySettingsUpdate): |
| 177 | +
|
| 178 | + Raises: |
| 179 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 180 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 181 | +
|
| 182 | + Returns: |
| 183 | + Any | EnvironmentDiscoverySettingsResponse | HTTPValidationError |
| 184 | + """ |
| 185 | + |
| 186 | + return ( |
| 187 | + await asyncio_detailed( |
| 188 | + env_id=env_id, |
| 189 | + client=client, |
| 190 | + body=body, |
| 191 | + ) |
| 192 | + ).parsed |
0 commit comments