Skip to content

[RSDK-10139] Implement User-defined Metadata Methods #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
148 changes: 148 additions & 0 deletions src/viam/app/app_client.py
Original file line number Diff line number Diff line change
@@ -54,12 +54,16 @@
GetFragmentResponse,
GetLocationRequest,
GetLocationResponse,
GetLocationMetadataRequest,
GetLocationMetadataResponse,
GetModuleRequest,
GetModuleResponse,
GetOrganizationNamespaceAvailabilityRequest,
GetOrganizationNamespaceAvailabilityResponse,
GetOrganizationRequest,
GetOrganizationResponse,
GetOrganizationMetadataRequest,
GetOrganizationMetadataResponse,
GetOrganizationsWithAccessToLocationRequest,
GetOrganizationsWithAccessToLocationResponse,
GetRegistryItemRequest,
@@ -70,12 +74,16 @@
GetRobotPartHistoryResponse,
GetRobotPartLogsRequest,
GetRobotPartLogsResponse,
GetRobotPartMetadataRequest,
GetRobotPartMetadataResponse,
GetRobotPartRequest,
GetRobotPartResponse,
GetRobotPartsRequest,
GetRobotPartsResponse,
GetRobotRequest,
GetRobotResponse,
GetRobotMetadataRequest,
GetRobotMetadataResponse,
GetRoverRentalRobotsRequest,
GetRoverRentalRobotsResponse,
GetUserIDByEmailRequest,
@@ -134,15 +142,23 @@
UnshareLocationRequest,
UpdateFragmentRequest,
UpdateFragmentResponse,
UpdateLocationMetadataRequest,
UpdateLocationMetadataResponse,
UpdateLocationRequest,
UpdateLocationResponse,
UpdateModuleRequest,
UpdateModuleResponse,
UpdateOrganizationInviteAuthorizationsRequest,
UpdateOrganizationInviteAuthorizationsResponse,
UpdateOrganizationMetadataRequest,
UpdateOrganizationMetadataResponse,
UpdateOrganizationRequest,
UpdateOrganizationResponse,
UpdateRegistryItemRequest,
UpdateRobotMetadataRequest,
UpdateRobotMetadataResponse,
UpdateRobotPartMetadataRequest,
UpdateRobotPartMetadataResponse,
UpdateRobotPartRequest,
UpdateRobotPartResponse,
UpdateRobotRequest,
@@ -2520,3 +2536,135 @@ async def rotate_key(self, id: str) -> Tuple[str, str]:
request = RotateKeyRequest(id=id)
response: RotateKeyResponse = await self._app_client.RotateKey(request, metadata=self._metadata)
return response.key, response.id

async def get_organization_metadata(self, org_id: str) -> Mapping[str, Any]:
"""Get an organization's user-defined metadata.

::

metadata = await cloud.get_organization_metadata(org_id="<YOUR-ORG-ID>")

Args:
org_id (str): The ID of the organization with which the user-defined metadata is associated.
You can obtain your organization ID from the Viam app's organization settings page.

Returns:
Mapping[str, Any]: The user-defined metadata converted from JSON to a Python dictionary
"""
request = GetOrganizationMetadataRequest(organization_id=org_id)
response: GetOrganizationMetadataResponse = await self._app_client.GetOrganizationMetadata(request)
return struct_to_dict(response.data)

async def update_organization_metadata(self, org_id: str, metadata: Mapping[str, Any]) -> None:
"""Update an organization's user-defined metadata.

::

await cloud.update_organization_metadata(org_id="<YOUR-ORG-ID>", metadata=)

Args:
organization_id (str): The ID of the organization with which to associate the user-defined metadata.
You can obtain your organization ID from the Viam app's organization settings page.
metadata (Mapping[str, Any]): The user-defined metadata to upload as a Python dictionary.
"""
request = UpdateOrganizationMetadataRequest(organization_id=org_id, data=dict_to_struct(metadata))
_: UpdateOrganizationMetadataResponse = await self._app_client.UpdateOrganizationMetadata(request)

async def get_location_metadata(self, location_id: str) -> Mapping[str, Any]:
"""Get a location's user-defined metadata.

::

metadata = await cloud.get_location_metadata(location_id="<YOUR-LOCATION-ID>")

Args:
location_id (str): The ID of the location with which the user-defined metadata is associated.
You can obtain your location ID from the Viam app's locations page.

Returns:
Mapping[str, Any]: The user-defined metadata converted from JSON to a Python dictionary.
"""
request = GetLocationMetadataRequest(location_id=location_id)
response: GetLocationMetadataResponse = await self._app_client.GetLocationMetadata(request)
return struct_to_dict(response.data)

async def update_location_metadata(self, location_id: str, metadata: Mapping[str, Any]) -> None:
"""Update a location's user-defined metadata.

::

await cloud.update_location_metadata(location_id="<YOUR-LOCATION-ID>", metadata=)

Args:
location_id (str): The ID of the location with which to associate the user-defined metadata.
You can obtain your location ID from the Viam app's locations page.
metadata (Mapping[str, Any]): The user-defined metadata converted from JSON to a Python dictionary.
"""
request = UpdateLocationMetadataRequest(location_id=location_id, data=dict_to_struct(metadata))
_: UpdateLocationMetadataResponse = await self._app_client.UpdateLocationMetadata(request)

async def get_robot_metadata(self, robot_id: str) -> Mapping[str, Any]:
"""Get a robot's user-defined metadata.

::

metadata = await cloud.get_robot_metadata(robot_id="<YOUR-ROBOT-ID>")

Args:
robot_id (str): The ID of the robot with which the user-defined metadata is associated.
You can obtain your robot ID from the Viam app's machine page.

Returns:
Mapping[str, Any]: The user-defined metadata converted from JSON to a Python dictionary.
"""
request = GetRobotMetadataRequest(id=robot_id)
response: GetRobotMetadataResponse = await self._app_client.GetRobotMetadata(request)
return struct_to_dict(response.data)

async def update_robot_metadata(self, robot_id: str, metadata: Mapping[str, Any]) -> None:
"""Update a robot's user-defined metadata.

::

await cloud.update_robot_metadata(robot_id="<YOUR-ROBOT-ID>", metadata=)

Args:
robot_id (str): The ID of the robot with which to associate the user-defined metadata.
You can obtain your robot ID from the Viam app's machine page.
metadata (Mapping[str, Any]): The user-defined metadata converted from JSON to a Python dictionary.
"""
request = UpdateRobotMetadataRequest(id=robot_id, data=dict_to_struct(metadata))
_: UpdateRobotMetadataResponse = await self._app_client.UpdateRobotMetadata(request)

async def get_robot_part_metadata(self, robot_part_id: str) -> Mapping[str, Any]:
"""Get a robot part's user-defined metadata.

::

metadata = await cloud.get_robot_part_metadata(robot_part_id="<YOUR-ROBOT-PART-ID>")

Args:
robot_part_id (str): The ID of the robot part with which the user-defined metadata is associated.
You can obtain your robot part ID from the Viam app's machine page.

Returns:
Mapping[str, Any]: The user-defined metadata converted from JSON to a Python dictionary.
"""
request = GetRobotPartMetadataRequest(id=robot_part_id)
response: GetRobotPartMetadataResponse = await self._app_client.GetRobotPartMetadata(request)
return struct_to_dict(response.data)

async def update_robot_part_metadata(self, robot_part_id: str, metadata: Mapping[str, Any]) -> None:
"""Update a robot part's user-defined metadata.

::

await cloud.update_robot_part_metadata(robot_part_id="<YOUR-ROBOT-PART-ID>", metadata=)

Args:
robot_id (str): The ID of the robot part with which to associate the user-defined metadata.
You can obtain your robot part ID from the Viam app's machine page.
metadata (Mapping[str, Any]): The user-defined metadata converted from JSON to a Python dictionary.
"""
request = UpdateRobotPartMetadataRequest(id=robot_part_id, data=dict_to_struct(metadata))
_: UpdateRobotPartMetadataResponse = await self._app_client.UpdateRobotPartMetadata(request)