Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding ServiceSettings.

  • Loading branch information...
commit 0e7269c311a9aa03ca5c5030bfa419bea7c22bb6 1 parent 07a61c3
@andrerod andrerod authored
View
1  lib/azure.js
@@ -150,6 +150,7 @@ exports.SharedKeyLiteTable = require('./services/table/sharedkeylitetable');
exports.ISO8061Date = require('./util/iso8061date');
exports.Logger = require('./diagnostics/logger');
exports.ConnectionStringParser = require('./services/core/connectionstringparser');
+exports.ServiceSettings = require('./services/core/servicesettings');
/*
* Convenience functions.
View
39 lib/services/core/servicesettings.js
@@ -0,0 +1,39 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+var util = require('../../util/util');
+
+exports = module.exports;
+
+/**
+* Parses the connection string and then validate that the parsed keys belong to
+* the $validSettingKeys
+*
+* @param {string} connectionString The user provided connection string.
+*
+* @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) {
+ if (!util.inArrayInsensitive(key, validKeys)) {
+ throw new Error('Invalid connection string setting key ' + key);
+ }
+ });
+
+ return tokenizedSettings;
+};
View
15 lib/util/util.js
@@ -217,6 +217,21 @@ exports.merge = function () {
return _.extend.apply(this, arguments);
};
+/**
+* Checks if a value exists in an array. The comparison is done in a case
+* insensitive manner.
+*
+* @param {string} needle The searched value.
+* @param {array} haystack The array.
+*
+* @static
+*
+* @return {boolean}
+*/
+exports.inArrayInsensitive = function (needle, haystack) {
+ return _.contains(_.map(haystack, function (h) { return h.toLowerCase() }), needle.toLowerCase());
+};
+
exports.pathExistsSync = fs.existsSync
? fs.existsSync
: path.existsSync;
View
35 test/services/core/servicesettings-tests.js
@@ -0,0 +1,35 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+var should = require('should');
+var testutil = require('../../util/util');
+var azure = testutil.libRequire('azure');
+var ServiceSettings = azure.ServiceSettings;
+
+suite('serviceclient-tests', function () {
+ test('NormalizedErrorsAreErrors', function () {
+ var error = {
+ 'message': 'this is an error message',
+ 'ResultCode': 500,
+ 'somethingElse': 'goes here'
+ };
+
+ var normalizedError = ServiceClient.prototype._normalizeError(error);
+
+ normalizedError.should.be.an.instanceOf(Error);
+ normalizedError.should.have.keys('message', 'resultcode', 'somethingelse');
+ });
+});
+
View
9 test/util/util-tests.js
@@ -166,4 +166,13 @@ suite('util-tests', function() {
done();
});
+
+ test('In array case insensitive', function (done) {
+ // int positives
+ assert.ok(util.inArrayInsensitive('a', [ 'a', 'b', 'c']));
+ assert.ok(util.inArrayInsensitive('A', [ 'a', 'b', 'c']));
+ assert.ok(!util.inArrayInsensitive('d', [ 'a', 'b', 'c']));
+
+ done();
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.