def _get_device_client(client, resource_group_name, hub_name, device_id): resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name) base_url = '{0}.azure-devices.net'.format(hub_name) uri = '{0}/devices/{1}'.format(base_url, device_id) access_policy = iot_hub_policy_get(client, hub_name, 'iothubowner', resource_group_name) creds = SasTokenAuthentication(uri, access_policy.key_name, access_policy.primary_key) return IotHubDeviceClient(creds, client.iot_hub_resource.config.subscription_id, base_url='https://' + base_url).iot_hub_devices
def _get_device_client(client, resource_group_name, hub_name, device_id): resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name) # Intermediate fix to support domains beyond azure-devices.net hub = _get_iot_hub_by_name(client, hub_name) base_url = hub.properties.host_name uri = '{0}/devices/{1}'.format(base_url, device_id) access_policy = iot_hub_policy_get(client, hub_name, 'iothubowner', resource_group_name) creds = SasTokenAuthentication(uri, access_policy.key_name, access_policy.primary_key) return IotHubDeviceClient(creds, client.iot_hub_resource.config.subscription_id, base_url='https://' + base_url).iot_hub_devices
def get_iot_device_client(client, resource_group_name, hub_name, device_id): access_policies = client.list_keys(resource_group_name, hub_name).next() if access_policies is None: raise CLIError('No policy found from IoT Hub {}.'.format(hub_name)) logger.info('Shared Access Polices: %s', str(access_policies)) try: access_policy = next(x for x in access_policies if 'registrywrite' in x.rights.value.lower()) except StopIteration: raise CLIError('No policy found with RegistryWrite permission.') base_url = '{0}.azure-devices.net'.format(hub_name) uri = '{0}/devices/{1}'.format(base_url, device_id) creds = SasTokenAuthentication(uri, access_policy.key_name, access_policy.primary_key) return IotHubDeviceClient(creds, client.config.subscription_id, base_url='https://' + base_url).iot_hub_devices