move config creation into its own function
This commit is contained in:
Родитель
f9f530659c
Коммит
8a0d657609
|
@ -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;
|
Загрузка…
Ссылка в новой задаче