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.
'use strict'
const logger = require('../lib').logger;
const iothub = require('azure-iothub');
const errors = require('azure-iot-common').errors;
const Registry = iothub.Registry;
const ConnectionString = require('azure-iothub').ConnectionString;
function getDevice(iotHubConnectionString, deviceId, done) {
var registry = Registry.fromConnectionString(iotHubConnectionString);
registry.get(deviceId, done);
}
function getDeviceConnectionString(iotHubConnectionString, deviceInfo) {
var deviceConnectionString = 'HostName=' + ConnectionString.parse(iotHubConnectionString).HostName + ';DeviceId=' + deviceInfo.deviceId + ';SharedAccessKey=' + deviceInfo.authentication.symmetricKey.primaryKey;
logger.trace('Connectionstring: ' + deviceConnectionString);
return deviceConnectionString;
}
// Create a new device
function createDevice(iotHubConnectionString, deviceId, done) {
var registry = Registry.fromConnectionString(iotHubConnectionString);
var device = {
// 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;
#!/usr/bin/env node
// 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 logger = require('./lib').logger;
const async = require('async');
const ConnectionString = require('azure-iothub').ConnectionString;
const argv = require('yargs')
.usage('$0 [hub connection string]')
.alias('d', 'device')
.describe('device', 'use the specified device id (Symmetric Key authentication only)')
.alias('h', 'help')
.help('h')
.alias('g', 'consumerGroup')
.describe('consumerGroup', 'consumer group to use on the Event-hubs compatible endpoint')
.demandCommand(1)
.argv;
logger.info('*******************************************')
logger.info('* Executing the Microsoft IOT Trace tool. *');
logger.info('*******************************************')
async.series([
// 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.
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 = {
'use strict';
// Native node modules
var fs = require('fs');
var path = require('path');
// External dependencies
var program = require('commander');
// Local dependencies
var inputError = require('./common.js').inputError;
var printSuccess = require('./common.js').printSuccess;
var configLoc = require('./common.js').configLoc;
// Azure IoT SDK dependencies
var ConnectionString = require('azure-iothub').ConnectionString;
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
var showDeprecationText = require('./common.js').showDeprecationText;
showDeprecationText('az login');
program
.description('Create a temporary session on your IoT hub')
.option('-d, --duration ', 'time to keep the session open for (in seconds): if not specified, the default is one hour', parseInt)
.parse(process.argv);
if(!program.args[0]) inputError('You must specify a connection string.');
var connString = program.args[0];
var nowInSeconds = Math.floor(Date.now() / 1000);
var expiry = program.duration ? nowInSeconds + program.duration : nowInSeconds + 3600;
var cn = ConnectionString.parse(connString);
'use strict';
// node native modules
var fs = require('fs');
// external dependencies
var chalk = require('chalk');
var prettyjson = require('prettyjson');
var uuid = require('uuid');
var _ = require('lodash');
// sdk dependencies
var errors = require('azure-iot-common').errors;
var Message = require('azure-iot-common').Message;
var ConnectionString = require('azure-iothub').ConnectionString;
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
function createDeviceConnectionString(deviceInfo, hubHostName) {
var cs = 'HostName=' + hubHostName + ';DeviceId=' + deviceInfo.deviceId;
if (deviceInfo.authentication.SymmetricKey.primaryKey) {
cs += ';SharedAccessKey=' + deviceInfo.authentication.SymmetricKey.primaryKey;
} else if (deviceInfo.authentication.SymmetricKey.secondaryKey) {
cs += ';SharedAccessKey=' + deviceInfo.authentication.SymmetricKey.secondaryKey;
} else if (deviceInfo.authentication.x509Thumbprint.primaryThumbprint || deviceInfo.authentication.x509Thumbprint.secondaryThumbprint || (deviceInfo.authentication.type === 'certificateAuthority')) {
cs += ';x509=true';
} else {
cs = null;
}
return cs;
}
// 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 ConnectionString = require('azure-iothub').ConnectionString;
const uuid = require('uuid');
const consoleLogLevel = "info";
const fileLogLevel = "debug";
const logFileName = "trace.log";
const testCommand = uuid.v4();
const pingUrl = 'www.microsoft.com';
const httpsRequestUrl = 'https://www.microsoft.com/';
module.exports = {
consoleLogLevel: consoleLogLevel,
fileLogLevel: fileLogLevel,
logFileName: logFileName,
pingUrl: pingUrl,
testCommand: testCommand,
httpsRequestUrl: httpsRequestUrl