Skip to content

Commit

Permalink
refactor!: removes unit tests and restores some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Sep 19, 2024
1 parent b98bd26 commit 45285d0
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 4,882 deletions.
162 changes: 141 additions & 21 deletions rapyuta_io/rio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,23 @@
from __future__ import absolute_import

import json
import jsonschema
import os

import six

from rapyuta_io.clients import DeviceManagerClient, _ParamserverClient
from rapyuta_io.clients.build import Build, BuildStatus
from rapyuta_io.clients.catalog_client import CatalogClient
from rapyuta_io.clients.core_api_client import CoreAPIClient
from rapyuta_io.clients.deployment import Deployment
from rapyuta_io.clients.device import Device
from rapyuta_io.clients.metrics import QueryMetricsRequest, MetricOperation, \
MetricFunction, QueryMetricsResponse, \
ListMetricsRequest, ListTagKeysRequest, \
Metric, Tags, ListTagValuesRequest
from rapyuta_io.clients.native_network import NativeNetwork
from rapyuta_io.clients.package import Package
from rapyuta_io.clients.package import Runtime, ROSDistro, RestartPolicy
from rapyuta_io.clients.persistent_volumes import VolumeInstance
from rapyuta_io.clients.project import Project
from rapyuta_io.clients.rip_client import RIPClient, AuthTokenLevel
from rapyuta_io.clients.rosbag import ROSBagJob, ROSBagJobStatus, ROSBagBlob, \
ROSBagBlobStatus
from rapyuta_io.clients.routed_network import RoutedNetwork, Parameters
from rapyuta_io.clients.secret import Secret
from rapyuta_io.clients.metrics import ListMetricsRequest, ListTagKeysRequest, ListTagValuesRequest, Metric, \
MetricFunction, MetricOperation, QueryMetricsRequest, QueryMetricsResponse, Tags
from rapyuta_io.clients.rip_client import AuthTokenLevel, RIPClient
from rapyuta_io.clients.rosbag import ROSBagBlob, ROSBagBlobStatus, ROSBagJob, ROSBagJobStatus
from rapyuta_io.clients.user_group import UserGroup
from rapyuta_io.utils import InvalidAuthTokenException, \
InvalidParameterException
from rapyuta_io.utils import to_objdict
from rapyuta_io.utils.settings import VOLUME_PACKAGE_ID, default_host_config
from rapyuta_io.utils.utils import get_api_response_data, valid_list_elements
from rapyuta_io.clients.validation_schema import UPDATE_DEPLOYMENT_SCHEMA
from rapyuta_io.utils.settings import default_host_config
from rapyuta_io.utils.utils import valid_list_elements


class Client(object):
Expand Down Expand Up @@ -127,6 +112,36 @@ def set_project(self, project_guid):
self._dmClient.set_project(project_guid)
self._paramserver_client.set_project(project_guid)

def get_authenticated_user(self):
"""
Get details for authenticated User.
:rtype: :py:class:`~rapyuta_io.clients.project.User`
Following example demonstrates how to get authenticated user details.
>>> from rapyuta_io import Client
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = client.get_authenticated_user()
"""
return self._core_api_client.get_user()

def get_user_organizations(self):
"""
Get list of organizations that a user is part of.
:rtype: list(:py:class:`~rapyuta_io.clients.organization.Organization`)
Following example demonstrates how to get the list of organizations that a user is part of.
>>> from rapyuta_io import Client
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> organizations = client.get_user_organizations()
"""
return self._core_api_client.get_user_organizations()

def get_all_devices(self, online_device=False, arch_list=None, retry_limit=0, device_name=None):
"""
Get all the devices
Expand Down Expand Up @@ -799,3 +814,108 @@ def list_tag_values(self, list_tag_values_request):

response = self._core_api_client.list_tag_values(list_tag_values_request)
return response.get('tags_values', [])

def list_usergroups(self, org_guid):
"""
List usergroups in an organization
:param org_guid: Organization GUID
:type org_guid: str
:return: A list of all Usergroups in the organization
:rtype: list(:py:class:`~rapyuta_io.clients.user_group.UserGroup`)
Following example demonstrates how to list usergroups
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = self._core_api_client.get_user()
>>> organization_guid = user.organization.guid
>>> client.list_usergroups(organization_guid)
"""
return self._core_api_client.list_usergroups(org_guid)

def get_usergroup(self, org_guid, group_guid):
"""
Get usergroup using its GUID
:param org_guid: Organization GUID
:type org_guid: str
:param group_guid: Usergroup GUID
:type group_guid: str
:return: A usergroup
:rtype: :py:class:`~rapyuta_io.clients.user_group.UserGroup`
Following example demonstrates how to fetch a usergroup using its GUID
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = self._core_api_client.get_user()
>>> organization_guid = user.organization.guid
>>> client.get_usergroup(organization_guid, 'group-guid')
"""
return self._core_api_client.get_usergroup(org_guid, group_guid)

def delete_usergroup(self, org_guid, group_guid):
"""
Delete usergroup using its GUID
:param org_guid: Organization GUID
:type org_guid: str
:param group_guid: Usergroup GUID
:type group_guid: str
Following example demonstrates how to delete a usergroup using its GUID
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = self._core_api_client.get_user()
>>> organization_guid = user.organization.guid
>>> client.delete_usergroup(organization_guid, 'group-guid')
"""
return self._core_api_client.delete_usergroup(org_guid, group_guid)

def create_usergroup(self, org_guid, usergroup):
"""
Create usergroup in organization
:param org_guid: Organization GUID
:type org_guid: str
:param usergroup: usergroup object
:type usergroup: py:class:`~rapyuta_io.clients.user_group.UserGroup`
:return: Usergroup object
:rtype: :py:class:`~rapyuta_io.clients.user_group.UserGroup`
Following example demonstrates how to create usergroup in an organization
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = self._core_api_client.get_user()
>>> organization_guid = user.organization.guid
>>> usergroup = UserGroup(name='test-usergroup', description='test-description', creator=user.guid)
>>> usergroup = client.create_usergroup(organization_guid, usergroup)
"""
return self._core_api_client.create_usergroup(org_guid, usergroup)

def update_usergroup(self, org_guid, group_guid, usergroup):
"""
Update usergroup in organization
:param org_guid: Organization GUID
:type org_guid: str
:param group_guid: Usergroup GUID
:type group_guid: str
:param usergroup: Usergroup object
:type usergroup: py:class:`~rapyuta_io.clients.user_group.UserGroup`
:return: Usergroup object
:rtype: :py:class:`~rapyuta_io.clients.user_group.UserGroup`
Following example demonstrates how to update usergroup
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> user = self._core_api_client.get_user()
>>> organization_guid = user.organization.guid
>>> usergroup = UserGroup(name='test-usergroup-updated', description='test-description-updated', creator=user.guid)
>>> usergroup = client.update_usergroup(organization_guid, 'group-guid', usergroup)
"""
return self._core_api_client.update_usergroup(org_guid, group_guid, usergroup)
Loading

0 comments on commit 45285d0

Please sign in to comment.