Permalink
Browse files

Merge remote-tracking branch 'origin/servicemanagement' into connecti…

…onStrings
  • Loading branch information...
Andre Rodrigues
Andre Rodrigues committed Oct 13, 2012
2 parents abf779f + 79c6e1c commit 08804f2c111c3d260e9ca15d3ba0a341e0ed77dd
View
@@ -153,6 +153,7 @@ exports.ConnectionStringParser = require('./services/core/connectionstringparser
exports.ServiceSettings = require('./services/core/servicesettings');
exports.StorageServiceSettings = require('./services/core/storageservicesettings');
exports.ServiceBusSettings = require('./services/core/servicebussettings');
+exports.ServiceManagementSettings = require('./services/core/servicemanagementsettings');
exports.Validate = require('./util/validate');
/*
@@ -0,0 +1,106 @@
+/**
+* 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 url = require('url');
+
+var util = require('../../util/util');
+
+var ConnectionStringParser = require('./connectionstringparser');
+var ServiceSettings = require('./servicesettings');
+var Constants = require('../../util/constants');
+var ConnectionStringKeys = Constants.ConnectionStringKeys;
+var Validate = require('../../util/validate');
+
+exports = module.exports = ServiceManagementSettings;
+
+var _endpointSetting = ServiceSettings.settingWithFunc(
+ ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
+ Validate.getIsValidUri()
+ );
+
+var _certificatePathSetting = ServiceSettings.setting(
+ ConnectionStringKeys.CERTIFICATE_PATH_NAME
+ );
+
+var _subscriptionIdSetting = ServiceSettings.setting(
+ ConnectionStringKeys.SUBSCRIPTION_ID_NAME
+ );
+
+var validKeys = [
+ ConnectionStringKeys.SUBSCRIPTION_ID_NAME,
+ ConnectionStringKeys.CERTIFICATE_PATH_NAME,
+ ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME
+];
+
+/**
+* Creates new service management settings instance.
+*
+* @param {string} subscriptionId The user provided subscription id.
+* @param {string} endpointUri The service management endpoint uri.
+* @param {string} certificatePath The management certificate path.
+*/
+function ServiceManagementSettings(subscriptionId, endpointUri, certificatePath) {
+ this._subscriptionId = subscriptionId;
+ this._endpointUri = endpointUri;
+ this._certificatePath = certificatePath;
+}
+
+/**
+* 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);
+
+ var matchedSpecs = ServiceSettings.matchedSpecification(
+ tokenizedSettings,
+ ServiceSettings.allRequired(
+ _subscriptionIdSetting,
+ _certificatePathSetting
+ ),
+ ServiceSettings.optional(
+ _endpointSetting
+ )
+ );
+
+ if (matchedSpecs) {
+ var endpointUri = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
+ tokenizedSettings,
+ Constants.SERVICE_MANAGEMENT_URL
+ );
+
+ var subscriptionId = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SUBSCRIPTION_ID_NAME,
+ tokenizedSettings
+ );
+
+ var certificatePath = util.tryGetValueInsensitive(
+ ConnectionStringKeys.CERTIFICATE_PATH_NAME,
+ tokenizedSettings
+ );
+
+ return new ServiceManagementSettings(
+ subscriptionId,
+ endpointUri,
+ certificatePath
+ );
+ }
+
+ ServiceSettings.noMatch(connectionString);
+}
View
@@ -825,6 +825,14 @@ var Constants = {
*/
DEV_STORE_URI: 'http://127.0.0.1',
+ /**
+ * The service management URI.
+ *
+ * @const
+ * @type {string}
+ */
+ SERVICE_MANAGEMENT_URL: 'https://management.core.windows.net',
+
/**
* Defines constants for use with blob operations.
*/
@@ -22,7 +22,7 @@ var Constants = azure.Constants;
var ConnectionStringKeys = Constants.ConnectionStringKeys;
var ServiceBusSettings = azure.ServiceBusSettings;
-suite('storageservicesettings-tests', function () {
+suite('servicebussettings-tests', function () {
test('testCreateFromConnectionStringWithServiceBusAutomaticCase', function () {
// Setup
var expectedNamespace = 'mynamespace';
@@ -0,0 +1,94 @@
+/**
+* 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 url = require('url');
+
+var testutil = require('../../util/util');
+var azure = testutil.libRequire('azure');
+var Constants = azure.Constants;
+var ConnectionStringKeys = Constants.ConnectionStringKeys;
+var ServiceManagementSettings = azure.ServiceManagementSettings;
+
+suite('servicemanagementsettings-tests', function () {
+ test('testCreateFromConnectionStringWithAutomaticCase', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = Constants.SERVICE_MANAGEMENT_URL;
+ var connectionString = 'SubscriptionID=' + expectedSubscriptionId + ';CertificatePath=' + expectedCertificatePath;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
+
+ test('testCreateFromConnectionStringWithExplicitCase', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = 'http://myprivatedns.com';
+ var connectionString = 'SubscriptionID=' + expectedSubscriptionId + ';CertificatePath=' + expectedCertificatePath + ';ServiceManagementEndpoint=' + expectedEndpointUri;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
+
+ test('testCreateFromConnectionStringWithMissingKeyFail', function () {
+ // Setup
+ var connectionString = 'CertificatePath=C:\\path_to_my_cert.pem;ServiceManagementEndpoint=http://myprivatedns.com';
+
+ // Test
+ (function() {
+ ServiceManagementSettings.createFromConnectionString(connectionString);
+ }).should.throw('The provided connection string ' + connectionString + ' does not have complete configuration settings.');
+ });
+
+ test('testCreateFromConnectionStringWithInvalidServiceManagementKeyFail', function () {
+ // Setup
+ var invalidKey = 'InvalidKey';
+ var connectionString = invalidKey + '=value;SubscriptionID=12345;CertificatePath=C:\\path_to_cert;ServiceManagementEndpoint=http://endpoint.com';
+
+ // Test
+ (function() {
+ ServiceManagementSettings.createFromConnectionString(connectionString);
+ }).should.throw('Invalid connection string setting key ' + invalidKey.toLowerCase());
+ });
+
+ test('testCreateFromConnectionStringWithCaseInsensitive', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = 'http://myprivatedns.com';
+ var connectionString = 'suBscriptIonId=' + expectedSubscriptionId + ';ceRtiFicAtepAth=' + expectedCertificatePath + ';ServiCemAnagemenTendPoinT=' + expectedEndpointUri;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
+});
View
@@ -13,6 +13,7 @@ services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/core/servicesettings-tests.js
services/core/servicebussettings-tests.js
+services/core/servicemanagementsettings-tests.js
services/core/storageservicesettings-tests.js
services/queue/queueservice-tests.js
services/table/batchserviceclient-tests.js

0 comments on commit 08804f2

Please sign in to comment.