Permalink
Browse files

Applying code reviews.

  • Loading branch information...
1 parent b4af3be commit a903cfee46564f24dcae97982c15e7bc795826c9 Andre Rodrigues committed Oct 13, 2012
View
26 lib/services/core/servicesettings.js
@@ -34,27 +34,27 @@ exports.noMatch = function (connectionString) {
/**
* Parses the connection string and then validate that the parsed keys belong to
-* the $validSettingKeys
+* the validSettingKeys
*
* @param {string} connectionString The user provided connection string.
-*
+* @param {array} validKeys The valid keys.
* @return {array} The tokenized connection string keys.
*/
exports.parseAndValidateKeys = function (connectionString, validKeys) {
var tokenizedSettings = ConnectionStringParser.parse(connectionString);
// Assure that all given keys are valid.
- for (var key in tokenizedSettings) {
+ for (var key in Object.keys(tokenizedSettings)) {
if (!util.inArrayInsensitive(key, validKeys)) {
- throw new Error('Invalid connection string setting key ' + key);
+ throw new Error('Invalid connection string setting key "' + key + '"');
}
}
return tokenizedSettings;
};
/**
-* Creates an anonymous function that acts as predicate.
+* Creates an anonymous function that acts as predicate to perform a validation.
*
* @param array {requirements} The array of conditions to satisfy.
* @param boolean {isRequired} Either these conditions are all required or all
@@ -69,17 +69,17 @@ exports.getValidator = function (requirements, isRequired, atLeastOne) {
var oneFound = false;
var result = { };
- for (var key in userSettings) {
+ for (var key in Object.keys(userSettings)) {
result[key.toLowerCase()] = userSettings[key];
}
- for (var requirement in requirements) {
- var settingName = requirements[requirement]['SettingName'].toLowerCase();
+ requirements.forEach(function (requirement) {
+ var settingName = requirement['SettingName'].toLowerCase();
// Check if the setting name exists in the provided user settings.
if (result[settingName]) {
// Check if the provided user setting value is valid.
- var validationFunc = requirements[requirement]['SettingConstraint'];
+ var validationFunc = requirement['SettingConstraint'];
var isValid = validationFunc(result[settingName]);
if (isValid) {
@@ -91,7 +91,7 @@ exports.getValidator = function (requirements, isRequired, atLeastOne) {
// If required then fail because the setting does not exist
return null;
}
- }
+ });
if (atLeastOne) {
// At least one requirement must succeed, otherwise fail.
@@ -193,15 +193,15 @@ exports.settingWithFunc = function (name, predicate) {
exports.matchedSpecification = function (settings) {
var constraints = Array.prototype.slice.call(arguments, 1, arguments.length);
- for (var constraint in constraints) {
- var remainingSettings = constraints[constraint](settings);
+ constraints.forEach(function (constraint) {
+ var remainingSettings = constraint(settings);
if (!remainingSettings) {
return false;
} else {
settings = remainingSettings;
}
- }
+ });
return util.objectKeysLength(settings) === 0;
};
View
46 lib/services/core/storageservicesettings.js
@@ -25,24 +25,24 @@ var Validate = require('../../util/validate');
exports = module.exports = StorageServiceSettings;
-var _devStoreAccount = null;
-var _useDevelopmentStorageSetting = ServiceSettings.setting(ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME, true);
-var _developmentStorageProxyUriSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME, Validate.getIsValidUri());
-var _defaultEndpointsProtocolSetting = ServiceSettings.setting(ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME, 'http', 'https');
-var _accountNameSetting = ServiceSettings.setting(ConnectionStringKeys.ACCOUNT_NAME_NAME);
-var _accountKeySetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.ACCOUNT_KEY_NAME, Validate.getIsBase64Encoded());
-
-var _blobEndpointSetting = ServiceSettings.settingWithFunc(
+var devStoreAccount = null;
+var useDevelopmentStorageSetting = ServiceSettings.setting(ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME, true);
+var developmentStorageProxyUriSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME, Validate.getIsValidUri());
+var defaultEndpointsProtocolSetting = ServiceSettings.setting(ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME, 'http', 'https');
+var accountNameSetting = ServiceSettings.setting(ConnectionStringKeys.ACCOUNT_NAME_NAME);
+var accountKeySetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.ACCOUNT_KEY_NAME, Validate.getIsBase64Encoded());
+
+var blobEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.BLOB_ENDPOINT_NAME,
Validate.getIsValidUri()
);
-var _queueEndpointSetting = ServiceSettings.settingWithFunc(
+var queueEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.QUEUE_ENDPOINT_NAME,
Validate.getIsValidUri()
);
-var _tableEndpointSetting = ServiceSettings.settingWithFunc(
+var tableEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.TABLE_ENDPOINT_NAME,
Validate.getIsValidUri()
);
@@ -201,8 +201,8 @@ StorageServiceSettings.createFromConnectionString = function (connectionString)
// Devstore case
var matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
- ServiceSettings.allRequired(_useDevelopmentStorageSetting),
- ServiceSettings.optional(_developmentStorageProxyUriSetting)
+ ServiceSettings.allRequired(useDevelopmentStorageSetting),
+ ServiceSettings.optional(developmentStorageProxyUriSetting)
);
if (matchedSpecs) {
@@ -218,14 +218,14 @@ StorageServiceSettings.createFromConnectionString = function (connectionString)
matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
ServiceSettings.allRequired(
- _defaultEndpointsProtocolSetting,
- _accountNameSetting,
- _accountKeySetting
+ defaultEndpointsProtocolSetting,
+ accountNameSetting,
+ accountKeySetting
),
ServiceSettings.optional(
- _blobEndpointSetting,
- _queueEndpointSetting,
- _tableEndpointSetting
+ blobEndpointSetting,
+ queueEndpointSetting,
+ tableEndpointSetting
)
);
@@ -250,13 +250,13 @@ StorageServiceSettings.createFromConnectionString = function (connectionString)
matchedSpecs = ServiceSettings.matchedSpecification(
tokenizedSettings,
ServiceSettings.atLeastOne(
- _blobEndpointSetting,
- _queueEndpointSetting,
- _tableEndpointSetting
+ blobEndpointSetting,
+ queueEndpointSetting,
+ tableEndpointSetting
),
ServiceSettings.allRequired(
- _accountNameSetting,
- _accountKeySetting
+ accountNameSetting,
+ accountKeySetting
)
);
View
2 test/services/core/storageservicesettings-tests.js
@@ -269,7 +269,7 @@ suite('storageservicesettings-tests', function () {
// Test
(function() {
StorageServiceSettings.createFromConnectionString(connectionString);
- }).should.throw('Invalid connection string setting key ' + invalidKey.toLowerCase());
+ }).should.throw('Invalid connection string setting key "' + invalidKey.toLowerCase() + '"');
});
test('testCreateFromConnectionStringWithCaseInsensitive', function () {

0 comments on commit a903cfe

Please sign in to comment.