diff --git a/lib/services/core/storageservicesettings.js b/lib/services/core/storageservicesettings.js index 03c2676b9..4362ee731 100644 --- a/lib/services/core/storageservicesettings.js +++ b/lib/services/core/storageservicesettings.js @@ -124,7 +124,30 @@ StorageServiceSettings.developmentStorageAccount = function () { } return _devStoreAccount; -} +}; + +/** +* Gets the default service endpoint using the specified protocol and account +* name. +* +* @param {array} settings The service settings. +* @param {string} dns The service DNS. +* +* @return {string} +*/ +StorageServiceSettings._getDefaultServiceEndpoint = function (settings, dns) { + var scheme = util.tryGetValueInsensitive( + ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME, + settings + ); + + var accountName = util.tryGetValueInsensitive( + ConnectionStringKeys.ACCOUNT_NAME_NAME, + settings + ); + + return url.format({ protocol: scheme, host: accountName + '.' + dns }); +}; /** * Creates StorageServiceSettings object given endpoints uri. diff --git a/lib/util/util.js b/lib/util/util.js index 8efdb31e6..ce8fbf266 100644 --- a/lib/util/util.js +++ b/lib/util/util.js @@ -232,6 +232,30 @@ exports.inArrayInsensitive = function (needle, haystack) { return _.contains(_.map(haystack, function (h) { return h.toLowerCase() }), needle.toLowerCase()); }; +/** +* Returns the specified value of the key passed from object and in case that +* this key doesn't exist, the default value is returned. The key matching is +* done in a case insensitive manner. +* +* @param {string} key The array key. +* @param {object} haystack The object to be used. +* @param {mix} default The value to return if $key is not found in $array. +* +* @static +* +* @return mix +*/ +exports.tryGetValueInsensitive = function (key, haystack, defaultValue) +{ + for (var i in haystack) { + if (i.toString().toLowerCase() === key.toString().toLowerCase()) { + return haystack[i]; + } + } + + return defaultValue; +}; + exports.pathExistsSync = fs.existsSync ? fs.existsSync : path.existsSync; \ No newline at end of file diff --git a/test/testlist.txt b/test/testlist.txt index a6c167892..e40a5eb04 100644 --- a/test/testlist.txt +++ b/test/testlist.txt @@ -1,3 +1,4 @@ services/core/servicesettings-tests.js services/core/storageservicesettings-tests.js -util/validate-tests.js \ No newline at end of file +util/validate-tests.js +util/util-tests.js \ No newline at end of file diff --git a/test/util/util-tests.js b/test/util/util-tests.js index 0281d1cc8..8fcfdd574 100644 --- a/test/util/util-tests.js +++ b/test/util/util-tests.js @@ -175,4 +175,14 @@ suite('util-tests', function() { done(); }); + + test('Get value case insensitive', function (done) { + // int positives + assert.equal(util.tryGetValueInsensitive('B', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1'); + assert.equal(util.tryGetValueInsensitive('b', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1'); + assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), undefined); + assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }, 'something'), 'something'); + + done(); + }); }); \ No newline at end of file