Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
233 changes: 233 additions & 0 deletions nuon/api/installs/toggle_install_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
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_workflow_response import AppWorkflowResponse
from ...models.service_toggle_install_component_request import ServiceToggleInstallComponentRequest
from ...models.stderr_err_response import StderrErrResponse
from ...types import Response


def _get_kwargs(
install_id: str,
component_id: str,
*,
body: ServiceToggleInstallComponentRequest,
) -> dict[str, Any]:
headers: dict[str, Any] = {}

_kwargs: dict[str, Any] = {
"method": "post",
"url": "/v1/installs/{install_id}/components/{component_id}/toggle".format(
install_id=quote(str(install_id), safe=""),
component_id=quote(str(component_id), safe=""),
),
}

_kwargs["json"] = body.to_dict()

headers["Content-Type"] = "application/json"

_kwargs["headers"] = headers
return _kwargs


def _parse_response(
*, client: AuthenticatedClient | Client, response: httpx.Response
) -> AppWorkflowResponse | StderrErrResponse | None:
if response.status_code == 201:
response_201 = AppWorkflowResponse.from_dict(response.json())

return response_201

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[AppWorkflowResponse | 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(
install_id: str,
component_id: str,
*,
client: AuthenticatedClient,
body: ServiceToggleInstallComponentRequest,
) -> Response[AppWorkflowResponse | StderrErrResponse]:
"""toggle an install component on or off

Enable or disable a toggleable component on an install. Enabling triggers a deploy workflow,
disabling triggers a teardown workflow.

Args:
install_id (str):
component_id (str):
body (ServiceToggleInstallComponentRequest):

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[AppWorkflowResponse | StderrErrResponse]
"""

kwargs = _get_kwargs(
install_id=install_id,
component_id=component_id,
body=body,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
install_id: str,
component_id: str,
*,
client: AuthenticatedClient,
body: ServiceToggleInstallComponentRequest,
) -> AppWorkflowResponse | StderrErrResponse | None:
"""toggle an install component on or off

Enable or disable a toggleable component on an install. Enabling triggers a deploy workflow,
disabling triggers a teardown workflow.

Args:
install_id (str):
component_id (str):
body (ServiceToggleInstallComponentRequest):

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:
AppWorkflowResponse | StderrErrResponse
"""

return sync_detailed(
install_id=install_id,
component_id=component_id,
client=client,
body=body,
).parsed


async def asyncio_detailed(
install_id: str,
component_id: str,
*,
client: AuthenticatedClient,
body: ServiceToggleInstallComponentRequest,
) -> Response[AppWorkflowResponse | StderrErrResponse]:
"""toggle an install component on or off

Enable or disable a toggleable component on an install. Enabling triggers a deploy workflow,
disabling triggers a teardown workflow.

Args:
install_id (str):
component_id (str):
body (ServiceToggleInstallComponentRequest):

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[AppWorkflowResponse | StderrErrResponse]
"""

kwargs = _get_kwargs(
install_id=install_id,
component_id=component_id,
body=body,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
install_id: str,
component_id: str,
*,
client: AuthenticatedClient,
body: ServiceToggleInstallComponentRequest,
) -> AppWorkflowResponse | StderrErrResponse | None:
"""toggle an install component on or off

Enable or disable a toggleable component on an install. Enabling triggers a deploy workflow,
disabling triggers a teardown workflow.

Args:
install_id (str):
component_id (str):
body (ServiceToggleInstallComponentRequest):

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:
AppWorkflowResponse | StderrErrResponse
"""

return (
await asyncio_detailed(
install_id=install_id,
component_id=component_id,
client=client,
body=body,
)
).parsed
4 changes: 4 additions & 0 deletions nuon/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
from .app_install_component_links import AppInstallComponentLinks
from .app_install_component_statuses import AppInstallComponentStatuses
from .app_install_config import AppInstallConfig
from .app_install_config_component_toggles import AppInstallConfigComponentToggles
from .app_install_config_update import AppInstallConfigUpdate
from .app_install_deploy import AppInstallDeploy
from .app_install_deploy_outputs import AppInstallDeployOutputs
Expand Down Expand Up @@ -639,6 +640,7 @@
from .service_teardown_install_component_request import ServiceTeardownInstallComponentRequest
from .service_teardown_install_components_request import ServiceTeardownInstallComponentsRequest
from .service_timeseries_bucket import ServiceTimeseriesBucket
from .service_toggle_install_component_request import ServiceToggleInstallComponentRequest
from .service_trigger_app_branch_run_request import ServiceTriggerAppBranchRunRequest
from .service_update_action_workflow_request import ServiceUpdateActionWorkflowRequest
from .service_update_action_workflow_request_labels import ServiceUpdateActionWorkflowRequestLabels
Expand Down Expand Up @@ -822,6 +824,7 @@
"AppInstallComponentLinks",
"AppInstallComponentStatuses",
"AppInstallConfig",
"AppInstallConfigComponentToggles",
"AppInstallConfigUpdate",
"AppInstallDeploy",
"AppInstallDeployOutputs",
Expand Down Expand Up @@ -1325,6 +1328,7 @@
"ServiceTeardownInstallComponentRequest",
"ServiceTeardownInstallComponentsRequest",
"ServiceTimeseriesBucket",
"ServiceToggleInstallComponentRequest",
"ServiceTriggerAppBranchRunRequest",
"ServiceUpdateActionWorkflowRequest",
"ServiceUpdateActionWorkflowRequestLabels",
Expand Down
4 changes: 4 additions & 0 deletions nuon/models/app_action_workflow_trigger_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AppActionWorkflowTriggerType(str, Enum):
POST_DEPLOY_COMPONENT = "post-deploy-component"
POST_DEPROVISION = "post-deprovision"
POST_DEPROVISION_SANDBOX = "post-deprovision-sandbox"
POST_DISABLE_COMPONENT = "post-disable-component"
POST_ENABLE_COMPONENT = "post-enable-component"
POST_PROVISION = "post-provision"
POST_REPROVISION = "post-reprovision"
POST_REPROVISION_SANDBOX = "post-reprovision-sandbox"
Expand All @@ -20,6 +22,8 @@ class AppActionWorkflowTriggerType(str, Enum):
PRE_DEPLOY_COMPONENT = "pre-deploy-component"
PRE_DEPROVISION = "pre-deprovision"
PRE_DEPROVISION_SANDBOX = "pre-deprovision-sandbox"
PRE_DISABLE_COMPONENT = "pre-disable-component"
PRE_ENABLE_COMPONENT = "pre-enable-component"
PRE_PROVISION = "pre-provision"
PRE_REPROVISION = "pre-reprovision"
PRE_REPROVISION_SANDBOX = "pre-reprovision-sandbox"
Expand Down
18 changes: 18 additions & 0 deletions nuon/models/app_component_config_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AppComponentConfigConnection:
component_name (str | Unset):
created_at (str | Unset):
created_by_id (str | Unset):
default_enabled (bool | Unset):
deploy_timeout (str | Unset): Duration string for deploy operations (e.g., "30m", "1h"). Max 1h.
docker_build (AppDockerBuildComponentConfig | Unset):
drift_schedule (str | Unset):
Expand All @@ -54,6 +55,7 @@ class AppComponentConfigConnection:
refs (list[RefsRef] | Unset):
skip_noops (bool | Unset):
terraform_module (AppTerraformModuleComponentConfig | Unset):
toggleable (bool | Unset):
type_ (AppComponentType | Unset):
updated_at (str | Unset):
version (int | Unset):
Expand All @@ -69,6 +71,7 @@ class AppComponentConfigConnection:
component_name: str | Unset = UNSET
created_at: str | Unset = UNSET
created_by_id: str | Unset = UNSET
default_enabled: bool | Unset = UNSET
deploy_timeout: str | Unset = UNSET
docker_build: AppDockerBuildComponentConfig | Unset = UNSET
drift_schedule: str | Unset = UNSET
Expand All @@ -84,6 +87,7 @@ class AppComponentConfigConnection:
refs: list[RefsRef] | Unset = UNSET
skip_noops: bool | Unset = UNSET
terraform_module: AppTerraformModuleComponentConfig | Unset = UNSET
toggleable: bool | Unset = UNSET
type_: AppComponentType | Unset = UNSET
updated_at: str | Unset = UNSET
version: int | Unset = UNSET
Expand Down Expand Up @@ -112,6 +116,8 @@ def to_dict(self) -> dict[str, Any]:

created_by_id = self.created_by_id

default_enabled = self.default_enabled

deploy_timeout = self.deploy_timeout

docker_build: dict[str, Any] | Unset = UNSET
Expand Down Expand Up @@ -165,6 +171,8 @@ def to_dict(self) -> dict[str, Any]:
if not isinstance(self.terraform_module, Unset):
terraform_module = self.terraform_module.to_dict()

toggleable = self.toggleable

type_: str | Unset = UNSET
if not isinstance(self.type_, Unset):
type_ = self.type_.value
Expand Down Expand Up @@ -196,6 +204,8 @@ def to_dict(self) -> dict[str, Any]:
field_dict["created_at"] = created_at
if created_by_id is not UNSET:
field_dict["created_by_id"] = created_by_id
if default_enabled is not UNSET:
field_dict["default_enabled"] = default_enabled
if deploy_timeout is not UNSET:
field_dict["deploy_timeout"] = deploy_timeout
if docker_build is not UNSET:
Expand Down Expand Up @@ -226,6 +236,8 @@ def to_dict(self) -> dict[str, Any]:
field_dict["skip_noops"] = skip_noops
if terraform_module is not UNSET:
field_dict["terraform_module"] = terraform_module
if toggleable is not UNSET:
field_dict["toggleable"] = toggleable
if type_ is not UNSET:
field_dict["type"] = type_
if updated_at is not UNSET:
Expand Down Expand Up @@ -268,6 +280,8 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:

created_by_id = d.pop("created_by_id", UNSET)

default_enabled = d.pop("default_enabled", UNSET)

deploy_timeout = d.pop("deploy_timeout", UNSET)

_docker_build = d.pop("docker_build", UNSET)
Expand Down Expand Up @@ -345,6 +359,8 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
else:
terraform_module = AppTerraformModuleComponentConfig.from_dict(_terraform_module)

toggleable = d.pop("toggleable", UNSET)

_type_ = d.pop("type", UNSET)
type_: AppComponentType | Unset
if isinstance(_type_, Unset):
Expand All @@ -367,6 +383,7 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
component_name=component_name,
created_at=created_at,
created_by_id=created_by_id,
default_enabled=default_enabled,
deploy_timeout=deploy_timeout,
docker_build=docker_build,
drift_schedule=drift_schedule,
Expand All @@ -382,6 +399,7 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
refs=refs,
skip_noops=skip_noops,
terraform_module=terraform_module,
toggleable=toggleable,
type_=type_,
updated_at=updated_at,
version=version,
Expand Down
Loading
Loading