Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Adding fromSettings function variations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Oct 12, 2012
1 parent a91a1c4 commit d3eb38e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 27 deletions.
5 changes: 5 additions & 0 deletions lib/services/core/servicebussettings.js
Expand Up @@ -68,6 +68,8 @@ function ServiceBusSettings(serviceBusEndpointUri, wrapEndpointUri, namespace, w
* @return {ServiceBusSettings}
*/
ServiceBusSettings.createFromSettings = function (settings) {
console.log(settings);

var matchedSpecs = ServiceSettings.matchedSpecification(
settings,
ServiceSettings.allRequired(
Expand All @@ -77,6 +79,9 @@ ServiceBusSettings.createFromSettings = function (settings) {
)
);

console.log('valid');
console.log(matchedSpecs);

if (matchedSpecs) {
var endpoint = util.tryGetValueInsensitive(
ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
Expand Down
3 changes: 1 addition & 2 deletions lib/services/core/serviceclient.js
Expand Up @@ -112,8 +112,7 @@ function ServiceClient(host, authenticationProvider) {
if (!this.protocol) {
this.protocol = parsedHost.protocol + '//';
}
}
else if (!this.protocol) {
} else if (!this.protocol) {
this.protocol = ServiceClient.DEFAULT_PROTOCOL;
}

Expand Down
29 changes: 22 additions & 7 deletions lib/services/core/servicemanagementsettings.js
Expand Up @@ -58,15 +58,13 @@ function ServiceManagementSettings(subscriptionId, endpointUri, certificatePath)
}

/**
* Creates a ServiceManagementSettings object from the given connection string.
* Creates a ServiceBusSettings object from a set of settings.
*
* @param {string} connectionString The storage settings connection string.
* @param {object} settings The settings object.
*
* @return {ServiceManagementSettings}
*/
ServiceManagementSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);

ServiceManagementSettings.createFromSettings = function (settings) {
var matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
ServiceSettings.allRequired(
Expand Down Expand Up @@ -101,6 +99,23 @@ ServiceManagementSettings.createFromConnectionString = function (connectionStrin
certificatePath
);
}

ServiceSettings.noMatch(connectionString);

ServiceSettings.noMatchSettings(settings);
};

/**
* Creates a ServiceManagementSettings object from the given connection string.
*
* @param {string} connectionString The storage settings connection string.
*
* @return {ServiceManagementSettings}
*/
ServiceManagementSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
try {
ServiceManagementSettings.createFromSettings(tokenizedSettings);
} catch (e) {
// Replace no match settings exception by no match connection string one.
ServiceSettings.noMatchConnectionString(connectionString);
}
}
47 changes: 31 additions & 16 deletions lib/services/core/storageservicesettings.js
Expand Up @@ -189,34 +189,32 @@ StorageServiceSettings._createStorageServiceSettings = function (settings, blobE
};

/**
* Creates a StorageServiceSettings object from the given connection string.
* Creates a ServiceBusSettings object from a set of settings.
*
* @param {string} connectionString The storage settings connection string.
* @param {object} settings The settings object.
*
* @return {StorageServiceSettings}
*/
StorageServiceSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);

StorageServiceSettings.createFromSettings = function (settings) {
// Devstore case
var matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
settings,
ServiceSettings.allRequired(_useDevelopmentStorageSetting),
ServiceSettings.optional(_developmentStorageProxyUriSetting)
);

if (matchedSpecs) {
var proxyUri = util.tryGetValueInsensitive(
ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME,
tokenizedSettings
settings
);

return this._getDevelopmentStorageAccount(proxyUri);
}

// Automatic case
matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
settings,
ServiceSettings.allRequired(
_defaultEndpointsProtocolSetting,
_accountNameSetting,
Expand All @@ -231,24 +229,24 @@ StorageServiceSettings.createFromConnectionString = function (connectionString)

if (matchedSpecs) {
return this._createStorageServiceSettings(
tokenizedSettings,
settings,
this._getDefaultServiceEndpoint(
tokenizedSettings,
settings,
ConnectionStringKeys.BLOB_BASE_DNS_NAME
),
this._getDefaultServiceEndpoint(
tokenizedSettings,
settings,
ConnectionStringKeys.QUEUE_BASE_DNS_NAME
),
this._getDefaultServiceEndpoint(
tokenizedSettings,
settings,
ConnectionStringKeys.TABLE_BASE_DNS_NAME
));
}

// Explicit case
matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
settings,
ServiceSettings.atLeastOne(
_blobEndpointSetting,
_queueEndpointSetting,
Expand All @@ -261,8 +259,25 @@ StorageServiceSettings.createFromConnectionString = function (connectionString)
);

if (matchedSpecs) {
return this._createStorageServiceSettings(tokenizedSettings);
return this._createStorageServiceSettings(settings);
}

ServiceSettings.noMatchSettings(settings);
};

/**
* Creates a StorageServiceSettings object from the given connection string.
*
* @param {string} connectionString The storage settings connection string.
*
* @return {StorageServiceSettings}
*/
StorageServiceSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
try {
StorageServiceSettings.createFromSettings(tokenizedSettings);
} catch (e) {
// Replace no match settings exception by no match connection string one.
ServiceSettings.noMatchConnectionString(connectionString);
}

ServiceSettings.noMatch(connectionString);
};
4 changes: 2 additions & 2 deletions lib/services/serviceBus/servicebusservice.js
Expand Up @@ -84,10 +84,10 @@ function ServiceBusService(namespaceOrConnectionString, accessKey, issuer, acsNa
}

var settings = {
endpoint: namespaceOrConnectionString + '.' + ServiceClient.CLOUD_SERVICEBUS_HOST,
endpoint: url.format({ protocol: 'https:', host: namespaceOrConnectionString + '.' + ServiceClient.CLOUD_SERVICEBUS_HOST }),
sharedsecretissuer: issuer,
sharedsecretvalue: accessKey,
stsendpoint: acsNamespace + '.' + ServiceClient.CLOUD_ACCESS_CONTROL_HOST
stsendpoint: url.format({ protocol: 'http:', host: acsNamespace + '.' + ServiceClient.CLOUD_ACCESS_CONTROL_HOST })
};

serviceBusSettings = ServiceBusSettings.createFromSettings(settings);
Expand Down

0 comments on commit d3eb38e

Please sign in to comment.