Skip to content

Commit

Permalink
Delete types replaced by pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
xDaile committed Jan 4, 2024
1 parent d8e52df commit 8218ba7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 229 deletions.
201 changes: 0 additions & 201 deletions iib/web/iib_static_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,207 +35,6 @@ class RelatedBundlesMetadata(TypedDict):
url: str


# Start of the Payloads Part

# try inheritance from other payloads

PayloadTags = Literal[
'AddRequestPayload',
'RmRequestPayload',
'RegenerateBundlePayload',
'RegenerateBundleBatchPayload',
'AddRmBatchPayload',
'MergeIndexImagesPayload',
'CreateEmptyIndexPayload',
'FbcOperationRequestPayload',
]


PossiblePayloadParameters = Sequence[
Literal[
'add_arches',
'annotations',
'batch',
'binary_image',
'build_requests',
'build_tags',
'bundles',
'cnr_token',
'check_related_images',
'deprecation_list',
'distribution_scope',
'force_backport',
'from_bundle_image',
'from_index',
'graph_update_mode',
'labels',
'operators',
'organization',
'output_fbc',
'overwrite_from_index',
'overwrite_from_index_token',
'registry_auths',
'related_bundles',
'source_from_index',
'target_index',
'user',
]
]


class AddRequestPayload(TypedDict):
"""Datastructure of the request to /builds/add API point."""

add_arches: NotRequired[List[str]]
binary_image: NotRequired[str]
build_tags: NotRequired[List[str]]
bundles: List[str]
cnr_token: NotRequired[str]
check_related_images: NotRequired[bool]
deprecation_list: NotRequired[List[str]]
distribution_scope: NotRequired[str]
force_backport: NotRequired[bool]
from_index: NotRequired[str]
graph_update_mode: NotRequired[GRAPH_MODE_LITERAL]
organization: NotRequired[str]
overwrite_from_index: NotRequired[bool]
overwrite_from_index_token: NotRequired[str]


class RmRequestPayload(TypedDict):
"""Datastructure of the request to /builds/rm API point."""

add_arches: NotRequired[List[str]]
binary_image: NotRequired[str]
build_tags: NotRequired[List[str]]
distribution_scope: NotRequired[str]
from_index: str
operators: List[str]
overwrite_from_index: NotRequired[bool]
overwrite_from_index_token: Optional[str]


class FbcOperationRequestPayload(TypedDict):
"""Datastructure of the request to /builds/fbc-operation API point."""

fbc_fragment: str
from_index: str
binary_image: NotRequired[str]
build_tags: NotRequired[List[str]]
add_arches: NotRequired[List[str]]
overwrite_from_index: NotRequired[bool]
overwrite_from_index_token: NotRequired[str]
batch: NotRequired[str]
distribution_scope: NotRequired[str]
user: NotRequired[str]


class RegenerateBundlePayload(TypedDict):
"""Datastructure of the request to /builds/regenerate-bundle API point."""

from_bundle_image: str
organization: NotRequired[str]
registry_auths: NotRequired[Dict[str, Any]]
related_bundles: NotRequired[RelatedBundlesMetadata]
user: NotRequired[str]
batch: NotRequired[str]


class RegenerateBundleBatchPayload(TypedDict):
"""Datastructure of the request to /builds/regenerate-bundle-batch API point."""

annotations: NotRequired[Dict[str, Any]]
build_requests: List[RegenerateBundlePayload]


class AddRmBatchPayload(TypedDict):
"""Datastructure of the request to /builds/add-rm-batch API point."""

annotations: NotRequired[Dict[str, Any]]
build_requests: List[Union[AddRequestPayload, RmRequestPayload]]


class MergeIndexImagesPayload(TypedDict):
"""Datastructure of the request to /builds/merge-index-image API point."""

binary_image: NotRequired[str]
build_tags: NotRequired[List[str]]
deprecation_list: NotRequired[List[str]]
distribution_scope: NotRequired[str]
graph_update_mode: NotRequired[GRAPH_MODE_LITERAL]
overwrite_target_index: NotRequired[bool]
overwrite_target_index_token: NotRequired[str]
source_from_index: str
target_index: NotRequired[str]
batch: NotRequired[str]
user: NotRequired[str]


class CreateEmptyIndexPayload(TypedDict):
"""Datastructure of the request to /builds/create-empty-index API point."""

binary_image: NotRequired[str]
from_index: str
labels: NotRequired[Dict[str, str]]
output_fbc: NotRequired[bool]


class RecursiveRelatedBundlesRequestPayload(TypedDict):
"""Datastructure of the request to /builds/recursive-related-bundles API point."""

batch: NotRequired[int]
organization: NotRequired[str]
parent_bundle_image: str
registry_auths: NotRequired[Dict[str, Any]]
user: NotRequired[str]


class RequestPayload(TypedDict):
"""Datastructure with all the possible keys that can API points receive."""

add_arches: NotRequired[List[str]]
annotations: NotRequired[Dict[str, Any]]
batch: NotRequired[int]
binary_image: NotRequired[str]
build_requests: NotRequired[
List[Union[AddRequestPayload, RmRequestPayload, RegenerateBundlePayload]]
]
build_tags: NotRequired[List[str]]
bundles: NotRequired[Optional[List[str]]]
cnr_token: NotRequired[str]
check_related_images: NotRequired[bool]
deprecation_list: NotRequired[List[str]]
distribution_scope: NotRequired[str]
fbc_fragment: NotRequired[bool]
force_backport: NotRequired[bool]
from_bundle_image: NotRequired[str]
from_index: NotRequired[str]
labels: NotRequired[Dict[str, str]]
operators: NotRequired[List[str]]
organization: NotRequired[str]
output_fbc: NotRequired[bool]
overwrite_from_index: NotRequired[bool]
overwrite_from_index_token: NotRequired[str]
overwrite_target_index: NotRequired[bool]
overwrite_target_index_token: NotRequired[str]
registry_auths: NotRequired[Dict[str, Any]]
related_bundles: NotRequired[RelatedBundlesMetadata]
source_from_index: NotRequired[str]
target_index: NotRequired[str]
user: NotRequired[str]


PayloadTypesUnion = Union[
AddRequestPayload,
CreateEmptyIndexPayload,
FbcOperationRequestPayload,
MergeIndexImagesPayload,
RecursiveRelatedBundlesRequestPayload,
RegenerateBundlePayload,
RmRequestPayload,
]

# End of the Payloads Part
# Start of the RequestResponses Part


Expand Down
28 changes: 0 additions & 28 deletions iib/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from iib.web.iib_static_types import (
AddRequestResponse,
AddRmBatchPayload,
AddRmRequestResponseBase,
BaseClassRequestResponse,
BuildRequestState,
Expand All @@ -33,7 +32,6 @@
FbcOperationRequestResponse,
MergeIndexImageRequestResponse,
RecursiveRelatedBundlesRequestResponse,
RegenerateBundleBatchPayload,
RegenerateBundleRequestResponse,
)

Expand Down Expand Up @@ -666,32 +664,6 @@ def annotations(self, annotations: Optional[Dict[str, Any]]) -> None:
json.dumps(annotations, sort_keys=True) if annotations is not None else None
)

# TODO DELETE
@staticmethod
def validate_batch_request_params(
payload: Union[AddRmBatchPayload, RegenerateBundleBatchPayload]
) -> None:
"""
Validate batch specific parameters from the input JSON payload.
The requests in the "build_requests" key's value are not validated. Those should be
validated separately.
:raises ValidationError: if the payload is invalid
"""
if (
not isinstance(payload, dict)
or not isinstance(payload.get('build_requests'), list)
or not payload['build_requests']
):
raise ValidationError(
'The input data must be a JSON object and the "build_requests" value must be a '
'non-empty array'
)

if not isinstance(payload.get('annotations', {}), dict):
raise ValidationError('The value of "annotations" must be a JSON object')

@property
def state(self) -> str:
"""
Expand Down

0 comments on commit 8218ba7

Please sign in to comment.