Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/poly/handlers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
Function,
FunctionStep,
Handoff,
Resource,
ResourceMap,
ResourceMapping,
SMSTemplate,
Variable,
Variant,
Expand Down Expand Up @@ -261,7 +262,7 @@ def list_template_projects(region: str) -> list[dict[str, Any]]:
@staticmethod
def get_template_resources(
template_id: str, region: str
) -> dict[type[Resource], dict[str, Resource]]:
) -> tuple[ResourceMap, list[ResourceMapping]]:
"""Fetch a template and return its resources.

Combines projection fetching and resource conversion in one call.
Expand All @@ -271,7 +272,9 @@ def get_template_resources(
region: The region to query.

Returns:
dict mapping resource types to their resources.
tuple[ResourceMap, list[ResourceMapping]]: A tuple containing:
1. A dictionary mapping resource types to their resources.
2. A list of slim resources.
"""
from poly.resources.resource import load_resources_from_projection

Expand Down Expand Up @@ -312,15 +315,17 @@ def get_active_deployments(

def pull_deployment_resources(
self, deployment_id: str
) -> dict[type[Resource], dict[str, Resource]]:
) -> tuple[ResourceMap, list[ResourceMapping]]:
"""Fetch all resources for a specific deployment of a project.

Args:
deployment_id (str): The deployment ID

Returns:
dict[type[Resource], dict[str, Resource]]: A dictionary mapping resource types to
their resources
tuple[ResourceMap, list[ResourceMapping]]: A tuple containing:
1. A dictionary mapping resource types to their resources.
2. A list of slim resources.

"""
from poly.resources.resource import load_resources_from_projection

Expand All @@ -332,25 +337,28 @@ def pull_deployment_resources(

def pull_resources(
self, projection_json: Optional[dict[str, Any]] = None
) -> tuple[dict[type[Resource], dict[str, Resource]], dict[str, Any]]:
) -> tuple[ResourceMap, list[ResourceMapping], dict[str, Any]]:
"""Fetch all resources for the specific project.

Args:
projection_json (Optional[dict[str, Any]]): A dictionary containing the projection.
If provided, the projection will be used instead of fetching it from the API.

Returns:
dict[type[Resource], dict[str, Resource]]: A dictionary mapping resource types to
their resources
dict[str, Any]: The projection data
tuple[ResourceMap, list[ResourceMapping], dict[str, Any]]: A tuple containing:
1. A dictionary mapping resource types to their resources.
2. A list of slim resources.
3. The projection JSON.
"""
from poly.resources.resource import load_resources_from_projection

if projection_json is not None:
return load_resources_from_projection(projection_json), projection_json
resources, slim_resources = load_resources_from_projection(projection_json)
return resources, slim_resources, projection_json
try:
projection = self.sync_client.pull_projection()
return load_resources_from_projection(projection), projection
resources, slim_resources = load_resources_from_projection(projection)
return resources, slim_resources, projection
except (requests.HTTPError, SourcererAPIError) as e:
self._handle_api_error(e)

Expand Down Expand Up @@ -635,15 +643,17 @@ def delete_branch(self, branch_id: str) -> bool:

def pull_branch_resources(
self, branch_id: str, at_sequence: Optional[int] = None
) -> dict[type, dict[str, Any]]:
) -> tuple[ResourceMap, list[ResourceMapping]]:
"""Fetch resources for a branch, optionally at a historical sequence.

Args:
branch_id: The branch whose projection to fetch.
at_sequence: When provided, fetches the projection at this sequence number.

Returns:
A ResourceMap of the branch's resources.
tuple[ResourceMap, list[ResourceMapping]]: A tuple containing:
1. A dictionary mapping resource types to their resources.
2. A list of slim resources.
"""
from poly.resources.resource import load_resources_from_projection

Expand Down
Loading
Loading