Permalink
Browse files

Implementing storageservicesettings ...

  • Loading branch information...
1 parent 8c489a3 commit cc4f916e726fcfe429a448eb748abb860653d810 Andre Rodrigues committed Oct 10, 2012
Showing with 164 additions and 0 deletions.
  1. +12 −0 lib/services/core/servicesettings.js
  2. +128 −0 lib/services/core/storageservicesettings.js
  3. +24 −0 lib/util/constants.js
@@ -20,6 +20,18 @@ var ConnectionStringParser = require('./connectionstringparser');
exports = module.exports;
/**
+* Throws an exception if the connection string format does not match any of the
+* available formats.
+*
+* @param {string} connectionString The invalid formatted connection string.
+*
+* @return none
+*/
+exports.noMatch = function (connectionString) {
+ throw new Error('The provided connection string ' + connectionString + ' does not have complete configuration settings.');
+};
+
+/**
* Parses the connection string and then validate that the parsed keys belong to
* the $validSettingKeys
*
@@ -0,0 +1,128 @@
+/**
+* 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');
+
+var ConnectionStringParser = require('./connectionstringparser');
+var ServiceSettings = require('./servicesettings');
+var Constants = require('../../util/constants');
+var ConnectionStringKeys = Constants.ConnectionStringKeys;
+
+exports = module.exports = StorageServiceSettings;
+
+var validKeys = [
+ ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME,
+ ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME,
+ ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME,
+ ConnectionStringKeys.ACCOUNT_NAME_NAME,
+ ConnectionStringKeys.ACCOUNT_KEY_NAME,
+ ConnectionStringKeys.BLOB_ENDPOINT_NAME,
+ ConnectionStringKeys.QUEUE_ENDPOINT_NAME,
+ ConnectionStringKeys.TABLE_ENDPOINT_NAME
+];
+
+/**
+* Creates new storage service settings instance.
+*
+* @param {string} name The storage service name.
+* @param {string} key The storage service key.
+* @param {string} blobEndpointUri The storage service blob endpoint.
+* @param {string} queueEndpointUri The storage service queue endpoint.
+* @param {string} tableEndpointUri The storage service table endpoint.
+*/
+function StorageServiceSettings(name, key, blobEndpointUri, queueEndpointUri, tableEndpointUri) {
+ this._name = name;
+ this._key = key;
+ this._blobEndpointUri = blobEndpointUri;
+ this._queueEndpointUri = queueEndpointUri;
+ this._tableEndpointUri = tableEndpointUri;
+}
+
+/**
+* Creates StorageServiceSettings object given endpoints uri.
+*
+* @param {array} settings The service settings.
+* @param {string} blobEndpointUri The blob endpoint uri.
+* @param {string} queueEndpointUri The queue endpoint uri.
+* @param {string} tableEndpointUri The table endpoint uri.
+*
+* @return {StorageServiceSettings}
+*/
+StorageServiceSettings._createStorageServiceSettings = function (
+ settings, blobEndpointUri, queueEndpointUri, tableEndpointUri
+) {
+ blobEndpointUri = util.tryGetValueInsensitive(
+ ConnectionStringKeys.BLOB_ENDPOINT_NAME,
+ settings,
+ blobEndpointUri
+ );
+
+ queueEndpointUri = util.tryGetValueInsensitive(
+ ConnectionStringKeys.QUEUE_ENDPOINT_NAME,
+ settings,
+ queueEndpointUri
+ );
+
+ tableEndpointUri = util.tryGetValueInsensitive(
+ ConnectionStringKeys.TABLE_ENDPOINT_NAME,
+ settings,
+ tableEndpointUri
+ );
+
+ accountName = util.tryGetValueInsensitive(
+ ConnectionStringKeys.ACCOUNT_NAME_NAME,
+ settings
+ );
+
+ accountKey = util.tryGetValueInsensitive(
+ ConnectionStringKeys.ACCOUNT_KEY_NAME,
+ settings
+ );
+
+ return new StorageServiceSettings(
+ accountName,
+ accountKey,
+ blobEndpointUri,
+ queueEndpointUri,
+ tableEndpointUri
+ );
+};
+
+/**
+* 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);
+
+ return this._createStorageServiceSettings(
+ tokenizedSettings,
+ this._getDefaultServiceEndpoint(
+ tokenizedSettings,
+ ConnectionStringKeys.BLOB_BASE_DNS_NAME
+ ),
+ this._getDefaultServiceEndpoint(
+ tokenizedSettings,
+ ConnectionStringKeys.QUEUE_BASE_DNS_NAME
+ ),
+ this._getDefaultServiceEndpoint(
+ tokenizedSettings,
+ ConnectionStringKeys.TABLE_BASE_DNS_NAME
+ )
+ );
+};
View
@@ -2556,6 +2556,30 @@ var Constants = {
GeneralErrorCodeStrings: {
INVALID_CONTENT_TYPE: 'The response content type is invalid'
+ },
+
+ ConnectionStringKeys: {
+ USE_DEVELOPMENT_STORAGE_NAME: 'UseDevelopmentStorage',
+ DEVELOPMENT_STORAGE_PROXY_URI_NAME: 'DevelopmentStorageProxyUri',
+ DEFAULT_ENDPOINTS_PROTOCOL_NAME: 'DefaultEndpointsProtocol',
+ ACCOUNT_NAME_NAME: 'AccountName',
+ ACCOUNT_KEY_NAME: 'AccountKey',
+ BLOB_ENDPOINT_NAME: 'BlobEndpoint',
+ QUEUE_ENDPOINT_NAME: 'QueueEndpoint',
+ TABLE_ENDPOINT_NAME: 'TableEndpoint',
+ SHARED_ACCESS_SIGNATURE_NAME: 'SharedAccessSignature',
+ DEV_STORE_NAME: 'devstoreaccount1',
+ DEV_STORE_KEY: 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',
+ BLOB_BASE_DNS_NAME: 'blob.core.windows.net',
+ QUEUE_BASE_DNS_NAME: 'queue.core.windows.net',
+ TABLE_BASE_DNS_NAME: 'table.core.windows.net',
+ DEV_STORE_CONNECTION_STRING: 'BlobEndpoint=127.0.0.1:10000;QueueEndpoint=127.0.0.1:10001;TableEndpoint=127.0.0.1:10002;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',
+ SUBSCRIPTION_ID_NAME: 'SubscriptionID',
+ CERTIFICATE_PATH_NAME: 'CertificatePath',
+ SERVICE_MANAGEMENT_ENDPOINT_NAME: 'ServiceManagementEndpoint',
+ SERVICE_BUS_ENDPOINT_NAME: 'Endpoint',
+ SHARED_SECRET_ISSUER_NAME: 'SharedSecretIssuer',
+ SHARED_SECRET_VALUE_NAME: 'SharedSecretValue'
}
};

0 comments on commit cc4f916

Please sign in to comment.