diff --git a/nuon/api/apps/sync_app_config.py b/nuon/api/apps/sync_app_config.py new file mode 100644 index 00000000..12b13730 --- /dev/null +++ b/nuon/api/apps/sync_app_config.py @@ -0,0 +1,244 @@ +from http import HTTPStatus +from typing import Any +from urllib.parse import quote + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.app_app_config import AppAppConfig +from ...models.stderr_err_response import StderrErrResponse +from ...types import Response + + +def _get_kwargs( + app_id: str, + config_id: str, +) -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/v1/apps/{app_id}/configs/{config_id}/sync".format( + app_id=quote(str(app_id), safe=""), + config_id=quote(str(config_id), safe=""), + ), + } + + return _kwargs + + +def _parse_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> AppAppConfig | StderrErrResponse | None: + if response.status_code == 202: + response_202 = AppAppConfig.from_dict(response.json()) + + return response_202 + + if response.status_code == 400: + response_400 = StderrErrResponse.from_dict(response.json()) + + return response_400 + + if response.status_code == 401: + response_401 = StderrErrResponse.from_dict(response.json()) + + return response_401 + + if response.status_code == 403: + response_403 = StderrErrResponse.from_dict(response.json()) + + return response_403 + + if response.status_code == 404: + response_404 = StderrErrResponse.from_dict(response.json()) + + return response_404 + + if response.status_code == 409: + response_409 = StderrErrResponse.from_dict(response.json()) + + return response_409 + + if response.status_code == 500: + response_500 = StderrErrResponse.from_dict(response.json()) + + return response_500 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[AppAppConfig | StderrErrResponse]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + app_id: str, + config_id: str, + *, + client: AuthenticatedClient, +) -> Response[AppAppConfig | StderrErrResponse]: + """Sync an app config that was created with an intermediate config. + + The config is applied asynchronously: this returns `202` immediately and the + config moves through `syncing` to `active` or `error`. Poll + `GET /v1/apps/{app_id}/configs/{config_id}` for the outcome — `status`, + `status_description`, and the resolved `component_ids` / `action_ids` / + `runbook_ids`. Scheduled component builds and resources orphaned by this sync are + reported under `state.result`. + + Component builds are scheduled as part of the sync. A component whose config is + unchanged since the previous sync, and whose last build did not fail, keeps its + existing config connection and is not rebuilt. + + Args: + app_id (str): + config_id (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AppAppConfig | StderrErrResponse] + """ + + kwargs = _get_kwargs( + app_id=app_id, + config_id=config_id, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + app_id: str, + config_id: str, + *, + client: AuthenticatedClient, +) -> AppAppConfig | StderrErrResponse | None: + """Sync an app config that was created with an intermediate config. + + The config is applied asynchronously: this returns `202` immediately and the + config moves through `syncing` to `active` or `error`. Poll + `GET /v1/apps/{app_id}/configs/{config_id}` for the outcome — `status`, + `status_description`, and the resolved `component_ids` / `action_ids` / + `runbook_ids`. Scheduled component builds and resources orphaned by this sync are + reported under `state.result`. + + Component builds are scheduled as part of the sync. A component whose config is + unchanged since the previous sync, and whose last build did not fail, keeps its + existing config connection and is not rebuilt. + + Args: + app_id (str): + config_id (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AppAppConfig | StderrErrResponse + """ + + return sync_detailed( + app_id=app_id, + config_id=config_id, + client=client, + ).parsed + + +async def asyncio_detailed( + app_id: str, + config_id: str, + *, + client: AuthenticatedClient, +) -> Response[AppAppConfig | StderrErrResponse]: + """Sync an app config that was created with an intermediate config. + + The config is applied asynchronously: this returns `202` immediately and the + config moves through `syncing` to `active` or `error`. Poll + `GET /v1/apps/{app_id}/configs/{config_id}` for the outcome — `status`, + `status_description`, and the resolved `component_ids` / `action_ids` / + `runbook_ids`. Scheduled component builds and resources orphaned by this sync are + reported under `state.result`. + + Component builds are scheduled as part of the sync. A component whose config is + unchanged since the previous sync, and whose last build did not fail, keeps its + existing config connection and is not rebuilt. + + Args: + app_id (str): + config_id (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AppAppConfig | StderrErrResponse] + """ + + kwargs = _get_kwargs( + app_id=app_id, + config_id=config_id, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + app_id: str, + config_id: str, + *, + client: AuthenticatedClient, +) -> AppAppConfig | StderrErrResponse | None: + """Sync an app config that was created with an intermediate config. + + The config is applied asynchronously: this returns `202` immediately and the + config moves through `syncing` to `active` or `error`. Poll + `GET /v1/apps/{app_id}/configs/{config_id}` for the outcome — `status`, + `status_description`, and the resolved `component_ids` / `action_ids` / + `runbook_ids`. Scheduled component builds and resources orphaned by this sync are + reported under `state.result`. + + Component builds are scheduled as part of the sync. A component whose config is + unchanged since the previous sync, and whose last build did not fail, keeps its + existing config connection and is not rebuilt. + + Args: + app_id (str): + config_id (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AppAppConfig | StderrErrResponse + """ + + return ( + await asyncio_detailed( + app_id=app_id, + config_id=config_id, + client=client, + ) + ).parsed diff --git a/pyproject.toml b/pyproject.toml index 2f7473e5..f3999bad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nuon" -version = "0.19.1101" +version = "0.19.1102" description = "A client library for accessing Nuon" authors = [] requires-python = ">=3.11" diff --git a/version.txt b/version.txt index a0a8cc3f..ae2a3c9d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.19.1101 +0.19.1102