예제 #1
0
    def list_certificates(self, **kwargs):
        """List certificates registered to organisation.

        Currently returns partially populated certificates. To obtain the full certificate object:
        `[get_certificate(certificate_id=cert['id']) for cert in list_certificates]`

        :param int limit: The number of certificates to retrieve.
        :param str order: The ordering direction, ascending (asc) or
            descending (desc).
        :param str after: Get certificates after/starting at given `certificate_id`.
        :param dict filters: Dictionary of filters to apply: type (eq), expire (eq), owner (eq)
        :return: list of :py:class:`Certificate` objects
        :rtype: Certificate
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, Certificate)
        if "service__eq" in kwargs:
            if kwargs["service__eq"] == CertificateType.bootstrap:
                pass
            elif kwargs["service__eq"] == CertificateType.developer:
                kwargs["device_execution_mode__eq"] = 1
                kwargs.pop("service__eq")
            elif kwargs["service__eq"] == CertificateType.lwm2m:
                pass
            else:
                raise CloudValueError(
                    "Incorrect value for CertificateType filter: %s" %
                    (kwargs["service__eq"]))
        owner = kwargs.pop('owner_id__eq', None)
        if owner is not None:
            kwargs['owner__eq'] = owner
        api = self._get_api(iam.DeveloperApi)
        return PaginatedResponse(api.get_all_certificates,
                                 lwrap_type=Certificate,
                                 **kwargs)
예제 #2
0
    def list_metrics(self, include=None, interval="1d", **kwargs):
        """Get statistics.

        :param list[str] include: List of fields included in response.
            None, or an empty list will return all fields.
            Fields: transactions, successful_api_calls, failed_api_calls, successful_handshakes,
            pending_bootstraps, successful_bootstraps, failed_bootstraps, registrations,
            updated_registrations, expired_registrations, deleted_registrations
        :param str interval: Group data by this interval in days, weeks or hours.
            Sample values: 2h, 3w, 4d.
        :param datetime start: Fetch the data with timestamp greater than or equal to this value.
            The parameter is not mandatory, if the period is specified.
        :param datetime end: Fetch the data with timestamp less than this value.
            The parameter is not mandatory, if the period is specified.
        :param str period: Period. Fetch the data for the period in days, weeks or hours.
            Sample values: 2h, 3w, 4d.
            The parameter is not mandatory, if the start and end time are specified
        :param int limit: The number of devices to retrieve
        :param str order: The ordering direction, ascending (asc) or descending (desc)
        :param str after: Get metrics after/starting at given metric ID
        :returns: a list of :py:class:`Metric` objects
        :rtype: PaginatedResponse
        """
        self._verify_arguments(interval, kwargs)
        include = Metric._map_includes(include)
        kwargs.update(dict(include=include, interval=interval))
        api = self._get_api(statistics.StatisticsApi)
        return PaginatedResponse(api.get_metrics, lwrap_type=Metric, **kwargs)
    def list_api_keys(self, **kwargs):
        """List the API keys registered in the organisation.

        List api keys Example:

        .. code-block:: python

            account_management_api = AccountManagementAPI()

            # List api keys
            api_keys_paginated_response = account_management_api.list_api_keys()
            # get single api key
            api_keys_paginated_response.data[0]

        :param int limit: Number of API keys to get
        :param str after: Entity ID after which to start fetching
        :param str order: Order of the records to return (asc|desc)
        :param dict filters: Dictionary of filters to apply: str owner (eq)
        :returns: a list of :class:`ApiKey` objects
        :rtype: PaginatedResponse
        :raises: ApiException
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, ApiKey)

        api = self._get_api(iam.DeveloperApi)

        # Return the data array
        return PaginatedResponse(api.get_all_api_keys,
                                 lwrap_type=ApiKey,
                                 **kwargs)
예제 #4
0
 def get_quota_history(self, **kwargs):
     """Get quota usage history"""
     kwargs = self._verify_sort_options(kwargs)
     kwargs = self._verify_filters(kwargs, ServicePackage)
     api = self._get_api(billing.DefaultApi)
     return PaginatedResponse(api.get_service_package_quota_history,
                              lwrap_type=QuotaHistory,
                              **kwargs)
예제 #5
0
 def list_enrollment_claims(self, **kwargs):
     """List"""
     kwargs = self._verify_sort_options(kwargs)
     kwargs = self._verify_filters(kwargs, EnrollmentClaim)
     api = self._get_api(enrollment.PublicAPIApi)
     return PaginatedResponse(api.get_device_enrollments,
                              lwrap_type=EnrollmentClaim,
                              **kwargs)
    def list_groups(self, **kwargs):
        """List all groups in organisation.

        :param int limit: The number of groups to retrieve
        :param str order: The ordering direction, ascending (asc) or descending (desc)
        :param str after: Get groups after/starting at given group ID
        :returns: a list of :py:class:`Group` objects.
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        api = self._get_api(iam.DeveloperApi)
        return PaginatedResponse(api.get_all_groups, lwrap_type=Group, **kwargs)
예제 #7
0
    def list_connected_devices(self, **kwargs):
        """List connected devices.

        Example usage, listing all registered devices in the catalog:

        .. code-block:: python

            filters = {
                'created_at': {'$gte': datetime.datetime(2017,01,01),
                               '$lte': datetime.datetime(2017,12,31)
                              }
            }
            devices = api.list_connected_devices(order='asc', filters=filters)
            for idx, device in enumerate(devices):
                print(device)

            ## Other example filters

            # Directly connected devices (not via gateways):
            filters = {
                'host_gateway': {'$eq': ''},
                'device_type': {'$eq': ''}
            }

            # Devices connected via gateways:
            filters = {
                'host_gateway': {'$neq': ''}
            }

            # Gateway devices:
            filters = {
                'device_type': {'$eq': 'MBED_GW'}
            }


        :param int limit: The number of devices to retrieve.
        :param str order: The ordering direction, ascending (asc) or
            descending (desc)
        :param str after: Get devices after/starting at given `device_id`
        :param filters: Dictionary of filters to apply.
        :returns: a list of connected :py:class:`Device` objects.
        :rtype: PaginatedResponse
        """
        # TODO(pick one of these)
        filter_or_filters = 'filter' if 'filter' in kwargs else 'filters'
        kwargs.setdefault(filter_or_filters,
                          {}).setdefault('state', {'$eq': 'registered'})
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, Device, True)
        api = self._get_api(device_directory.DefaultApi)
        return PaginatedResponse(api.device_list, lwrap_type=Device, **kwargs)
    def list_users(self, **kwargs):
        """List all users in organisation.

        :param int limit: The number of users to retrieve
        :param str order: The ordering direction, ascending (asc) or descending (desc)
        :param str after: Get users after/starting at given user ID
        :param dict filters: Dictionary of filters to apply: str status (eq)
        :returns: a list of :py:class:`User` objects
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, User)
        api = self._get_api(iam.AccountAdminApi)
        return PaginatedResponse(api.get_all_users, lwrap_type=User, **kwargs)
예제 #9
0
    def list_firmware_manifests(self, **kwargs):
        """List all manifests.

        :param int limit: number of manifests to retrieve
        :param str order: sort direction of manifests when ordered by time. 'desc' or 'asc'
        :param str after: get manifests after given `image_id`
        :param dict filters: Dictionary of filters to apply
        :return: list of :py:class:`FirmwareManifest` objects
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, FirmwareManifest, True)
        api = self._get_api(update_service.DefaultApi)
        return PaginatedResponse(api.firmware_manifest_list, lwrap_type=FirmwareManifest, **kwargs)
    def list_group_api_keys(self, group_id, **kwargs):
        """List API keys of a group.

        :param str group_id: The group ID (Required)
        :param int limit: The number of api keys to retrieve.
        :param str order: The ordering direction, ascending (asc) or descending (desc).
        :param str after: Get API keys after/starting at given api key ID.
        :returns: a list of :py:class:`ApiKey` objects.
        :rtype: PaginatedResponse
        """
        kwargs["group_id"] = group_id
        kwargs = self._verify_sort_options(kwargs)
        api = self._get_api(iam.DeveloperApi)
        return PaginatedResponse(api.get_api_keys_of_group, lwrap_type=ApiKey, **kwargs)
    def list_group_users(self, group_id, **kwargs):
        """List users of a group.

        :param str group_id: The group ID (Required)
        :param int limit: The number of users to retrieve
        :param str order: The ordering direction, ascending (asc) or descending (desc)
        :param str after: Get API keys after/starting at given user ID
        :returns: a list of :py:class:`User` objects.
        :rtype: PaginatedResponse
        """
        kwargs["group_id"] = group_id
        kwargs = self._verify_sort_options(kwargs)
        api = self._get_api(iam.AccountAdminApi)
        return PaginatedResponse(api.get_users_of_group, lwrap_type=User, **kwargs)
예제 #12
0
    def list_campaigns(self, **kwargs):
        """List all update campaigns.

        :param int limit: number of campaigns to retrieve
        :param str order: sort direction of campaigns when ordered by creation time (desc|asc)
        :param str after: get campaigns after given campaign ID
        :param dict filters: Dictionary of filters to apply
        :return: List of :py:class:`Campaign` objects
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, Campaign, True)
        api = self._get_api(update_service.DefaultApi)
        return PaginatedResponse(api.update_campaign_list, lwrap_type=Campaign, **kwargs)
    def list_queries(self, **kwargs):
        """List queries in device query service.

        :param int limit: The number of devices to retrieve.
        :param str order: The ordering direction, ascending (asc) or
            descending (desc)
        :param str after: Get devices after/starting at given `device_id`
        :param filters: Dictionary of filters to apply.
        :returns: a list of :py:class:`Query` objects.
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, Query, True)
        api = self._get_api(device_directory.DefaultApi)
        return PaginatedResponse(api.device_query_list, lwrap_type=Query, **kwargs)
    def list_device_events(self, **kwargs):
        """List all device logs.

        :param int limit: The number of logs to retrieve.
        :param str order: The ordering direction, ascending (asc) or
            descending (desc)
        :param str after: Get logs after/starting at given `device_event_id`
        :param dict filters: Dictionary of filters to apply.
        :return: list of :py:class:`DeviceEvent` objects
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, DeviceEvent, True)

        api = self._get_api(device_directory.DefaultApi)
        return PaginatedResponse(api.device_log_list, lwrap_type=DeviceEvent, **kwargs)
예제 #15
0
    def list_campaign_device_states(self, campaign_id, **kwargs):
        """List campaign devices status.

        :param str campaign_id: Id of the update campaign (Required)
        :param int limit: number of devices state to retrieve
        :param str order: sort direction of device state when ordered by creation time (desc|asc)
        :param str after: get devices state after given id
        :return: List of :py:class:`CampaignDeviceState` objects
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, CampaignDeviceState, True)
        kwargs["campaign_id"] = campaign_id
        api = self._get_api(update_service.DefaultApi)
        return PaginatedResponse(api.update_campaign_metadata_list,
                                 lwrap_type=CampaignDeviceState, **kwargs)
    def list_devices(self, **kwargs):
        """List devices in the device catalog.

        Example usage, listing all registered devices in the catalog:

        .. code-block:: python

            filters = { 'state': {'$eq': 'registered' } }
            devices = api.list_devices(order='asc', filters=filters)
            for idx, d in enumerate(devices):
                print(idx, d.id)

        :param int limit: The number of devices to retrieve.
        :param str order: The ordering direction, ascending (asc) or
            descending (desc)
        :param str after: Get devices after/starting at given `device_id`
        :param filters: Dictionary of filters to apply.
        :returns: a list of :py:class:`Device` objects registered in the catalog.
        :rtype: PaginatedResponse
        """
        kwargs = self._verify_sort_options(kwargs)
        kwargs = self._verify_filters(kwargs, Device, True)
        api = self._get_api(device_directory.DefaultApi)
        return PaginatedResponse(api.device_list, lwrap_type=Device, **kwargs)
예제 #17
0
 def list_psks(self, **kwargs):
     """List"""
     api = self._get_api(bootstrap.PreSharedKeysApi)
     return PaginatedResponse(api.list_pre_shared_keys,
                              lwrap_type=PreSharedKey,
                              **kwargs)
예제 #18
0
def paginate(self, foreign_key, wraps, *args, **kwargs):
    """Pagination wrapper for listing resources."""
    def wrapper(api_data):
        return foreign_key().from_api(**api_data)

    return PaginatedResponse(func=wraps, lwrap_type=wrapper, *args, **kwargs)
예제 #19
0
 def test_has_more(self):
     getter = partial(ListResponse)
     p = PaginatedResponse(getter)
     self.assertEqual([next(p) for _ in range(4)], [D(0), D(1), D(2), D(3)])