From 594bb174d29a1ddf19aa551ec9aad71681c13930 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Fri, 17 Jan 2025 11:01:40 -0800 Subject: [PATCH] Generate only relevant api routes for the client in SDKs --- packages/js-sdk/package.json | 2 +- packages/js-sdk/src/api/schema.gen.ts | 151 +++++++++-- packages/python-sdk/Makefile | 5 +- .../e2b/api/client/api/auth/__init__.py | 0 .../e2b/api/client/api/auth/get_teams.py | 137 ---------- .../e2b/api/client/api/default/__init__.py | 0 .../e2b/api/client/api/default/get_health.py | 81 ------ .../sandboxes/delete_sandboxes_sandbox_id.py | 4 +- .../api/client/api/sandboxes/get_sandboxes.py | 50 +++- .../get_sandboxes_sandbox_id_logs.py | 6 +- .../client/api/sandboxes/post_sandboxes.py | 6 +- .../e2b/api/client/api/templates/__init__.py | 0 .../templates/delete_templates_template_id.py | 97 -------- .../api/client/api/templates/get_templates.py | 169 ------------- ...ates_template_id_builds_build_id_status.py | 193 -------------- .../client/api/templates/post_templates.py | 166 ------------- .../templates/post_templates_template_id.py | 179 ------------- ...t_templates_template_id_builds_build_id.py | 104 -------- .../e2b/api/client/models/__init__.py | 14 ++ .../e2b/api/client/models/new_sandbox.py | 28 +-- .../e2b/api/client/models/running_sandbox.py | 60 ++--- .../e2b/api/client/models/sandbox.py | 32 +-- .../e2b/api/client/models/sandbox_log.py | 16 +- .../python-sdk/e2b/api/client/models/team.py | 32 +-- .../e2b/api/client/models/template.py | 89 ++++++- .../e2b/api/client/models/template_build.py | 32 +-- .../client/models/template_build_request.py | 36 +-- spec/openapi.yml | 235 +++++++++++++++++- spec/remove_extra_tags.py | 35 +++ 29 files changed, 662 insertions(+), 1297 deletions(-) delete mode 100644 packages/python-sdk/e2b/api/client/api/auth/__init__.py delete mode 100644 packages/python-sdk/e2b/api/client/api/auth/get_teams.py delete mode 100644 packages/python-sdk/e2b/api/client/api/default/__init__.py delete mode 100644 packages/python-sdk/e2b/api/client/api/default/get_health.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/__init__.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/delete_templates_template_id.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/get_templates.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/get_templates_template_id_builds_build_id_status.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/post_templates.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id.py delete mode 100644 packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id_builds_build_id.py create mode 100644 spec/remove_extra_tags.py diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.json index d57b08e15..6fc6cd57e 100644 --- a/packages/js-sdk/package.json +++ b/packages/js-sdk/package.json @@ -28,7 +28,7 @@ "dev": "tsup --watch", "example": "tsx example.mts", "test": "vitest run", - "generate": "openapi-typescript ../../spec/openapi.yml -x api_key --support-array-length --alphabetize --output src/api/schema.gen.ts", + "generate": "python ./../../spec/remove_extra_tags.py sandboxes templates && openapi-typescript ../../spec/openapi_generated.yml -x api_key --support-array-length --alphabetize --output src/api/schema.gen.ts", "generate-envd-api": "openapi-typescript ../../spec/envd/envd.yaml -x api_key --support-array-length --alphabetize --output src/envd/schema.gen.ts", "generate-ref": "./scripts/generate_sdk_ref.sh", "check-deps": "knip", diff --git a/packages/js-sdk/src/api/schema.gen.ts b/packages/js-sdk/src/api/schema.gen.ts index 3cc9a39e3..6fe8e4642 100644 --- a/packages/js-sdk/src/api/schema.gen.ts +++ b/packages/js-sdk/src/api/schema.gen.ts @@ -5,21 +5,15 @@ export interface paths { - "/health": { - /** @description Health check */ - get: { - responses: { - /** @description Request was successful */ - 200: { - content: never; - }; - 401: components["responses"]["401"]; - }; - }; - }; "/sandboxes": { /** @description List all running sandboxes */ get: { + parameters: { + query?: { + /** @description A list of filters with key-value pairs (e.g. user:abc, app:prod). */ + filter?: string[]; + }; + }; responses: { /** @description Successfully returned all running sandboxes */ 200: { @@ -53,6 +47,25 @@ export interface paths { }; }; "/sandboxes/{sandboxID}": { + /** @description Get a sandbox by id */ + get: { + parameters: { + path: { + sandboxID: components["parameters"]["sandboxID"]; + }; + }; + responses: { + /** @description Successfully returned the sandbox */ + 200: { + content: { + "application/json": components["schemas"]["RunningSandbox"]; + }; + }; + 401: components["responses"]["401"]; + 404: components["responses"]["404"]; + 500: components["responses"]["500"]; + }; + }; /** @description Kill a sandbox */ delete: { parameters: { @@ -98,6 +111,26 @@ export interface paths { }; }; }; + "/sandboxes/{sandboxID}/pause": { + /** @description Pause the sandbox */ + post: { + parameters: { + path: { + sandboxID: components["parameters"]["sandboxID"]; + }; + }; + responses: { + /** @description The sandbox was paused successfully and can be resumed */ + 204: { + content: never; + }; + 401: components["responses"]["401"]; + 404: components["responses"]["404"]; + 409: components["responses"]["409"]; + 500: components["responses"]["500"]; + }; + }; + }; "/sandboxes/{sandboxID}/refreshes": { /** @description Refresh the sandbox extending its time to live */ post: { @@ -124,6 +157,33 @@ export interface paths { }; }; }; + "/sandboxes/{sandboxID}/resume": { + /** @description Resume the sandbox */ + post: { + parameters: { + path: { + sandboxID: components["parameters"]["sandboxID"]; + }; + }; + requestBody: { + content: { + "application/json": components["schemas"]["ResumedSandbox"]; + }; + }; + responses: { + /** @description The sandbox was resumed successfully */ + 201: { + content: { + "application/json": components["schemas"]["Sandbox"]; + }; + }; + 401: components["responses"]["401"]; + 404: components["responses"]["404"]; + 409: components["responses"]["409"]; + 500: components["responses"]["500"]; + }; + }; + }; "/sandboxes/{sandboxID}/timeout": { /** @description Set the timeout for the sandbox. The sandbox will expire x seconds from the time of the request. Calling this method multiple times overwrites the TTL, each time using the current timestamp as the starting point to measure the timeout duration. */ post: { @@ -154,21 +214,6 @@ export interface paths { }; }; }; - "/teams": { - /** @description List all teams */ - get: { - responses: { - /** @description Successfully returned all teams */ - 200: { - content: { - "application/json": components["schemas"]["Team"][]; - }; - }; - 401: components["responses"]["401"]; - 500: components["responses"]["500"]; - }; - }; - }; "/templates": { /** @description List all templates */ get: { @@ -355,6 +400,51 @@ export interface components { */ timeout?: number; }; + Node: { + /** + * Format: int32 + * @description Number of allocated CPU cores + */ + allocatedCPU: number; + /** + * Format: int32 + * @description Amount of allocated memory in MiB + */ + allocatedMemoryMiB: number; + /** @description Identifier of the node */ + nodeID: string; + /** + * Format: int32 + * @description Number of sandboxes running on the node + */ + sandboxCount: number; + status: components["schemas"]["NodeStatus"]; + }; + NodeDetail: { + /** @description List of cached builds id on the node */ + cachedBuilds: string[]; + /** @description Identifier of the node */ + nodeID: string; + /** @description List of sandboxes running on the node */ + sandboxes: components["schemas"]["RunningSandbox"][]; + status: components["schemas"]["NodeStatus"]; + }; + /** + * @description Status of the node + * @enum {string} + */ + NodeStatus: "ready" | "draining"; + NodeStatusChange: { + status: components["schemas"]["NodeStatus"]; + }; + ResumedSandbox: { + /** + * Format: int32 + * @description Time to live for the sandbox in seconds. + * @default 15 + */ + timeout?: number; + }; RunningSandbox: { /** @description Alias of the template */ alias?: string; @@ -516,6 +606,12 @@ export interface components { "application/json": components["schemas"]["Error"]; }; }; + /** @description Conflict */ + 409: { + content: { + "application/json": components["schemas"]["Error"]; + }; + }; /** @description Server error */ 500: { content: { @@ -525,6 +621,7 @@ export interface components { }; parameters: { buildID: string; + nodeID: string; sandboxID: string; templateID: string; }; diff --git a/packages/python-sdk/Makefile b/packages/python-sdk/Makefile index c99288d06..c1b169c53 100644 --- a/packages/python-sdk/Makefile +++ b/packages/python-sdk/Makefile @@ -1,8 +1,9 @@ generate-api: - openapi-python-client generate --output-path e2b/api/api --overwrite --path ../../spec/openapi.yml + python ./../../spec/remove_extra_tags.py sandboxes + openapi-python-client generate --output-path e2b/api/api --overwrite --path ../../spec/openapi_generated.yml rm -rf e2b/api/client mv e2b/api/api/e2b_api_client e2b/api/client rm -rf e2b/api/api init: - pip install openapi-python-client \ No newline at end of file + pip install openapi-python-client diff --git a/packages/python-sdk/e2b/api/client/api/auth/__init__.py b/packages/python-sdk/e2b/api/client/api/auth/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/python-sdk/e2b/api/client/api/auth/get_teams.py b/packages/python-sdk/e2b/api/client/api/auth/get_teams.py deleted file mode 100644 index d26eb508b..000000000 --- a/packages/python-sdk/e2b/api/client/api/auth/get_teams.py +++ /dev/null @@ -1,137 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.team import Team -from ...types import Response - - -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { - "method": "get", - "url": "/teams", - } - - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, List["Team"]]]: - if response.status_code == HTTPStatus.OK: - response_200 = [] - _response_200 = response.json() - for response_200_item_data in _response_200: - response_200_item = Team.from_dict(response_200_item_data) - - response_200.append(response_200_item) - - return response_200 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - response_500 = cast(Any, None) - return response_500 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, List["Team"]]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - *, - client: AuthenticatedClient, -) -> Response[Union[Any, List["Team"]]]: - """List all teams - - 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[Union[Any, List['Team']]] - """ - - kwargs = _get_kwargs() - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - *, - client: AuthenticatedClient, -) -> Optional[Union[Any, List["Team"]]]: - """List all teams - - 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: - Union[Any, List['Team']] - """ - - return sync_detailed( - client=client, - ).parsed - - -async def asyncio_detailed( - *, - client: AuthenticatedClient, -) -> Response[Union[Any, List["Team"]]]: - """List all teams - - 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[Union[Any, List['Team']]] - """ - - kwargs = _get_kwargs() - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - *, - client: AuthenticatedClient, -) -> Optional[Union[Any, List["Team"]]]: - """List all teams - - 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: - Union[Any, List['Team']] - """ - - return ( - await asyncio_detailed( - client=client, - ) - ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/default/__init__.py b/packages/python-sdk/e2b/api/client/api/default/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/python-sdk/e2b/api/client/api/default/get_health.py b/packages/python-sdk/e2b/api/client/api/default/get_health.py deleted file mode 100644 index 339a6905f..000000000 --- a/packages/python-sdk/e2b/api/client/api/default/get_health.py +++ /dev/null @@ -1,81 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...types import Response - - -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { - "method": "get", - "url": "/health", - } - - return _kwargs - - -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: - return None - if response.status_code == HTTPStatus.UNAUTHORIZED: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - *, - client: Union[AuthenticatedClient, Client], -) -> Response[Any]: - """Health check - - 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[Any] - """ - - kwargs = _get_kwargs() - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -async def asyncio_detailed( - *, - client: Union[AuthenticatedClient, Client], -) -> Response[Any]: - """Health check - - 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[Any] - """ - - kwargs = _get_kwargs() - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) diff --git a/packages/python-sdk/e2b/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py b/packages/python-sdk/e2b/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py index fa9f37750..30a419c00 100644 --- a/packages/python-sdk/e2b/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py +++ b/packages/python-sdk/e2b/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py @@ -22,10 +22,10 @@ def _get_kwargs( def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.NO_CONTENT: return None - if response.status_code == HTTPStatus.NOT_FOUND: - return None if response.status_code == HTTPStatus.UNAUTHORIZED: return None + if response.status_code == HTTPStatus.NOT_FOUND: + return None if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: return None if client.raise_on_unexpected_status: diff --git a/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes.py b/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes.py index 70bb816f7..71539e473 100644 --- a/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes.py +++ b/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes.py @@ -6,13 +6,27 @@ from ... import errors from ...client import AuthenticatedClient, Client from ...models.running_sandbox import RunningSandbox -from ...types import Response +from ...types import UNSET, Response, Unset -def _get_kwargs() -> Dict[str, Any]: +def _get_kwargs( + *, + filter_: Union[Unset, List[str]] = UNSET, +) -> Dict[str, Any]: + params: Dict[str, Any] = {} + + json_filter_: Union[Unset, List[str]] = UNSET + if not isinstance(filter_, Unset): + json_filter_ = filter_ + + params["filter"] = json_filter_ + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + _kwargs: Dict[str, Any] = { "method": "get", "url": "/sandboxes", + "params": params, } return _kwargs @@ -30,12 +44,12 @@ def _parse_response( response_200.append(response_200_item) return response_200 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 if response.status_code == HTTPStatus.BAD_REQUEST: response_400 = cast(Any, None) return response_400 + if response.status_code == HTTPStatus.UNAUTHORIZED: + response_401 = cast(Any, None) + return response_401 if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: response_500 = cast(Any, None) return response_500 @@ -59,9 +73,13 @@ def _build_response( def sync_detailed( *, client: AuthenticatedClient, + filter_: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, List["RunningSandbox"]]]: """List all running sandboxes + Args: + filter_ (Union[Unset, List[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. @@ -70,7 +88,9 @@ def sync_detailed( Response[Union[Any, List['RunningSandbox']]] """ - kwargs = _get_kwargs() + kwargs = _get_kwargs( + filter_=filter_, + ) response = client.get_httpx_client().request( **kwargs, @@ -82,9 +102,13 @@ def sync_detailed( def sync( *, client: AuthenticatedClient, + filter_: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, List["RunningSandbox"]]]: """List all running sandboxes + Args: + filter_ (Union[Unset, List[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. @@ -95,15 +119,20 @@ def sync( return sync_detailed( client=client, + filter_=filter_, ).parsed async def asyncio_detailed( *, client: AuthenticatedClient, + filter_: Union[Unset, List[str]] = UNSET, ) -> Response[Union[Any, List["RunningSandbox"]]]: """List all running sandboxes + Args: + filter_ (Union[Unset, List[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. @@ -112,7 +141,9 @@ async def asyncio_detailed( Response[Union[Any, List['RunningSandbox']]] """ - kwargs = _get_kwargs() + kwargs = _get_kwargs( + filter_=filter_, + ) response = await client.get_async_httpx_client().request(**kwargs) @@ -122,9 +153,13 @@ async def asyncio_detailed( async def asyncio( *, client: AuthenticatedClient, + filter_: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, List["RunningSandbox"]]]: """List all running sandboxes + Args: + filter_ (Union[Unset, List[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. @@ -136,5 +171,6 @@ async def asyncio( return ( await asyncio_detailed( client=client, + filter_=filter_, ) ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py b/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py index 97325e59b..7c70e28b7 100644 --- a/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py +++ b/packages/python-sdk/e2b/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py @@ -39,12 +39,12 @@ def _parse_response( response_200 = SandboxLogs.from_dict(response.json()) return response_200 - if response.status_code == HTTPStatus.NOT_FOUND: - response_404 = cast(Any, None) - return response_404 if response.status_code == HTTPStatus.UNAUTHORIZED: response_401 = cast(Any, None) return response_401 + if response.status_code == HTTPStatus.NOT_FOUND: + response_404 = cast(Any, None) + return response_404 if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: response_500 = cast(Any, None) return response_500 diff --git a/packages/python-sdk/e2b/api/client/api/sandboxes/post_sandboxes.py b/packages/python-sdk/e2b/api/client/api/sandboxes/post_sandboxes.py index 56220c047..70fa540da 100644 --- a/packages/python-sdk/e2b/api/client/api/sandboxes/post_sandboxes.py +++ b/packages/python-sdk/e2b/api/client/api/sandboxes/post_sandboxes.py @@ -37,12 +37,12 @@ def _parse_response( response_201 = Sandbox.from_dict(response.json()) return response_201 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 if response.status_code == HTTPStatus.BAD_REQUEST: response_400 = cast(Any, None) return response_400 + if response.status_code == HTTPStatus.UNAUTHORIZED: + response_401 = cast(Any, None) + return response_401 if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: response_500 = cast(Any, None) return response_500 diff --git a/packages/python-sdk/e2b/api/client/api/templates/__init__.py b/packages/python-sdk/e2b/api/client/api/templates/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/python-sdk/e2b/api/client/api/templates/delete_templates_template_id.py b/packages/python-sdk/e2b/api/client/api/templates/delete_templates_template_id.py deleted file mode 100644 index d493420f3..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/delete_templates_template_id.py +++ /dev/null @@ -1,97 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...types import Response - - -def _get_kwargs( - template_id: str, -) -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { - "method": "delete", - "url": f"/templates/{template_id}", - } - - return _kwargs - - -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.NO_CONTENT: - return None - if response.status_code == HTTPStatus.UNAUTHORIZED: - return None - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - template_id: str, - *, - client: AuthenticatedClient, -) -> Response[Any]: - """Delete a template - - Args: - template_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[Any] - """ - - kwargs = _get_kwargs( - template_id=template_id, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -async def asyncio_detailed( - template_id: str, - *, - client: AuthenticatedClient, -) -> Response[Any]: - """Delete a template - - Args: - template_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[Any] - """ - - kwargs = _get_kwargs( - template_id=template_id, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) diff --git a/packages/python-sdk/e2b/api/client/api/templates/get_templates.py b/packages/python-sdk/e2b/api/client/api/templates/get_templates.py deleted file mode 100644 index d50150950..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/get_templates.py +++ /dev/null @@ -1,169 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.template import Template -from ...types import UNSET, Response, Unset - - -def _get_kwargs( - *, - team_id: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} - - params["teamID"] = team_id - - params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - - _kwargs: Dict[str, Any] = { - "method": "get", - "url": "/templates", - "params": params, - } - - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, List["Template"]]]: - if response.status_code == HTTPStatus.OK: - response_200 = [] - _response_200 = response.json() - for response_200_item_data in _response_200: - response_200_item = Template.from_dict(response_200_item_data) - - response_200.append(response_200_item) - - return response_200 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - response_500 = cast(Any, None) - return response_500 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, List["Template"]]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - *, - client: AuthenticatedClient, - team_id: Union[Unset, str] = UNSET, -) -> Response[Union[Any, List["Template"]]]: - """List all templates - - Args: - team_id (Union[Unset, str]): Identifier of the team - - 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[Union[Any, List['Template']]] - """ - - kwargs = _get_kwargs( - team_id=team_id, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - *, - client: AuthenticatedClient, - team_id: Union[Unset, str] = UNSET, -) -> Optional[Union[Any, List["Template"]]]: - """List all templates - - Args: - team_id (Union[Unset, str]): Identifier of the team - - 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: - Union[Any, List['Template']] - """ - - return sync_detailed( - client=client, - team_id=team_id, - ).parsed - - -async def asyncio_detailed( - *, - client: AuthenticatedClient, - team_id: Union[Unset, str] = UNSET, -) -> Response[Union[Any, List["Template"]]]: - """List all templates - - Args: - team_id (Union[Unset, str]): Identifier of the team - - 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[Union[Any, List['Template']]] - """ - - kwargs = _get_kwargs( - team_id=team_id, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - *, - client: AuthenticatedClient, - team_id: Union[Unset, str] = UNSET, -) -> Optional[Union[Any, List["Template"]]]: - """List all templates - - Args: - team_id (Union[Unset, str]): Identifier of the team - - 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: - Union[Any, List['Template']] - """ - - return ( - await asyncio_detailed( - client=client, - team_id=team_id, - ) - ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/templates/get_templates_template_id_builds_build_id_status.py b/packages/python-sdk/e2b/api/client/api/templates/get_templates_template_id_builds_build_id_status.py deleted file mode 100644 index 6918199ce..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/get_templates_template_id_builds_build_id_status.py +++ /dev/null @@ -1,193 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.template_build import TemplateBuild -from ...types import UNSET, Response, Unset - - -def _get_kwargs( - template_id: str, - build_id: str, - *, - logs_offset: Union[Unset, int] = 0, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} - - params["logsOffset"] = logs_offset - - params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - - _kwargs: Dict[str, Any] = { - "method": "get", - "url": f"/templates/{template_id}/builds/{build_id}/status", - "params": params, - } - - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, TemplateBuild]]: - if response.status_code == HTTPStatus.OK: - response_200 = TemplateBuild.from_dict(response.json()) - - return response_200 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 - if response.status_code == HTTPStatus.NOT_FOUND: - response_404 = cast(Any, None) - return response_404 - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - response_500 = cast(Any, None) - return response_500 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, TemplateBuild]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, - logs_offset: Union[Unset, int] = 0, -) -> Response[Union[Any, TemplateBuild]]: - """Get template build info - - Args: - template_id (str): - build_id (str): - logs_offset (Union[Unset, int]): Default: 0. - - 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[Union[Any, TemplateBuild]] - """ - - kwargs = _get_kwargs( - template_id=template_id, - build_id=build_id, - logs_offset=logs_offset, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, - logs_offset: Union[Unset, int] = 0, -) -> Optional[Union[Any, TemplateBuild]]: - """Get template build info - - Args: - template_id (str): - build_id (str): - logs_offset (Union[Unset, int]): Default: 0. - - 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: - Union[Any, TemplateBuild] - """ - - return sync_detailed( - template_id=template_id, - build_id=build_id, - client=client, - logs_offset=logs_offset, - ).parsed - - -async def asyncio_detailed( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, - logs_offset: Union[Unset, int] = 0, -) -> Response[Union[Any, TemplateBuild]]: - """Get template build info - - Args: - template_id (str): - build_id (str): - logs_offset (Union[Unset, int]): Default: 0. - - 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[Union[Any, TemplateBuild]] - """ - - kwargs = _get_kwargs( - template_id=template_id, - build_id=build_id, - logs_offset=logs_offset, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, - logs_offset: Union[Unset, int] = 0, -) -> Optional[Union[Any, TemplateBuild]]: - """Get template build info - - Args: - template_id (str): - build_id (str): - logs_offset (Union[Unset, int]): Default: 0. - - 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: - Union[Any, TemplateBuild] - """ - - return ( - await asyncio_detailed( - template_id=template_id, - build_id=build_id, - client=client, - logs_offset=logs_offset, - ) - ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/templates/post_templates.py b/packages/python-sdk/e2b/api/client/api/templates/post_templates.py deleted file mode 100644 index bf0e5bd2e..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/post_templates.py +++ /dev/null @@ -1,166 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.template import Template -from ...models.template_build_request import TemplateBuildRequest -from ...types import Response - - -def _get_kwargs( - *, - body: TemplateBuildRequest, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} - - _kwargs: Dict[str, Any] = { - "method": "post", - "url": "/templates", - } - - _body = body.to_dict() - - _kwargs["json"] = _body - headers["Content-Type"] = "application/json" - - _kwargs["headers"] = headers - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, Template]]: - if response.status_code == HTTPStatus.ACCEPTED: - response_202 = Template.from_dict(response.json()) - - return response_202 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - response_500 = cast(Any, None) - return response_500 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, Template]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Response[Union[Any, Template]]: - """Create a new template - - Args: - body (TemplateBuildRequest): - - 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[Union[Any, Template]] - """ - - kwargs = _get_kwargs( - body=body, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Optional[Union[Any, Template]]: - """Create a new template - - Args: - body (TemplateBuildRequest): - - 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: - Union[Any, Template] - """ - - return sync_detailed( - client=client, - body=body, - ).parsed - - -async def asyncio_detailed( - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Response[Union[Any, Template]]: - """Create a new template - - Args: - body (TemplateBuildRequest): - - 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[Union[Any, Template]] - """ - - kwargs = _get_kwargs( - body=body, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Optional[Union[Any, Template]]: - """Create a new template - - Args: - body (TemplateBuildRequest): - - 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: - Union[Any, Template] - """ - - return ( - await asyncio_detailed( - client=client, - body=body, - ) - ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id.py b/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id.py deleted file mode 100644 index 9221efb8f..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id.py +++ /dev/null @@ -1,179 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.template import Template -from ...models.template_build_request import TemplateBuildRequest -from ...types import Response - - -def _get_kwargs( - template_id: str, - *, - body: TemplateBuildRequest, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} - - _kwargs: Dict[str, Any] = { - "method": "post", - "url": f"/templates/{template_id}", - } - - _body = body.to_dict() - - _kwargs["json"] = _body - headers["Content-Type"] = "application/json" - - _kwargs["headers"] = headers - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, Template]]: - if response.status_code == HTTPStatus.ACCEPTED: - response_202 = Template.from_dict(response.json()) - - return response_202 - if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(Any, None) - return response_401 - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - response_500 = cast(Any, None) - return response_500 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, Template]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - template_id: str, - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Response[Union[Any, Template]]: - """Rebuild an template - - Args: - template_id (str): - body (TemplateBuildRequest): - - 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[Union[Any, Template]] - """ - - kwargs = _get_kwargs( - template_id=template_id, - body=body, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - template_id: str, - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Optional[Union[Any, Template]]: - """Rebuild an template - - Args: - template_id (str): - body (TemplateBuildRequest): - - 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: - Union[Any, Template] - """ - - return sync_detailed( - template_id=template_id, - client=client, - body=body, - ).parsed - - -async def asyncio_detailed( - template_id: str, - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Response[Union[Any, Template]]: - """Rebuild an template - - Args: - template_id (str): - body (TemplateBuildRequest): - - 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[Union[Any, Template]] - """ - - kwargs = _get_kwargs( - template_id=template_id, - body=body, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - template_id: str, - *, - client: AuthenticatedClient, - body: TemplateBuildRequest, -) -> Optional[Union[Any, Template]]: - """Rebuild an template - - Args: - template_id (str): - body (TemplateBuildRequest): - - 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: - Union[Any, Template] - """ - - return ( - await asyncio_detailed( - template_id=template_id, - client=client, - body=body, - ) - ).parsed diff --git a/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id_builds_build_id.py b/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id_builds_build_id.py deleted file mode 100644 index 67e21c739..000000000 --- a/packages/python-sdk/e2b/api/client/api/templates/post_templates_template_id_builds_build_id.py +++ /dev/null @@ -1,104 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, Optional, Union - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...types import Response - - -def _get_kwargs( - template_id: str, - build_id: str, -) -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { - "method": "post", - "url": f"/templates/{template_id}/builds/{build_id}", - } - - return _kwargs - - -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.ACCEPTED: - return None - if response.status_code == HTTPStatus.UNAUTHORIZED: - return None - if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, -) -> Response[Any]: - """Start the build - - Args: - template_id (str): - build_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[Any] - """ - - kwargs = _get_kwargs( - template_id=template_id, - build_id=build_id, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -async def asyncio_detailed( - template_id: str, - build_id: str, - *, - client: AuthenticatedClient, -) -> Response[Any]: - """Start the build - - Args: - template_id (str): - build_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[Any] - """ - - kwargs = _get_kwargs( - template_id=template_id, - build_id=build_id, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) diff --git a/packages/python-sdk/e2b/api/client/models/__init__.py b/packages/python-sdk/e2b/api/client/models/__init__.py index d55b958c2..ec61ba395 100644 --- a/packages/python-sdk/e2b/api/client/models/__init__.py +++ b/packages/python-sdk/e2b/api/client/models/__init__.py @@ -2,30 +2,44 @@ from .error import Error from .new_sandbox import NewSandbox +from .node import Node +from .node_detail import NodeDetail +from .node_status import NodeStatus +from .node_status_change import NodeStatusChange from .post_sandboxes_sandbox_id_refreshes_body import PostSandboxesSandboxIDRefreshesBody from .post_sandboxes_sandbox_id_timeout_body import PostSandboxesSandboxIDTimeoutBody +from .resumed_sandbox import ResumedSandbox from .running_sandbox import RunningSandbox from .sandbox import Sandbox from .sandbox_log import SandboxLog from .sandbox_logs import SandboxLogs from .team import Team +from .team_user import TeamUser from .template import Template from .template_build import TemplateBuild from .template_build_request import TemplateBuildRequest from .template_build_status import TemplateBuildStatus +from .template_update_request import TemplateUpdateRequest __all__ = ( "Error", "NewSandbox", + "Node", + "NodeDetail", + "NodeStatus", + "NodeStatusChange", "PostSandboxesSandboxIDRefreshesBody", "PostSandboxesSandboxIDTimeoutBody", + "ResumedSandbox", "RunningSandbox", "Sandbox", "SandboxLog", "SandboxLogs", "Team", + "TeamUser", "Template", "TemplateBuild", "TemplateBuildRequest", "TemplateBuildStatus", + "TemplateUpdateRequest", ) diff --git a/packages/python-sdk/e2b/api/client/models/new_sandbox.py b/packages/python-sdk/e2b/api/client/models/new_sandbox.py index 2094bb5a6..10cf61310 100644 --- a/packages/python-sdk/e2b/api/client/models/new_sandbox.py +++ b/packages/python-sdk/e2b/api/client/models/new_sandbox.py @@ -13,25 +13,25 @@ class NewSandbox: """ Attributes: template_id (str): Identifier of the required template - timeout (Union[Unset, int]): Time to live for the sandbox in seconds. Default: 15. - metadata (Union[Unset, Any]): env_vars (Union[Unset, Any]): + metadata (Union[Unset, Any]): + timeout (Union[Unset, int]): Time to live for the sandbox in seconds. Default: 15. """ template_id: str - timeout: Union[Unset, int] = 15 - metadata: Union[Unset, Any] = UNSET env_vars: Union[Unset, Any] = UNSET + metadata: Union[Unset, Any] = UNSET + timeout: Union[Unset, int] = 15 additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: template_id = self.template_id - timeout = self.timeout + env_vars = self.env_vars metadata = self.metadata - env_vars = self.env_vars + timeout = self.timeout field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) @@ -40,12 +40,12 @@ def to_dict(self) -> Dict[str, Any]: "templateID": template_id, } ) - if timeout is not UNSET: - field_dict["timeout"] = timeout - if metadata is not UNSET: - field_dict["metadata"] = metadata if env_vars is not UNSET: field_dict["envVars"] = env_vars + if metadata is not UNSET: + field_dict["metadata"] = metadata + if timeout is not UNSET: + field_dict["timeout"] = timeout return field_dict @@ -54,17 +54,17 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() template_id = d.pop("templateID") - timeout = d.pop("timeout", UNSET) + env_vars = d.pop("envVars", UNSET) metadata = d.pop("metadata", UNSET) - env_vars = d.pop("envVars", UNSET) + timeout = d.pop("timeout", UNSET) new_sandbox = cls( template_id=template_id, - timeout=timeout, - metadata=metadata, env_vars=env_vars, + metadata=metadata, + timeout=timeout, ) new_sandbox.additional_properties = d diff --git a/packages/python-sdk/e2b/api/client/models/running_sandbox.py b/packages/python-sdk/e2b/api/client/models/running_sandbox.py index 46c6757a6..c329511b5 100644 --- a/packages/python-sdk/e2b/api/client/models/running_sandbox.py +++ b/packages/python-sdk/e2b/api/client/models/running_sandbox.py @@ -14,43 +14,43 @@ class RunningSandbox: """ Attributes: - template_id (str): Identifier of the template from which is the sandbox created - sandbox_id (str): Identifier of the sandbox client_id (str): Identifier of the client - started_at (datetime.datetime): Time when the sandbox was started - end_at (datetime.datetime): Time when the sandbox will expire cpu_count (int): CPU cores for the sandbox + end_at (datetime.datetime): Time when the sandbox will expire memory_mb (int): Memory for the sandbox in MB + sandbox_id (str): Identifier of the sandbox + started_at (datetime.datetime): Time when the sandbox was started + template_id (str): Identifier of the template from which is the sandbox created alias (Union[Unset, str]): Alias of the template metadata (Union[Unset, Any]): """ - template_id: str - sandbox_id: str client_id: str - started_at: datetime.datetime - end_at: datetime.datetime cpu_count: int + end_at: datetime.datetime memory_mb: int + sandbox_id: str + started_at: datetime.datetime + template_id: str alias: Union[Unset, str] = UNSET metadata: Union[Unset, Any] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - template_id = self.template_id - - sandbox_id = self.sandbox_id - client_id = self.client_id - started_at = self.started_at.isoformat() + cpu_count = self.cpu_count end_at = self.end_at.isoformat() - cpu_count = self.cpu_count - memory_mb = self.memory_mb + sandbox_id = self.sandbox_id + + started_at = self.started_at.isoformat() + + template_id = self.template_id + alias = self.alias metadata = self.metadata @@ -59,13 +59,13 @@ def to_dict(self) -> Dict[str, Any]: field_dict.update(self.additional_properties) field_dict.update( { - "templateID": template_id, - "sandboxID": sandbox_id, "clientID": client_id, - "startedAt": started_at, - "endAt": end_at, "cpuCount": cpu_count, + "endAt": end_at, "memoryMB": memory_mb, + "sandboxID": sandbox_id, + "startedAt": started_at, + "templateID": template_id, } ) if alias is not UNSET: @@ -78,32 +78,32 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - template_id = d.pop("templateID") - - sandbox_id = d.pop("sandboxID") - client_id = d.pop("clientID") - started_at = isoparse(d.pop("startedAt")) + cpu_count = d.pop("cpuCount") end_at = isoparse(d.pop("endAt")) - cpu_count = d.pop("cpuCount") - memory_mb = d.pop("memoryMB") + sandbox_id = d.pop("sandboxID") + + started_at = isoparse(d.pop("startedAt")) + + template_id = d.pop("templateID") + alias = d.pop("alias", UNSET) metadata = d.pop("metadata", UNSET) running_sandbox = cls( - template_id=template_id, - sandbox_id=sandbox_id, client_id=client_id, - started_at=started_at, - end_at=end_at, cpu_count=cpu_count, + end_at=end_at, memory_mb=memory_mb, + sandbox_id=sandbox_id, + started_at=started_at, + template_id=template_id, alias=alias, metadata=metadata, ) diff --git a/packages/python-sdk/e2b/api/client/models/sandbox.py b/packages/python-sdk/e2b/api/client/models/sandbox.py index a331e9a6b..baf5b4890 100644 --- a/packages/python-sdk/e2b/api/client/models/sandbox.py +++ b/packages/python-sdk/e2b/api/client/models/sandbox.py @@ -12,39 +12,39 @@ class Sandbox: """ Attributes: - template_id (str): Identifier of the template from which is the sandbox created - sandbox_id (str): Identifier of the sandbox client_id (str): Identifier of the client envd_version (str): Version of the envd running in the sandbox + sandbox_id (str): Identifier of the sandbox + template_id (str): Identifier of the template from which is the sandbox created alias (Union[Unset, str]): Alias of the template """ - template_id: str - sandbox_id: str client_id: str envd_version: str + sandbox_id: str + template_id: str alias: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - template_id = self.template_id - - sandbox_id = self.sandbox_id - client_id = self.client_id envd_version = self.envd_version + sandbox_id = self.sandbox_id + + template_id = self.template_id + alias = self.alias field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { - "templateID": template_id, - "sandboxID": sandbox_id, "clientID": client_id, "envdVersion": envd_version, + "sandboxID": sandbox_id, + "templateID": template_id, } ) if alias is not UNSET: @@ -55,21 +55,21 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - template_id = d.pop("templateID") - - sandbox_id = d.pop("sandboxID") - client_id = d.pop("clientID") envd_version = d.pop("envdVersion") + sandbox_id = d.pop("sandboxID") + + template_id = d.pop("templateID") + alias = d.pop("alias", UNSET) sandbox = cls( - template_id=template_id, - sandbox_id=sandbox_id, client_id=client_id, envd_version=envd_version, + sandbox_id=sandbox_id, + template_id=template_id, alias=alias, ) diff --git a/packages/python-sdk/e2b/api/client/models/sandbox_log.py b/packages/python-sdk/e2b/api/client/models/sandbox_log.py index 3e5dc9cfa..44c990e9a 100644 --- a/packages/python-sdk/e2b/api/client/models/sandbox_log.py +++ b/packages/python-sdk/e2b/api/client/models/sandbox_log.py @@ -13,25 +13,25 @@ class SandboxLog: """Log entry with timestamp and line Attributes: - timestamp (datetime.datetime): Timestamp of the log entry line (str): Log line content + timestamp (datetime.datetime): Timestamp of the log entry """ - timestamp: datetime.datetime line: str + timestamp: datetime.datetime additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - timestamp = self.timestamp.isoformat() - line = self.line + timestamp = self.timestamp.isoformat() + field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { - "timestamp": timestamp, "line": line, + "timestamp": timestamp, } ) @@ -40,13 +40,13 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - timestamp = isoparse(d.pop("timestamp")) - line = d.pop("line") + timestamp = isoparse(d.pop("timestamp")) + sandbox_log = cls( - timestamp=timestamp, line=line, + timestamp=timestamp, ) sandbox_log.additional_properties = d diff --git a/packages/python-sdk/e2b/api/client/models/team.py b/packages/python-sdk/e2b/api/client/models/team.py index 38cc16a8d..c957f9384 100644 --- a/packages/python-sdk/e2b/api/client/models/team.py +++ b/packages/python-sdk/e2b/api/client/models/team.py @@ -10,35 +10,35 @@ class Team: """ Attributes: - team_id (str): Identifier of the team - name (str): Name of the team api_key (str): API key for the team is_default (bool): Whether the team is the default team + name (str): Name of the team + team_id (str): Identifier of the team """ - team_id: str - name: str api_key: str is_default: bool + name: str + team_id: str additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - team_id = self.team_id - - name = self.name - api_key = self.api_key is_default = self.is_default + name = self.name + + team_id = self.team_id + field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { - "teamID": team_id, - "name": name, "apiKey": api_key, "isDefault": is_default, + "name": name, + "teamID": team_id, } ) @@ -47,19 +47,19 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - team_id = d.pop("teamID") - - name = d.pop("name") - api_key = d.pop("apiKey") is_default = d.pop("isDefault") + name = d.pop("name") + + team_id = d.pop("teamID") + team = cls( - team_id=team_id, - name=name, api_key=api_key, is_default=is_default, + name=name, + team_id=team_id, ) team.additional_properties = d diff --git a/packages/python-sdk/e2b/api/client/models/template.py b/packages/python-sdk/e2b/api/client/models/template.py index 7120815e2..7e76153e9 100644 --- a/packages/python-sdk/e2b/api/client/models/template.py +++ b/packages/python-sdk/e2b/api/client/models/template.py @@ -1,10 +1,16 @@ -from typing import Any, Dict, List, Type, TypeVar, Union, cast +import datetime +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast from attrs import define as _attrs_define from attrs import field as _attrs_field +from dateutil.parser import isoparse from ..types import UNSET, Unset +if TYPE_CHECKING: + from ..models.team_user import TeamUser + + T = TypeVar("T", bound="Template") @@ -12,33 +18,63 @@ class Template: """ Attributes: - template_id (str): Identifier of the template + build_count (int): Number of times the template was built build_id (str): Identifier of the last successful build for given template cpu_count (int): CPU cores for the sandbox + created_at (datetime.datetime): Time when the template was created + created_by (Union['TeamUser', None]): + last_spawned_at (datetime.datetime): Time when the template was last used memory_mb (int): Memory for the sandbox in MB public (bool): Whether the template is public or only accessible by the team + spawn_count (int): Number of times the template was used + template_id (str): Identifier of the template + updated_at (datetime.datetime): Time when the template was last updated aliases (Union[Unset, List[str]]): Aliases of the template """ - template_id: str + build_count: int build_id: str cpu_count: int + created_at: datetime.datetime + created_by: Union["TeamUser", None] + last_spawned_at: datetime.datetime memory_mb: int public: bool + spawn_count: int + template_id: str + updated_at: datetime.datetime aliases: Union[Unset, List[str]] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - template_id = self.template_id + from ..models.team_user import TeamUser + + build_count = self.build_count build_id = self.build_id cpu_count = self.cpu_count + created_at = self.created_at.isoformat() + + created_by: Union[Dict[str, Any], None] + if isinstance(self.created_by, TeamUser): + created_by = self.created_by.to_dict() + else: + created_by = self.created_by + + last_spawned_at = self.last_spawned_at.isoformat() + memory_mb = self.memory_mb public = self.public + spawn_count = self.spawn_count + + template_id = self.template_id + + updated_at = self.updated_at.isoformat() + aliases: Union[Unset, List[str]] = UNSET if not isinstance(self.aliases, Unset): aliases = self.aliases @@ -47,11 +83,17 @@ def to_dict(self) -> Dict[str, Any]: field_dict.update(self.additional_properties) field_dict.update( { - "templateID": template_id, + "buildCount": build_count, "buildID": build_id, "cpuCount": cpu_count, + "createdAt": created_at, + "createdBy": created_by, + "lastSpawnedAt": last_spawned_at, "memoryMB": memory_mb, "public": public, + "spawnCount": spawn_count, + "templateID": template_id, + "updatedAt": updated_at, } ) if aliases is not UNSET: @@ -61,25 +103,58 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.team_user import TeamUser + d = src_dict.copy() - template_id = d.pop("templateID") + build_count = d.pop("buildCount") build_id = d.pop("buildID") cpu_count = d.pop("cpuCount") + created_at = isoparse(d.pop("createdAt")) + + def _parse_created_by(data: object) -> Union["TeamUser", None]: + if data is None: + return data + try: + if not isinstance(data, dict): + raise TypeError() + created_by_type_1 = TeamUser.from_dict(data) + + return created_by_type_1 + except: # noqa: E722 + pass + return cast(Union["TeamUser", None], data) + + created_by = _parse_created_by(d.pop("createdBy")) + + last_spawned_at = isoparse(d.pop("lastSpawnedAt")) + memory_mb = d.pop("memoryMB") public = d.pop("public") + spawn_count = d.pop("spawnCount") + + template_id = d.pop("templateID") + + updated_at = isoparse(d.pop("updatedAt")) + aliases = cast(List[str], d.pop("aliases", UNSET)) template = cls( - template_id=template_id, + build_count=build_count, build_id=build_id, cpu_count=cpu_count, + created_at=created_at, + created_by=created_by, + last_spawned_at=last_spawned_at, memory_mb=memory_mb, public=public, + spawn_count=spawn_count, + template_id=template_id, + updated_at=updated_at, aliases=aliases, ) diff --git a/packages/python-sdk/e2b/api/client/models/template_build.py b/packages/python-sdk/e2b/api/client/models/template_build.py index 082e96ac3..ed05e1114 100644 --- a/packages/python-sdk/e2b/api/client/models/template_build.py +++ b/packages/python-sdk/e2b/api/client/models/template_build.py @@ -12,35 +12,35 @@ class TemplateBuild: """ Attributes: - logs (List[str]): Build logs - template_id (str): Identifier of the template build_id (str): Identifier of the build + logs (List[str]): Build logs status (TemplateBuildStatus): Status of the template + template_id (str): Identifier of the template """ - logs: List[str] - template_id: str build_id: str + logs: List[str] status: TemplateBuildStatus + template_id: str additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - logs = self.logs - - template_id = self.template_id - build_id = self.build_id + logs = self.logs + status = self.status.value + template_id = self.template_id + field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { - "logs": logs, - "templateID": template_id, "buildID": build_id, + "logs": logs, "status": status, + "templateID": template_id, } ) @@ -49,19 +49,19 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - logs = cast(List[str], d.pop("logs")) - - template_id = d.pop("templateID") - build_id = d.pop("buildID") + logs = cast(List[str], d.pop("logs")) + status = TemplateBuildStatus(d.pop("status")) + template_id = d.pop("templateID") + template_build = cls( - logs=logs, - template_id=template_id, build_id=build_id, + logs=logs, status=status, + template_id=template_id, ) template_build.additional_properties = d diff --git a/packages/python-sdk/e2b/api/client/models/template_build_request.py b/packages/python-sdk/e2b/api/client/models/template_build_request.py index d93c68fb6..08ac58490 100644 --- a/packages/python-sdk/e2b/api/client/models/template_build_request.py +++ b/packages/python-sdk/e2b/api/client/models/template_build_request.py @@ -14,18 +14,18 @@ class TemplateBuildRequest: Attributes: dockerfile (str): Dockerfile for the template alias (Union[Unset, str]): Alias of the template - team_id (Union[Unset, str]): Identifier of the team - start_cmd (Union[Unset, str]): Start command to execute in the template after the build cpu_count (Union[Unset, int]): CPU cores for the sandbox memory_mb (Union[Unset, int]): Memory for the sandbox in MB + start_cmd (Union[Unset, str]): Start command to execute in the template after the build + team_id (Union[Unset, str]): Identifier of the team """ dockerfile: str alias: Union[Unset, str] = UNSET - team_id: Union[Unset, str] = UNSET - start_cmd: Union[Unset, str] = UNSET cpu_count: Union[Unset, int] = UNSET memory_mb: Union[Unset, int] = UNSET + start_cmd: Union[Unset, str] = UNSET + team_id: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: @@ -33,14 +33,14 @@ def to_dict(self) -> Dict[str, Any]: alias = self.alias - team_id = self.team_id - - start_cmd = self.start_cmd - cpu_count = self.cpu_count memory_mb = self.memory_mb + start_cmd = self.start_cmd + + team_id = self.team_id + field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( @@ -50,14 +50,14 @@ def to_dict(self) -> Dict[str, Any]: ) if alias is not UNSET: field_dict["alias"] = alias - if team_id is not UNSET: - field_dict["teamID"] = team_id - if start_cmd is not UNSET: - field_dict["startCmd"] = start_cmd if cpu_count is not UNSET: field_dict["cpuCount"] = cpu_count if memory_mb is not UNSET: field_dict["memoryMB"] = memory_mb + if start_cmd is not UNSET: + field_dict["startCmd"] = start_cmd + if team_id is not UNSET: + field_dict["teamID"] = team_id return field_dict @@ -68,21 +68,21 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: alias = d.pop("alias", UNSET) - team_id = d.pop("teamID", UNSET) - - start_cmd = d.pop("startCmd", UNSET) - cpu_count = d.pop("cpuCount", UNSET) memory_mb = d.pop("memoryMB", UNSET) + start_cmd = d.pop("startCmd", UNSET) + + team_id = d.pop("teamID", UNSET) + template_build_request = cls( dockerfile=dockerfile, alias=alias, - team_id=team_id, - start_cmd=start_cmd, cpu_count=cpu_count, memory_mb=memory_mb, + start_cmd=start_cmd, + team_id=team_id, ) template_build_request.additional_properties = d diff --git a/spec/openapi.yml b/spec/openapi.yml index 17a1db854..32bbc8763 100644 --- a/spec/openapi.yml +++ b/spec/openapi.yml @@ -16,6 +16,10 @@ components: type: http scheme: bearer bearerFormat: access_token + AdminTokenAuth: + type: apiKey + in: header + name: X-Admin-Token parameters: templateID: @@ -36,6 +40,12 @@ components: required: true schema: type: string + nodeID: + name: nodeID + in: path + required: true + schema: + type: string responses: "400": @@ -56,7 +66,12 @@ components: application/json: schema: $ref: "#/components/schemas/Error" - + "409": + description: Conflict + content: + application/json: + schema: + $ref: "#/components/schemas/Error" "500": description: Server error content: @@ -230,6 +245,15 @@ components: envVars: $ref: "#/components/schemas/EnvVars" + ResumedSandbox: + properties: + timeout: + type: integer + format: int32 + minimum: 0 + default: 15 + description: Time to live for the sandbox in seconds. + Template: required: - templateID @@ -335,6 +359,70 @@ components: - ready - error + NodeStatus: + type: string + description: Status of the node + enum: + - ready + - draining + + NodeStatusChange: + required: + - status + properties: + status: + $ref: "#/components/schemas/NodeStatus" + + Node: + required: + - nodeID + - status + - sandboxCount + - allocatedCPU + - allocatedMemoryMiB + properties: + nodeID: + type: string + description: Identifier of the node + status: + $ref: "#/components/schemas/NodeStatus" + sandboxCount: + type: integer + format: int32 + description: Number of sandboxes running on the node + allocatedCPU: + type: integer + format: int32 + description: Number of allocated CPU cores + allocatedMemoryMiB: + type: integer + format: int32 + description: Amount of allocated memory in MiB + + NodeDetail: + required: + - nodeID + - status + - sandboxes + - cachedBuilds + properties: + nodeID: + type: string + description: Identifier of the node + status: + $ref: "#/components/schemas/NodeStatus" + sandboxes: + type: array + description: List of sandboxes running on the node + items: + $ref: "#/components/schemas/RunningSandbox" + cachedBuilds: + type: array + description: List of cached builds id on the node + items: + type: string + + Error: required: - code @@ -390,6 +478,15 @@ paths: tags: [sandboxes] security: - ApiKeyAuth: [] + parameters: + - name: filter + in: query + description: A list of filters with key-value pairs (e.g. user:abc, app:prod). + required: false + schema: + type: array + items: + type: string responses: "200": description: Successfully returned all running sandboxes @@ -469,6 +566,27 @@ paths: $ref: "#/components/responses/500" /sandboxes/{sandboxID}: + get: + description: Get a sandbox by id + tags: [sandboxes] + security: + - ApiKeyAuth: [] + parameters: + - $ref: "#/components/parameters/sandboxID" + responses: + "200": + description: Successfully returned the sandbox + content: + application/json: + schema: + $ref: "#/components/schemas/RunningSandbox" + "404": + $ref: "#/components/responses/404" + "401": + $ref: "#/components/responses/401" + "500": + $ref: "#/components/responses/500" + delete: description: Kill a sandbox tags: [sandboxes] @@ -486,6 +604,57 @@ paths: "500": $ref: "#/components/responses/500" + # TODO: Pause and resume might be exposed as POST /sandboxes/{sandboxID}/snapshot and then POST /sandboxes with specified snapshotting setup + /sandboxes/{sandboxID}/pause: + post: + description: Pause the sandbox + tags: [sandboxes] + security: + - ApiKeyAuth: [] + parameters: + - $ref: "#/components/parameters/sandboxID" + responses: + "204": + description: The sandbox was paused successfully and can be resumed + "409": + $ref: "#/components/responses/409" + "404": + $ref: "#/components/responses/404" + "401": + $ref: "#/components/responses/401" + "500": + $ref: "#/components/responses/500" + + /sandboxes/{sandboxID}/resume: + post: + description: Resume the sandbox + tags: [sandboxes] + security: + - ApiKeyAuth: [] + parameters: + - $ref: "#/components/parameters/sandboxID" + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ResumedSandbox" + responses: + "201": + description: The sandbox was resumed successfully + content: + application/json: + schema: + $ref: "#/components/schemas/Sandbox" + "409": + $ref: "#/components/responses/409" + "404": + $ref: "#/components/responses/404" + "401": + $ref: "#/components/responses/401" + "500": + $ref: "#/components/responses/500" + /sandboxes/{sandboxID}/timeout: post: description: Set the timeout for the sandbox. The sandbox will expire x seconds from the time of the request. Calling this method multiple times overwrites the TTL, each time using the current timestamp as the starting point to measure the timeout duration. @@ -705,3 +874,67 @@ paths: $ref: "#/components/responses/404" "500": $ref: "#/components/responses/500" + + /nodes: + get: + description: List all nodes + tags: [admin] + security: + - AdminTokenAuth: [] + responses: + "200": + description: Successfully returned all nodes + content: + application/json: + schema: + type: array + items: + allOf: + - $ref: "#/components/schemas/Node" + "401": + $ref: "#/components/responses/401" + "500": + $ref: "#/components/responses/500" + + /nodes/{nodeID}: + get: + description: Get node info + tags: [admin] + security: + - AdminTokenAuth: [] + parameters: + - $ref: "#/components/parameters/nodeID" + responses: + "200": + description: Successfully returned the node + content: + application/json: + schema: + $ref: "#/components/schemas/NodeDetail" + "401": + $ref: "#/components/responses/401" + "404": + $ref: "#/components/responses/404" + "500": + $ref: "#/components/responses/500" + post: + description: Change status of a node + tags: [admin] + security: + - AdminTokenAuth: [] + parameters: + - $ref: "#/components/parameters/nodeID" + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/NodeStatusChange" + responses: + "204": + description: The node status was changed successfully + "401": + $ref: "#/components/responses/401" + "404": + $ref: "#/components/responses/404" + "500": + $ref: "#/components/responses/500" \ No newline at end of file diff --git a/spec/remove_extra_tags.py b/spec/remove_extra_tags.py new file mode 100644 index 000000000..387052d63 --- /dev/null +++ b/spec/remove_extra_tags.py @@ -0,0 +1,35 @@ +import os +import sys + +import yaml + +# Get directory of this script +directory = os.path.dirname(os.path.abspath(__file__)) +path = os.path.join(directory, "openapi.yml") + +# Load OpenAPI spec +with open(path, "r") as file: + spec = yaml.safe_load(file) + +tags_to_keep = sys.argv[1:] if len(sys.argv) > 1 else None +filtered_paths = {} + +for path, methods in spec.get("paths", {}).items(): + for method, operation in methods.items(): + if "tags" in operation: + for tag in tags_to_keep: + if tag in operation["tags"]: + if path in filtered_paths: + filtered_paths[path][method] = operation + else: + filtered_paths[path] = {method: operation} + break + + +# Create a new spec with only the filtered paths +filtered_spec = spec.copy() +filtered_spec["paths"] = filtered_paths + +# Save the filtered spec +with open(os.path.join(directory, "openapi_generated.yml"), "w") as file: + yaml.dump(filtered_spec, file)