Skip to content

Commit 9e87387

Browse files
committed
Refactor backup and restore operations into graph operations module
This commit removes the existing `create_backup.py` and `restore_backup.py` files and introduces new modules under `graph_operations` for handling backup and restore operations. The new structure enhances organization and aligns with the overall architecture of the API. Key Changes: - Deleted `create_backup.py` and `restore_backup.py`. - Added `op_create_backup.py` and `op_restore_backup.py` to `graph_operations` for improved modularity. - Updated response handling and request structures to support new operation envelopes and error models. This refactor aims to streamline the backup and restore processes, making them more consistent with other graph operations.
1 parent 30a34cc commit 9e87387

29 files changed

Lines changed: 2042 additions & 3464 deletions

‎robosystems_client/api/backup/create_backup.py‎

Lines changed: 0 additions & 445 deletions
This file was deleted.

‎robosystems_client/api/backup/restore_backup.py‎

Lines changed: 0 additions & 479 deletions
This file was deleted.
File renamed without changes.
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
from http import HTTPStatus
2+
from typing import Any, cast
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.backup_create_request import BackupCreateRequest
10+
from ...models.http_validation_error import HTTPValidationError
11+
from ...models.operation_envelope import OperationEnvelope
12+
from ...models.operation_error import OperationError
13+
from ...types import UNSET, Response, Unset
14+
15+
16+
def _get_kwargs(
17+
graph_id: str,
18+
*,
19+
body: BackupCreateRequest,
20+
idempotency_key: None | str | Unset = UNSET,
21+
) -> dict[str, Any]:
22+
headers: dict[str, Any] = {}
23+
if not isinstance(idempotency_key, Unset):
24+
headers["Idempotency-Key"] = idempotency_key
25+
26+
_kwargs: dict[str, Any] = {
27+
"method": "post",
28+
"url": "/v1/graphs/{graph_id}/operations/create-backup".format(
29+
graph_id=quote(str(graph_id), safe=""),
30+
),
31+
}
32+
33+
_kwargs["json"] = body.to_dict()
34+
35+
headers["Content-Type"] = "application/json"
36+
37+
_kwargs["headers"] = headers
38+
return _kwargs
39+
40+
41+
def _parse_response(
42+
*, client: AuthenticatedClient | Client, response: httpx.Response
43+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
44+
if response.status_code == 202:
45+
response_202 = OperationEnvelope.from_dict(response.json())
46+
47+
return response_202
48+
49+
if response.status_code == 400:
50+
response_400 = OperationError.from_dict(response.json())
51+
52+
return response_400
53+
54+
if response.status_code == 401:
55+
response_401 = cast(Any, None)
56+
return response_401
57+
58+
if response.status_code == 403:
59+
response_403 = cast(Any, None)
60+
return response_403
61+
62+
if response.status_code == 404:
63+
response_404 = OperationError.from_dict(response.json())
64+
65+
return response_404
66+
67+
if response.status_code == 409:
68+
response_409 = OperationError.from_dict(response.json())
69+
70+
return response_409
71+
72+
if response.status_code == 422:
73+
response_422 = HTTPValidationError.from_dict(response.json())
74+
75+
return response_422
76+
77+
if response.status_code == 429:
78+
response_429 = cast(Any, None)
79+
return response_429
80+
81+
if response.status_code == 500:
82+
response_500 = cast(Any, None)
83+
return response_500
84+
85+
if client.raise_on_unexpected_status:
86+
raise errors.UnexpectedStatus(response.status_code, response.content)
87+
else:
88+
return None
89+
90+
91+
def _build_response(
92+
*, client: AuthenticatedClient | Client, response: httpx.Response
93+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
94+
return Response(
95+
status_code=HTTPStatus(response.status_code),
96+
content=response.content,
97+
headers=response.headers,
98+
parsed=_parse_response(client=client, response=response),
99+
)
100+
101+
102+
def sync_detailed(
103+
graph_id: str,
104+
*,
105+
client: AuthenticatedClient,
106+
body: BackupCreateRequest,
107+
idempotency_key: None | str | Unset = UNSET,
108+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
109+
"""Create Backup
110+
111+
Create a backup of the graph database (async).
112+
113+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
114+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
115+
116+
Args:
117+
graph_id (str):
118+
idempotency_key (None | str | Unset):
119+
body (BackupCreateRequest): Request model for creating a backup.
120+
121+
Raises:
122+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123+
httpx.TimeoutException: If the request takes longer than Client.timeout.
124+
125+
Returns:
126+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
127+
"""
128+
129+
kwargs = _get_kwargs(
130+
graph_id=graph_id,
131+
body=body,
132+
idempotency_key=idempotency_key,
133+
)
134+
135+
response = client.get_httpx_client().request(
136+
**kwargs,
137+
)
138+
139+
return _build_response(client=client, response=response)
140+
141+
142+
def sync(
143+
graph_id: str,
144+
*,
145+
client: AuthenticatedClient,
146+
body: BackupCreateRequest,
147+
idempotency_key: None | str | Unset = UNSET,
148+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
149+
"""Create Backup
150+
151+
Create a backup of the graph database (async).
152+
153+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
154+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
155+
156+
Args:
157+
graph_id (str):
158+
idempotency_key (None | str | Unset):
159+
body (BackupCreateRequest): Request model for creating a backup.
160+
161+
Raises:
162+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
163+
httpx.TimeoutException: If the request takes longer than Client.timeout.
164+
165+
Returns:
166+
Any | HTTPValidationError | OperationEnvelope | OperationError
167+
"""
168+
169+
return sync_detailed(
170+
graph_id=graph_id,
171+
client=client,
172+
body=body,
173+
idempotency_key=idempotency_key,
174+
).parsed
175+
176+
177+
async def asyncio_detailed(
178+
graph_id: str,
179+
*,
180+
client: AuthenticatedClient,
181+
body: BackupCreateRequest,
182+
idempotency_key: None | str | Unset = UNSET,
183+
) -> Response[Any | HTTPValidationError | OperationEnvelope | OperationError]:
184+
"""Create Backup
185+
186+
Create a backup of the graph database (async).
187+
188+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
189+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
190+
191+
Args:
192+
graph_id (str):
193+
idempotency_key (None | str | Unset):
194+
body (BackupCreateRequest): Request model for creating a backup.
195+
196+
Raises:
197+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
198+
httpx.TimeoutException: If the request takes longer than Client.timeout.
199+
200+
Returns:
201+
Response[Any | HTTPValidationError | OperationEnvelope | OperationError]
202+
"""
203+
204+
kwargs = _get_kwargs(
205+
graph_id=graph_id,
206+
body=body,
207+
idempotency_key=idempotency_key,
208+
)
209+
210+
response = await client.get_async_httpx_client().request(**kwargs)
211+
212+
return _build_response(client=client, response=response)
213+
214+
215+
async def asyncio(
216+
graph_id: str,
217+
*,
218+
client: AuthenticatedClient,
219+
body: BackupCreateRequest,
220+
idempotency_key: None | str | Unset = UNSET,
221+
) -> Any | HTTPValidationError | OperationEnvelope | OperationError | None:
222+
"""Create Backup
223+
224+
Create a backup of the graph database (async).
225+
226+
**Idempotency**: supply an `Idempotency-Key` header to make safe retries; replays within 24 hours
227+
return the same envelope. Reusing the key with a different body returns HTTP 409 Conflict.
228+
229+
Args:
230+
graph_id (str):
231+
idempotency_key (None | str | Unset):
232+
body (BackupCreateRequest): Request model for creating a backup.
233+
234+
Raises:
235+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
236+
httpx.TimeoutException: If the request takes longer than Client.timeout.
237+
238+
Returns:
239+
Any | HTTPValidationError | OperationEnvelope | OperationError
240+
"""
241+
242+
return (
243+
await asyncio_detailed(
244+
graph_id=graph_id,
245+
client=client,
246+
body=body,
247+
idempotency_key=idempotency_key,
248+
)
249+
).parsed

0 commit comments

Comments
 (0)