Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
const debug = require('debug')('e2etests:digitaltwin_property');
const uuid = require('uuid');
const assert = require('chai').assert;
const Registry = require('azure-iothub').Registry;
const DigitalTwinDeviceClient = require('azure-iot-digitaltwins-device').DigitalTwinClient;
const DeviceClient = require('azure-iot-device').Client;
const Mqtt = require('azure-iot-device-mqtt').Mqtt;
const ServiceConnectionString = require('azure-iothub').ConnectionString;
const DeviceSas = require('azure-iot-device').SharedAccessSignature;
const TestInterfaceInstance = require('./test_interfaceInstance').TestInterfaceInstance;
const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials;
const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient;
const createModel = require('./model_repository_helper').createModel;
const interfaceDocument = require('./dtdl/test_interface');
const capabilityModelDocument = require('./dtdl/test_capability_model');
const hubConnectionString = process.env.IOTHUB_CONNECTION_STRING;
const hubHostName = ServiceConnectionString.parse(hubConnectionString).HostName;
// Create service client
const credentials = new IoTHubTokenCredentials(process.env.IOTHUB_CONNECTION_STRING);
const digitalTwinServiceClient = new DigitalTwinServiceClient(credentials);
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
const debug = require('debug')('e2etests:digitaltwin_commands');
const uuid = require('uuid');
const assert = require('chai').assert;
const ServiceConnectionString = require('azure-iothub').ConnectionString;
const Registry = require('azure-iothub').Registry;
const Mqtt = require('azure-iot-device-mqtt').Mqtt;
const DeviceSas = require('azure-iot-device').SharedAccessSignature;
const DeviceClient = require('azure-iot-device').Client;
const IoTHubTokenCredentials = require('azure-iot-digitaltwins-service').IoTHubTokenCredentials;
const DigitalTwinDeviceClient = require('azure-iot-digitaltwins-device').DigitalTwinClient;
const DigitalTwinServiceClient = require('azure-iot-digitaltwins-service').DigitalTwinServiceClient;
const createModel = require('./model_repository_helper').createModel;
const interfaceDocument = require('./dtdl/test_interface');
const capabilityModelDocument = require('./dtdl/test_capability_model');
const startEventHubsClient = require('./event_hubs_helper').startEventHubsClient;
const closeClients = require('./event_hubs_helper').closeClients;
const hubConnectionString = process.env.IOTHUB_CONNECTION_STRING;
const hubHostName = ServiceConnectionString.parse(hubConnectionString).HostName;
const credentials = new IoTHubTokenCredentials(hubConnectionString);
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var Message = require('azure-iot-device').Message;
var SharedAccessSignature = require('azure-iot-device').SharedAccessSignature;
function makeError(errorMessage) {
var err = new Error(errorMessage);
return err;
}
function SimulatedMqtt(config) {
this.handleRequest = function (done) {
var sig = SharedAccessSignature.parse(config.sharedAccessSignature);
if (config.host === 'bad') { // bad host
done(new Error('Invalid host address'));
}
else if (config.deviceId === 'bad') { // bad policy
done(makeError('Connection Refused'));
}
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
const debug = require('debug')('e2etests:digitaltwin_telemetry');
const uuid = require('uuid');
const Registry = require('azure-iothub').Registry;
const DigitalTwinDeviceClient = require('azure-iot-digitaltwins-device').DigitalTwinClient;
const DeviceClient = require('azure-iot-device').Client;
const Mqtt = require('azure-iot-device-mqtt').Mqtt;
const ServiceConnectionString = require('azure-iothub').ConnectionString;
const DeviceSas = require('azure-iot-device').SharedAccessSignature;
const TestInterfaceInstance = require('./test_interfaceInstance').TestInterfaceInstance;
const createModel = require('./model_repository_helper').createModel;
const startEventHubsClient = require('./event_hubs_helper').startEventHubsClient;
const closeClients = require('./event_hubs_helper').closeClients;
const interfaceDocument = require('./dtdl/test_interface');
const capabilityModelDocument = require('./dtdl/test_capability_model');
const hubConnectionString = process.env.IOTHUB_CONNECTION_STRING;
const hubHostName = ServiceConnectionString.parse(hubConnectionString).HostName;
describe('Digital Twin Telemetry', function () {
const deviceDescription = {
deviceId: 'node-e2e-digitaltwin-telemetry-' + uuid.v4()
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
// External dependencies
var program = require('commander');
// Local dependencies
var inputError = require('./common.js').inputError;
var serviceError = require('./common.js').serviceError;
var printSuccess = require('./common.js').printSuccess;
var getHostFromSas = require('./common.js').getHostFromSas;
var getSas = require('./common.js').getSas;
// Azure IoT SDK dependencies
var deviceSas = require('azure-iot-device').SharedAccessSignature;
var Registry = require('azure-iothub').Registry;
var showDeprecationText = require('./common.js').showDeprecationText;
showDeprecationText('az iot hub generate-sas-token');
program
.description('Generate a shared access signature token for the given device with an expiry time from now')
.option('-l, --login ', 'use the connection string provided as argument to use to authenticate with your IoT hub')
.option('-d, --duration ', 'expiration time (in seconds): if not specified, the default is one hour', parseInt)
.parse(process.argv);
if(!program.args[0]) inputError('You must specify a device id.');
var deviceId = program.args[0];
var nowInSeconds = Math.floor(Date.now() / 1000);
var expiry = program.duration ? nowInSeconds + program.duration : nowInSeconds + 3600;