зеркало из
1
0
Форкнуть 0

move config creation into its own function

This commit is contained in:
Damon Barry 2015-11-19 12:54:29 -08:00
Родитель f9f530659c
Коммит 8a0d657609
1 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -15,19 +15,12 @@ EventHubClient.fromConnectionString = function (connectionString, path, Type_) {
if (!connectionString) {
throw new ArgumentError('Missing argument connectionString');
}
var cn = ConnectionString.parse(connectionString);
if (!cn.EntityPath && !path) {
var config = makeConfig(connectionString, path);
if (!config.path) {
throw new ArgumentError('Connection string doesn\'t have EntityPath, or missing argument path');
}
var endpoint = cn.Endpoint || '';
var host = (endpoint.match('sb://([^/]*)') || [])[1];
var config = {
host: host
};
Type_ = Type_ || EventHubClient;
return new Type_(config);
@ -37,4 +30,14 @@ EventHubClient.prototype.open = function () {
return Promise.resolve();
};
function makeConfig(connectionString, path) {
var cn = ConnectionString.parse(connectionString);
var endpoint = cn.Endpoint || '';
return {
host: (endpoint.match('sb://([^/]*)') || [])[1],
path: cn.EntityPath || path
};
}
module.exports = EventHubClient;