Пример #1
0
 def __init__(
     self,
     cmd: AzCliCommand,
     app_id: str,
     token: str,
     consumer_group: str,
     central_handler_args: CentralHandlerArguments,
     central_dns_suffix: str,
 ):
     central_device_provider = CentralDeviceProvider(cmd=cmd,
                                                     app_id=app_id,
                                                     token=token)
     central_template_provider = CentralDeviceTemplateProvider(
         cmd=cmd, app_id=app_id, token=token)
     self._targets = self._build_targets(
         cmd=cmd,
         app_id=app_id,
         token=token,
         consumer_group=consumer_group,
         central_dns_suffix=central_dns_suffix,
     )
     self._handler = self._build_handler(
         central_device_provider=central_device_provider,
         central_template_provider=central_template_provider,
         central_handler_args=central_handler_args,
     )
def map_device_templates(cmd,
                         app_id: str,
                         token=None,
                         central_dns_suffix=CENTRAL_ENDPOINT):
    provider = CentralDeviceTemplateProvider(cmd=cmd,
                                             app_id=app_id,
                                             token=token)
    return provider.map_device_templates(central_dns_suffix=central_dns_suffix)
Пример #3
0
def delete_device_template(
    cmd,
    app_id: str,
    device_template_id: str,
    token=None,
    central_dns_suffix="azureiotcentral.com",
):
    provider = CentralDeviceTemplateProvider(cmd=cmd, app_id=app_id, token=token)
    return provider.delete_device_template(
        device_template_id=device_template_id, central_dns_suffix=central_dns_suffix
    )
def delete_device_template(
    cmd,
    app_id: str,
    device_template_id: str,
    token=None,
    central_dns_suffix=CENTRAL_ENDPOINT,
):
    provider = CentralDeviceTemplateProvider(cmd=cmd,
                                             app_id=app_id,
                                             token=token)
    return provider.delete_device_template(
        device_template_id=device_template_id,
        central_dns_suffix=central_dns_suffix)
def list_device_templates(cmd,
                          app_id: str,
                          token=None,
                          central_dns_suffix=CENTRAL_ENDPOINT):
    provider = CentralDeviceTemplateProvider(cmd=cmd,
                                             app_id=app_id,
                                             token=token)
    templates = provider.list_device_templates(
        central_dns_suffix=central_dns_suffix)
    return {
        template.id: template.raw_template
        for template in templates.values()
    }
Пример #6
0
 def _create_parser(self, device_template: Template, message: Message,
                    args: CommonParserArguments):
     device_provider = CentralDeviceProvider(cmd=None, app_id=None)
     template_provider = CentralDeviceTemplateProvider(cmd=None,
                                                       app_id=None)
     device_provider.get_device = mock.MagicMock(return_value=Device({}))
     template_provider.get_device_template = mock.MagicMock(
         return_value=device_template)
     return central_parser.CentralParser(
         message=message,
         central_device_provider=device_provider,
         central_template_provider=template_provider,
         common_parser_args=args,
     )
    def test_should_return_device_template(self, mock_device_svc,
                                           mock_device_template_svc):
        # setup
        provider = CentralDeviceTemplateProvider(cmd=None, app_id=app_id)
        mock_device_svc.get_device.return_value = self._device
        mock_device_template_svc.get_device_template.return_value = (
            self._device_template)

        # act
        template = provider.get_device_template("someDeviceTemplate")
        # check that caching is working
        template = provider.get_device_template("someDeviceTemplate")

        # verify
        # call counts should be at most 1 since the provider has a cache
        assert mock_device_template_svc.get_device_template.call_count == 1
        assert template == self._device_template
Пример #8
0
def create_device_template(
    cmd,
    app_id: str,
    device_template_id: str,
    content: str,
    token=None,
    central_dns_suffix="azureiotcentral.com",
):
    if not isinstance(content, str):
        raise CLIError("content must be a string: {}".format(content))

    payload = utility.process_json_arg(content, argument_name="content")

    provider = CentralDeviceTemplateProvider(cmd=cmd, app_id=app_id, token=token)
    return provider.create_device_template(
        device_template_id=device_template_id,
        payload=payload,
        central_dns_suffix=central_dns_suffix,
    )
Пример #9
0
 def __init__(
     self,
     cmd,
     app_id: str,
     device_id: str,
     token: str,
     central_dns_suffix=CENTRAL_ENDPOINT,
 ):
     self._cmd = cmd
     self._app_id = app_id
     self._device_id = device_id
     self._token = token
     self._central_dns_suffix = central_dns_suffix
     self._device_twin_provider = CentralDeviceTwinProvider(
         cmd=self._cmd,
         app_id=self._app_id,
         token=self._token,
         device_id=self._device_id,
     )
     self._central_device_provider = CentralDeviceProvider(
         cmd=self._cmd, app_id=self._app_id, token=self._token)
     self._central_template_provider = CentralDeviceTemplateProvider(
         cmd=self._cmd, app_id=self._app_id, token=self._token)
     self._template = self._get_device_template()
Пример #10
0
def map_device_templates(
    cmd, app_id: str, token=None, central_dns_suffix="azureiotcentral.com"
):
    provider = CentralDeviceTemplateProvider(cmd=cmd, app_id=app_id, token=token)
    return provider.map_device_templates(central_dns_suffix=central_dns_suffix)