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';
var amqp10 = require('amqp10');
var Promise = require('bluebird');
var anHourFromNow = require('azure-iot-common').anHourFromNow;
var ConnectionString = require('azure-iot-common').ConnectionString;
var EventHubReceiver = require('./eventhubreceiver.js');
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
var managementEndpoint = '$management';
function createConfig(connectionString, entityPath) {
var cn = ConnectionString.parse(connectionString);
var host = cn.HostName || (cn.Endpoint || '').slice('sb://'.length);
return {
host: host,
namespace: host.split('.')[0],
keyName: cn.SharedAccessKeyName,
key: cn.SharedAccessKey,
eventHubName: entityPath
};
}
// 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 assert = require('chai').assert;
var Client = require('azure-iot-device').Client;
var ConnectionString = require('azure-iot-common').ConnectionString;
var Message = require('azure-iot-common').Message;
var Amqp = require('./amqp.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
function makeConnectionString(host, device, key) {
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
}
var connectionString = makeConnectionString(host, deviceId, key);
var badConnStrings = [
makeConnectionString('bad', deviceId, key),
makeConnectionString(host, 'bad', key),
// 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 ConnectionString = require('azure-iot-common').ConnectionString;
var runTests = require('azure-iot-device/lib/_client_test.js');
var Http = require('./http.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
var connectionString = 'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=' + key;
var badConnStrings = [
'HostName=bad;DeviceId=' + deviceId + ';SharedAccessKey=' + key,
'HostName=' + host + ';DeviceId=bad;SharedAccessKey=' + key,
'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=bad;'
];
describe('Over real HTTPS', function () {
this.timeout(15000);
function ConnectionConfig(connectionString, path) {
var cn = aziot.ConnectionString.parse(connectionString);
this.isIotHub = !!cn.HostName; // HostName is present in IoTHub connection strings, Endpoint in the case of Event Hubs
this.keyName = cn.SharedAccessKeyName;
this.key = cn.SharedAccessKey;
if(this.isIotHub) {
this.host = cn.HostName;
var hubName = this.host.split('.')[0];
this.sharedAccessSignature = aziot.SharedAccessSignature.create(this.host, this.keyName, this.key, aziot.anHourFromNow());
this.path = path || 'messages/events/';
this.saslPlainUri = 'amqps://' +
encodeURIComponent(this.keyName) +
'%40sas.root.' +
hubName +
':' +
encodeURIComponent(this.sharedAccessSignature) +
function ConnectionConfig(connectionString, path) {
var cn = aziot.ConnectionString.parse(connectionString);
this.isIotHub = !!cn.HostName; // HostName is present in IoTHub connection strings, Endpoint in the case of Event Hubs
this.keyName = cn.SharedAccessKeyName;
this.key = cn.SharedAccessKey;
if(this.isIotHub) {
this.host = cn.HostName;
var hubName = this.host.split('.')[0];
this.sharedAccessSignature = aziot.SharedAccessSignature.create(this.host, this.keyName, this.key, aziot.anHourFromNow());
this.path = path || 'messages/events/';
this.saslPlainUri = 'amqps://' +
encodeURIComponent(this.keyName) +
'%40sas.root.' +
hubName +
':' +
encodeURIComponent(this.sharedAccessSignature) +
// 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 amqp10 = require('amqp10');
var Promise = require('bluebird');
var anHourFromNow = require('azure-iot-common').anHourFromNow;
var ConnectionString = require('azure-iot-common').ConnectionString;
var EventHubReceiver = require('./eventhubreceiver.js');
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
var managementEndpoint = '$management';
function createConfig(connectionString, entityPath) {
var cn = ConnectionString.parse(connectionString);
var host = cn.HostName || (cn.Endpoint || '').slice('sb://'.length);
return {
host: host,
namespace: host.split('.')[0],
keyName: cn.SharedAccessKeyName,
key: cn.SharedAccessKey,
eventHubName: entityPath
};
}
// 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 Base = require('azure-iot-common').ConnectionString;
module.exports = {
parse: function parse(source) {
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName', 'SharedAccessKeyName', or 'SharedAccessKey' fields are not found in the source argument.]*/
return Base.parse(source, ['HostName', 'SharedAccessKeyName', 'SharedAccessKey']);
}
};
// 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 AuthorizationHeader = require('@azure/ms-rest-js').Constants.HeaderConstants.AUTHORIZATION;
const crypto = require('crypto');
const ConnectionString = require('azure-iot-common').ConnectionString;
class ModelRepositoryCredentials {
constructor(connectionString) {
this._connectionString = ConnectionString.parse(connectionString, ['HostName', 'SharedAccessKeyName', 'SharedAccessKey', 'RepositoryId']);
}
signRequest(webResource) {
webResource.headers.set(AuthorizationHeader, this._generateToken());
return Promise.resolve(webResource);
}
getBaseUri() {
return `https://${this._connectionString.HostName}`;
}
getRepositoryId() {
function parse(source) {
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName', 'SharedAccessKeyName', or 'SharedAccessKey' fields are not found in the source argument.]*/
return azure_iot_common_1.ConnectionString.parse(source, ['HostName', 'SharedAccessKeyName', 'SharedAccessKey']);
}
exports.parse = parse;
function parse(source) {
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
/*Codes_SRS_NODE_IOTHUB_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName', 'SharedAccessKeyName', or 'SharedAccessKey' fields are not found in the source argument.]*/
return azure_iot_common_1.ConnectionString.parse(source, ['HostName', 'SharedAccessKeyName', 'SharedAccessKey']);
}
exports.parse = parse;