How to use the azure-iot-common.ConnectionString function in azure-iot-common

To help you get started, we’ve selected a few azure-iot-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdks / node / e2etests / eh / eventhubclient.js View on Github external
// 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
  };
}
github Azure / azure-iot-sdk-node / device / transport / amqp / lib / _client_test_integration.js View on Github external
// 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),
github Azure / azure-iot-sdks / node / device / transport / http / lib / _client_test_integration.js View on Github external
// 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);
github Azure / node-red-contrib-azure / event / node_modules / azure-event-hubs / lib / config.js View on Github external
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) +
github Azure / azure-event-hubs-node / send_receive / lib / config.js View on Github external
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) +
github Azure / iothub-explorer / lib / eventhubclient.js View on Github external
// 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
  };
}
github Azure / azure-iot-sdks / node / service / lib / connection_string.js View on Github external
// 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']);
  }
};
github Azure / azure-iot-sdk-node / digitaltwins / e2e / model_repository_credentials.js View on Github external
// 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() {
github lcarli / NodeRedIoTHub / node_modules / azure-iothub / lib / connection_string.js View on Github external
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;
github Azure / node-red-contrib-azure / node_modules / azure-iothub / lib / connection_string.js View on Github external
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;