|
18 | 18 |
|
19 | 19 | from iib.exceptions import ValidationError
|
20 | 20 | from iib.web import db
|
21 |
| - |
| 21 | +from iib.web.pydantic_models import ( |
| 22 | + AddPydanticModel, |
| 23 | + CreateEmptyIndexPydanticModel, |
| 24 | + FbcOperationsPydanticModel, |
| 25 | + MergeIndexImagePydanticModel, |
| 26 | + RecursiveRelatedBundlesPydanticModel, |
| 27 | + RegenerateBundlePydanticModel, |
| 28 | + RmPydanticModel, |
| 29 | +) |
22 | 30 |
|
23 | 31 | from iib.web.iib_static_types import (
|
24 | 32 | AddRequestPayload,
|
@@ -1002,6 +1010,20 @@ def _from_json(
|
1002 | 1010 | db.session.add(batch)
|
1003 | 1011 | request_kwargs['batch'] = batch
|
1004 | 1012 |
|
| 1013 | + @staticmethod |
| 1014 | + def from_json_replacement( |
| 1015 | + request_kwargs: RequestPayload, |
| 1016 | + batch: Optional[Batch] = None, |
| 1017 | + ): |
| 1018 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 1019 | + if current_user.is_authenticated: |
| 1020 | + request_kwargs['user'] = current_user |
| 1021 | + |
| 1022 | + # Add the request to a new batch |
| 1023 | + batch = batch or Batch() |
| 1024 | + db.session.add(batch) |
| 1025 | + request_kwargs['batch'] = batch |
| 1026 | + |
1005 | 1027 | def get_common_index_image_json(self) -> CommonIndexImageResponseBase:
|
1006 | 1028 | """
|
1007 | 1029 | Return the common set of attributes for an index image request.
|
@@ -1177,6 +1199,50 @@ def from_json( # type: ignore[override] # noqa: F821
|
1177 | 1199 | request.add_state('in_progress', 'The request was initiated')
|
1178 | 1200 | return request
|
1179 | 1201 |
|
| 1202 | + def from_json_replacement( |
| 1203 | + cls, |
| 1204 | + payload: AddPydanticModel, |
| 1205 | + batch: Optional[Batch] = None, |
| 1206 | + ): |
| 1207 | + """ |
| 1208 | + Handle JSON requests for the builds/add API endpoint. |
| 1209 | +
|
| 1210 | + :param AddPydanticModel payload: the Pydantic model representing the request. |
| 1211 | + :param Batch batch: the batch to specify with the request. |
| 1212 | + """ |
| 1213 | + request_kwargs = payload.get_json_for_request() |
| 1214 | + |
| 1215 | + # setup user and batch in request |
| 1216 | + # cls.from_json_replacement( |
| 1217 | + # cast(RequestPayload, request_kwargs), |
| 1218 | + # batch=batch, |
| 1219 | + # ) |
| 1220 | + |
| 1221 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 1222 | + if current_user.is_authenticated: |
| 1223 | + request_kwargs['user'] = current_user |
| 1224 | + |
| 1225 | + # Add the request to a new batch |
| 1226 | + batch = batch or Batch() |
| 1227 | + db.session.add(batch) |
| 1228 | + request_kwargs['batch'] = batch |
| 1229 | + |
| 1230 | + |
| 1231 | + request_kwargs["bundles"] = [ |
| 1232 | + Image.get_or_create(pull_specification=item) for item in payload.bundles |
| 1233 | + ] |
| 1234 | + request_kwargs["deprecation_list"] = [ |
| 1235 | + Image.get_or_create(pull_specification=item) for item in payload.deprecation_list |
| 1236 | + ] |
| 1237 | + |
| 1238 | + request = cls(**request_kwargs) |
| 1239 | + |
| 1240 | + for bt in payload.build_tags: |
| 1241 | + request.add_build_tag(bt) |
| 1242 | + |
| 1243 | + request.add_state('in_progress', 'The request was initiated') |
| 1244 | + return request |
| 1245 | + |
1180 | 1246 | def to_json(self, verbose: Optional[bool] = True) -> AddRequestResponse:
|
1181 | 1247 | """
|
1182 | 1248 | Provide the JSON representation of an "add" build request.
|
@@ -1276,6 +1342,38 @@ def from_json( # type: ignore[override] # noqa: F821
|
1276 | 1342 |
|
1277 | 1343 | return request
|
1278 | 1344 |
|
| 1345 | + def from_json_replacement( |
| 1346 | + cls, |
| 1347 | + payload: RmPydanticModel, |
| 1348 | + batch: Optional[Batch] = None, |
| 1349 | + ): |
| 1350 | + """ |
| 1351 | + Handle JSON requests for the builds/rm API endpoint. |
| 1352 | +
|
| 1353 | + :param RmPydanticModel payload: the Pydantic model representing the request. |
| 1354 | + :param Batch batch: the batch to specify with the request. |
| 1355 | + """ |
| 1356 | + request_kwargs = payload.get_json_for_request() |
| 1357 | + |
| 1358 | + request_kwargs['operators'] = [Operator.get_or_create(name=item) for item in payload.operators] |
| 1359 | + request_kwargs['from_index'] = Image.get_or_create(pull_specification=request_kwargs['from_index']) |
| 1360 | + |
| 1361 | + if current_user.is_authenticated: |
| 1362 | + request_kwargs['user'] = current_user |
| 1363 | + |
| 1364 | + # Add the request to a new batch |
| 1365 | + batch = batch or Batch() |
| 1366 | + db.session.add(batch) |
| 1367 | + request_kwargs['batch'] = batch |
| 1368 | + |
| 1369 | + request = cls(**request_kwargs) |
| 1370 | + request.add_state('in_progress', 'The request was initiated') |
| 1371 | + |
| 1372 | + for bt in payload.build_tags: |
| 1373 | + request.add_build_tag(bt) |
| 1374 | + |
| 1375 | + return request |
| 1376 | + |
1279 | 1377 | def to_json(self, verbose: Optional[bool] = True) -> AddRmRequestResponseBase:
|
1280 | 1378 | """
|
1281 | 1379 | Provide the JSON representation of an "rm" build request.
|
@@ -1422,6 +1520,36 @@ def from_json( # type: ignore[override] # noqa: F821
|
1422 | 1520 | request.add_state('in_progress', 'The request was initiated')
|
1423 | 1521 | return request
|
1424 | 1522 |
|
| 1523 | + def from_json_replacement( |
| 1524 | + cls, |
| 1525 | + payload: RegenerateBundlePydanticModel, |
| 1526 | + batch: Optional[Batch] = None, |
| 1527 | + ): |
| 1528 | + """ |
| 1529 | + Handle JSON requests for the builds/egenerate-bundle API endpoint. |
| 1530 | +
|
| 1531 | + :param RegenerateBundlePydanticModel payload: the Pydantic model representing the request. |
| 1532 | + :param Batch batch: the batch to specify with the request. |
| 1533 | + """ |
| 1534 | + request_kwargs = payload.get_json_for_request() |
| 1535 | + |
| 1536 | + request_kwargs['from_bundle_image'] = Image.get_or_create( |
| 1537 | + pull_specification=payload.from_bundle_image |
| 1538 | + ) |
| 1539 | + |
| 1540 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 1541 | + if current_user.is_authenticated: |
| 1542 | + request_kwargs['user'] = current_user |
| 1543 | + |
| 1544 | + # Add the request to a new batch |
| 1545 | + batch = batch or Batch() |
| 1546 | + db.session.add(batch) |
| 1547 | + request_kwargs['batch'] = batch |
| 1548 | + |
| 1549 | + request = cls(**request_kwargs) |
| 1550 | + request.add_state('in_progress', 'The request was initiated') |
| 1551 | + return request |
| 1552 | + |
1425 | 1553 | def to_json(self, verbose: Optional[bool] = True) -> RegenerateBundleRequestResponse:
|
1426 | 1554 | """
|
1427 | 1555 | Provide the JSON representation of a "regenerate-bundle" build request.
|
@@ -1624,6 +1752,45 @@ def from_json( # type: ignore[override] # noqa: F821
|
1624 | 1752 | request.add_state('in_progress', 'The request was initiated')
|
1625 | 1753 | return request
|
1626 | 1754 |
|
| 1755 | + def from_json_replacement( |
| 1756 | + cls, |
| 1757 | + payload: MergeIndexImagePydanticModel, |
| 1758 | + batch: Optional[Batch] = None, |
| 1759 | + ): |
| 1760 | + """ |
| 1761 | + Handle JSON requests for the builds/merge-index-image API endpoint. |
| 1762 | +
|
| 1763 | + :param MergeIndexImagePydanticModel payload: the Pydantic model representing the request. |
| 1764 | + :param Batch batch: the batch to specify with the request. |
| 1765 | + """ |
| 1766 | + request_kwargs = payload.get_json_for_request() |
| 1767 | + |
| 1768 | + request_kwargs['deprecation_list'] = [ |
| 1769 | + Image.get_or_create(pull_specification=item) for item in payload.deprecation_list |
| 1770 | + ] |
| 1771 | + request_kwargs['source_from_index'] = Image.get_or_create( |
| 1772 | + pull_specification=payload.source_from_index |
| 1773 | + ) |
| 1774 | + request_kwargs['target_index'] = Image.get_or_create(pull_specification=payload.target_index) |
| 1775 | + request_kwargs['binary_image'] = Image.get_or_create(pull_specification=payload.binary_image) |
| 1776 | + |
| 1777 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 1778 | + if current_user.is_authenticated: |
| 1779 | + request_kwargs['user'] = current_user |
| 1780 | + |
| 1781 | + # Add the request to a new batch |
| 1782 | + batch = batch or Batch() |
| 1783 | + db.session.add(batch) |
| 1784 | + request_kwargs['batch'] = batch |
| 1785 | + |
| 1786 | + request = cls(**request_kwargs) |
| 1787 | + |
| 1788 | + for bt in payload.build_tags: |
| 1789 | + request.add_build_tag(bt) |
| 1790 | + |
| 1791 | + request.add_state('in_progress', 'The request was initiated') |
| 1792 | + return request |
| 1793 | + |
1627 | 1794 | def to_json(self, verbose: Optional[bool] = True) -> MergeIndexImageRequestResponse:
|
1628 | 1795 | """
|
1629 | 1796 | Provide the JSON representation of an "merge-index-image" build request.
|
@@ -1896,6 +2063,36 @@ def from_json( # type: ignore[override] # noqa: F821
|
1896 | 2063 |
|
1897 | 2064 | return request
|
1898 | 2065 |
|
| 2066 | + def from_json_replacement( |
| 2067 | + cls, |
| 2068 | + payload: CreateEmptyIndexPydanticModel, |
| 2069 | + batch: Optional[Batch] = None, |
| 2070 | + ): |
| 2071 | + """ |
| 2072 | + Handle JSON requests for the builds/create-empty-index API endpoint. |
| 2073 | +
|
| 2074 | + :param CreateEmptyIndexPydanticModel payload: the Pydantic model representing the request. |
| 2075 | + :param Batch batch: the batch to specify with the request. |
| 2076 | + """ |
| 2077 | + request_kwargs = payload.get_json_for_request() |
| 2078 | + |
| 2079 | + request_kwargs['binary_image'] = Image.get_or_create(pull_specification=payload.binary_image) |
| 2080 | + request_kwargs['from_index'] = Image.get_or_create(pull_specification=payload.from_index) |
| 2081 | + |
| 2082 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 2083 | + if current_user.is_authenticated: |
| 2084 | + request_kwargs['user'] = current_user |
| 2085 | + |
| 2086 | + # Add the request to a new batch |
| 2087 | + batch = batch or Batch() |
| 2088 | + db.session.add(batch) |
| 2089 | + request_kwargs['batch'] = batch |
| 2090 | + |
| 2091 | + request = cls(**request_kwargs) |
| 2092 | + request.add_state('in_progress', 'The request was initiated') |
| 2093 | + |
| 2094 | + return request |
| 2095 | + |
1899 | 2096 | def to_json(self, verbose: Optional[bool] = True) -> CreateEmptyIndexRequestResponse:
|
1900 | 2097 | """
|
1901 | 2098 | Provide the JSON representation of an "create-empty-index" build request.
|
@@ -2020,6 +2217,35 @@ def from_json( # type: ignore[override] # noqa: F821
|
2020 | 2217 | request.add_state('in_progress', 'The request was initiated')
|
2021 | 2218 | return request
|
2022 | 2219 |
|
| 2220 | + def from_json_replacement( |
| 2221 | + cls, |
| 2222 | + payload: RecursiveRelatedBundlesPydanticModel, |
| 2223 | + batch: Optional[Batch] = None, |
| 2224 | + ): |
| 2225 | + """ |
| 2226 | + Handle JSON requests for the builds/recursive-related-bundles API endpoint. |
| 2227 | +
|
| 2228 | + :param RecursiveRelatedBundlesPydanticModel payload: the Pydantic model representing the request. |
| 2229 | + :param Batch batch: the batch to specify with the request. |
| 2230 | + """ |
| 2231 | + |
| 2232 | + request_kwargs = payload.get_json_for_request() |
| 2233 | + |
| 2234 | + request_kwargs['parent_bundle_image'] = Image.get_or_create(pull_specification=payload.parent_bundle_image) |
| 2235 | + |
| 2236 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 2237 | + if current_user.is_authenticated: |
| 2238 | + request_kwargs['user'] = current_user |
| 2239 | + |
| 2240 | + # Add the request to a new batch |
| 2241 | + batch = batch or Batch() |
| 2242 | + db.session.add(batch) |
| 2243 | + request_kwargs['batch'] = batch |
| 2244 | + |
| 2245 | + request = cls(**request_kwargs) |
| 2246 | + request.add_state('in_progress', 'The request was initiated') |
| 2247 | + return request |
| 2248 | + |
2023 | 2249 | def to_json(self, verbose: Optional[bool] = True) -> RecursiveRelatedBundlesRequestResponse:
|
2024 | 2250 | """
|
2025 | 2251 | Provide the JSON representation of a "recursive-related-bundles" build request.
|
@@ -2128,6 +2354,35 @@ def from_json( # type: ignore[override] # noqa: F821
|
2128 | 2354 | request.add_state('in_progress', 'The request was initiated')
|
2129 | 2355 | return request
|
2130 | 2356 |
|
| 2357 | + def from_json_replacement( |
| 2358 | + cls, |
| 2359 | + payload: FbcOperationsPydanticModel, |
| 2360 | + ): |
| 2361 | + """ |
| 2362 | + Handle JSON requests for the builds/fbc-operations API endpoint. |
| 2363 | +
|
| 2364 | + :param FbcOperationsPydanticModel payload: the Pydantic model representing the request. |
| 2365 | + :param Batch batch: the batch to specify with the request. |
| 2366 | + """ |
| 2367 | + request_kwargs = payload.get_json_for_request() |
| 2368 | + |
| 2369 | + request_kwargs['fbc_fragment'] = Image.get_or_create(pull_specification=payload.fbc_fragment) |
| 2370 | + request_kwargs['binary_image'] = Image.get_or_create(pull_specification=payload.binary_image) |
| 2371 | + request_kwargs['from_index'] = Image.get_or_create(pull_specification=payload.from_index) |
| 2372 | + |
| 2373 | + # current_user.is_authenticated is only ever False when auth is disabled |
| 2374 | + if current_user.is_authenticated: |
| 2375 | + request_kwargs['user'] = current_user |
| 2376 | + |
| 2377 | + request = cls(**request_kwargs) |
| 2378 | + |
| 2379 | + for bt in payload.build_tags: |
| 2380 | + request.add_build_tag(bt) |
| 2381 | + |
| 2382 | + request.add_state('in_progress', 'The request was initiated') |
| 2383 | + return request |
| 2384 | + |
| 2385 | + |
2131 | 2386 | def to_json(self, verbose: Optional[bool] = True) -> FbcOperationRequestResponse:
|
2132 | 2387 | """
|
2133 | 2388 | Provide the JSON representation of a "fbc-operation" build request.
|
|
0 commit comments