Skip to content

Commit

Permalink
feat: begin implementing the SubEndpointChildren version of Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jkglasbrenner committed Sep 9, 2024
1 parent ff7bd34 commit 8bc158c
Showing 1 changed file with 118 additions and 1 deletion.
119 changes: 118 additions & 1 deletion src/dioptra/client/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import structlog
from structlog.stdlib import BoundLogger

from .base import EndpointClient, FieldsValidationError, SubEndpointClient
from .base import (
EndpointClient,
FieldsValidationError,
SubEndpointChildrenClient,
SubEndpointClient,
)

LOGGER: BoundLogger = structlog.stdlib.get_logger()

Expand Down Expand Up @@ -265,6 +270,118 @@ def remove_all(
return self._session.delete(self.parent_url, str(resource_id), self.name)


class TagsSubEndpointChildrenClient(SubEndpointChildrenClient[T]):
"""
The sub-endpoint client for managing the tags of child resources under a specific
parent resource.
Attributes:
name: The name of the sub-endpoint.
"""

name: ClassVar[str] = "tags"

def get(self, parent_resource_id: str | int, child_resource_id: str | int) -> T:
"""Get a list of tags.
Args:
parent_resource_id: The ID of the parent resource.
child_resource_id: The ID of the child resource.
Returns:
The response from the Dioptra API.
"""
return self._session.get(
self.build_child_url(parent_resource_id),
str(child_resource_id),
self.name,
)

# def modify(
# self,
# resource_id: int,
# ids: list[int],
# ) -> T:
# """Change the list of tags associated with an endpoint resource.

# This method overwrites the existing list of tags associated with an endpoint
# resource. To non-destructively append multiple tags, use the `append` method.
# To delete an individual tag, use the `remove` method.

# Args:
# resource_id: The ID of an endpoint resource.
# ids: The list of tag IDs to set on the resource.

# Returns:
# The response from the Dioptra API.
# """
# return self._session.put(
# self.parent_url,
# str(resource_id),
# self.name,
# json_={"ids": _validate_ids_argument(ids)},
# )

# def append(
# self,
# resource_id: int,
# ids: list[int],
# ) -> T:
# """Append one or more tags to an endpoint resource.

# Tag IDs that have already been appended to the endpoint resource will be
# ignored.

# Args:
# resource_id: The ID of an endpoint resource.
# ids: The list of tag IDs to append to the endpoint resource.

# Returns:
# The response from the Dioptra API.
# """
# return self._session.post(
# self.parent_url,
# str(resource_id),
# self.name,
# json_={"ids": _validate_ids_argument(ids)},
# )

# def remove(
# self,
# resource_id: int,
# tag_id: int,
# ) -> T:
# """Remove a tag from an endpoint resource.

# Args:
# resource_id: The ID of an endpoint resource.
# tag_id: The ID of the tag to remove from the endpoint resource.

# Returns:
# The response from the Dioptra API.
# """
# return self._session.delete(
# self.parent_url, str(resource_id), self.name, str(tag_id)
# )

# def remove_all(
# self,
# resource_id: int,
# ) -> T:
# """Remove all tags from an endpoint resource.

# This method will remove all tags from the endpoint resource and cannot be
# reversed. To remove individual tags, use the `remove` method.

# Args:
# resource_id: The ID of an endpoint resource.

# Returns:
# The response from the Dioptra API.
# """
# return self._session.delete(self.parent_url, str(resource_id), self.name)


def _validate_ids_argument(ids: list[int]) -> list[int]:
"""Validate the ids argument for tag operations.
Expand Down

0 comments on commit 8bc158c

Please sign in to comment.