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
176 changes: 176 additions & 0 deletions cirro_api_client/v1/api/execution/calculate_cost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
from http import HTTPStatus
from typing import Any, Dict, Optional

import httpx

from ... import errors
from ...client import Client
from ...models.cost_response import CostResponse
from ...types import Response


def _get_kwargs(
project_id: str,
dataset_id: str,
) -> Dict[str, Any]:
_kwargs: Dict[str, Any] = {
"method": "get",
"url": f"/projects/{project_id}/execution/{dataset_id}/cost",
}

return _kwargs


def _parse_response(*, client: Client, response: httpx.Response) -> Optional[CostResponse]:
if response.status_code == HTTPStatus.OK:
response_200 = CostResponse.from_dict(response.json())

return response_200

errors.handle_error_response(response, client.raise_on_unexpected_status)


def _build_response(*, client: Client, response: httpx.Response) -> Response[CostResponse]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
project_id: str,
dataset_id: str,
*,
client: Client,
) -> Response[CostResponse]:
"""Calculate cost

Calculate cost of an execution run

Args:
project_id (str):
dataset_id (str):
client (Client): instance of the API client

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[CostResponse]
"""

kwargs = _get_kwargs(
project_id=project_id,
dataset_id=dataset_id,
)

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

return _build_response(client=client, response=response)


def sync(
project_id: str,
dataset_id: str,
*,
client: Client,
) -> Optional[CostResponse]:
"""Calculate cost

Calculate cost of an execution run

Args:
project_id (str):
dataset_id (str):
client (Client): instance of the API client

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:
CostResponse
"""

try:
return sync_detailed(
project_id=project_id,
dataset_id=dataset_id,
client=client,
).parsed
except errors.NotFoundException:
return None


async def asyncio_detailed(
project_id: str,
dataset_id: str,
*,
client: Client,
) -> Response[CostResponse]:
"""Calculate cost

Calculate cost of an execution run

Args:
project_id (str):
dataset_id (str):
client (Client): instance of the API client

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[CostResponse]
"""

kwargs = _get_kwargs(
project_id=project_id,
dataset_id=dataset_id,
)

response = await client.get_async_httpx_client().request(auth=client.get_auth(), **kwargs)

return _build_response(client=client, response=response)


async def asyncio(
project_id: str,
dataset_id: str,
*,
client: Client,
) -> Optional[CostResponse]:
"""Calculate cost

Calculate cost of an execution run

Args:
project_id (str):
dataset_id (str):
client (Client): instance of the API client

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:
CostResponse
"""

try:
return (
await asyncio_detailed(
project_id=project_id,
dataset_id=dataset_id,
client=client,
)
).parsed
except errors.NotFoundException:
return None
Empty file.
176 changes: 176 additions & 0 deletions cirro_api_client/v1/api/workspaces/connect_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
from http import HTTPStatus
from typing import Any, Dict, Optional

import httpx

from ... import errors
from ...client import Client
from ...models.workspace_connection_response import WorkspaceConnectionResponse
from ...types import Response


def _get_kwargs(
project_id: str,
workspace_id: str,
) -> Dict[str, Any]:
_kwargs: Dict[str, Any] = {
"method": "post",
"url": f"/projects/{project_id}/workspaces/{workspace_id}:connect",
}

return _kwargs


def _parse_response(*, client: Client, response: httpx.Response) -> Optional[WorkspaceConnectionResponse]:
if response.status_code == HTTPStatus.ACCEPTED:
response_202 = WorkspaceConnectionResponse.from_dict(response.json())

return response_202

errors.handle_error_response(response, client.raise_on_unexpected_status)


def _build_response(*, client: Client, response: httpx.Response) -> Response[WorkspaceConnectionResponse]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
project_id: str,
workspace_id: str,
*,
client: Client,
) -> Response[WorkspaceConnectionResponse]:
"""Connect to workspace

Generates a URL to connect to the given workspace

Args:
project_id (str):
workspace_id (str):
client (Client): instance of the API client

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[WorkspaceConnectionResponse]
"""

kwargs = _get_kwargs(
project_id=project_id,
workspace_id=workspace_id,
)

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

return _build_response(client=client, response=response)


def sync(
project_id: str,
workspace_id: str,
*,
client: Client,
) -> Optional[WorkspaceConnectionResponse]:
"""Connect to workspace

Generates a URL to connect to the given workspace

Args:
project_id (str):
workspace_id (str):
client (Client): instance of the API client

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:
WorkspaceConnectionResponse
"""

try:
return sync_detailed(
project_id=project_id,
workspace_id=workspace_id,
client=client,
).parsed
except errors.NotFoundException:
return None


async def asyncio_detailed(
project_id: str,
workspace_id: str,
*,
client: Client,
) -> Response[WorkspaceConnectionResponse]:
"""Connect to workspace

Generates a URL to connect to the given workspace

Args:
project_id (str):
workspace_id (str):
client (Client): instance of the API client

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[WorkspaceConnectionResponse]
"""

kwargs = _get_kwargs(
project_id=project_id,
workspace_id=workspace_id,
)

response = await client.get_async_httpx_client().request(auth=client.get_auth(), **kwargs)

return _build_response(client=client, response=response)


async def asyncio(
project_id: str,
workspace_id: str,
*,
client: Client,
) -> Optional[WorkspaceConnectionResponse]:
"""Connect to workspace

Generates a URL to connect to the given workspace

Args:
project_id (str):
workspace_id (str):
client (Client): instance of the API client

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:
WorkspaceConnectionResponse
"""

try:
return (
await asyncio_detailed(
project_id=project_id,
workspace_id=workspace_id,
client=client,
)
).parsed
except errors.NotFoundException:
return None
Loading
Loading