Permalink
Browse files

Merge pull request #384 from andrerod/dev

Connection strings support
  • Loading branch information...
2 parents e112911 + f3eef81 commit 6cfaa1ab7a5836eba03b54d9e0607384a533c08b André Rodrigues committed Oct 15, 2012
Showing with 1,989 additions and 284 deletions.
  1. +5 −1 ChangeLog.txt
  2. +1 −1 examples/blobuploader/server.js
  3. +1 −1 examples/blog/blog.js
  4. +1 −1 examples/blog/public/stylesheets/style.css
  5. +3 −2 examples/geophoto/package.json
  6. +2 −2 examples/geophoto/services/pushpinService.js
  7. +3 −3 examples/geophoto/views/layout.ejs
  8. +2 −2 examples/myevents/server.js
  9. +1 −1 examples/tasklist/server.js
  10. +5 −0 lib/azure.js
  11. +10 −10 lib/services/blob/blobservice.js
  12. +8 −48 lib/services/core/servicebusserviceclient.js
  13. +137 −0 lib/services/core/servicebussettings.js
  14. +18 −26 lib/services/core/serviceclient.js
  15. +2 −10 lib/services/core/servicemanagementclient.js
  16. +120 −0 lib/services/core/servicemanagementsettings.js
  17. +238 −0 lib/services/core/servicesettings.js
  18. +99 −53 lib/services/core/storageserviceclient.js
  19. +296 −0 lib/services/core/storageservicesettings.js
  20. +9 −9 lib/services/queue/queueservice.js
  21. +42 −19 lib/services/serviceBus/servicebusservice.js
  22. +6 −4 lib/services/serviceBus/wrap.js
  23. +12 −29 lib/services/serviceBus/wrapservice.js
  24. +3 −4 lib/services/serviceBus/wraptokenmanager.js
  25. +2 −2 lib/services/serviceManagement/servicemanagementservice.js
  26. +2 −2 lib/services/table/batchserviceclient.js
  27. +11 −10 lib/services/table/tableservice.js
  28. +55 −0 lib/util/constants.js
  29. +38 −0 lib/util/util.js
  30. +50 −0 lib/util/validate.js
  31. +3 −2 package.json
  32. +13 −15 test/azure-tests.js
  33. +21 −14 test/services/blob/blobservice-tests.js
  34. +86 −0 test/services/core/servicebussettings-tests.js
  35. +94 −0 test/services/core/servicemanagementsettings-tests.js
  36. +59 −0 test/services/core/servicesettings-tests.js
  37. +310 −0 test/services/core/storageservicesettings-tests.js
  38. +16 −2 test/services/queue/queueservice-tests.js
  39. +44 −6 test/services/serviceBus/servicebusservice-tests.js
  40. +3 −1 test/services/table/tableservice-batch-tests.js
  41. +94 −4 test/services/table/tableservice-tests.js
  42. +5 −0 test/testlist.txt
  43. +19 −0 test/util/util-tests.js
  44. +40 −0 test/util/validate-tests.js
View
@@ -1,3 +1,7 @@
+2012.10.15 Version 0.6.7
+ * Adding connection strings support for storage and service bus
+ * Fixing issue with EMULATED and explicit variables making the later more relevant
+
2012.10.12 Version 0.6.6
* Using fixed version of commander.js to avoid bug in commander.js 1.0.5
@@ -33,7 +37,7 @@
* Multiple Bugfixes
2011.12.14 Version 0.5.1
- * Multiple bug fixes.
+ * Multiple bug fixes
2011.12.09 Version 0.5.0
* Initial Release
@@ -31,7 +31,7 @@ var helpers = require('./helpers.js');
var app = module.exports = express.createServer();
// Global request options, set the retryPolicy
-var blobClient = azure.createBlobService(azure.ServiceClient.DEVSTORE_STORAGE_ACCOUNT, azure.ServiceClient.DEVSTORE_STORAGE_ACCESS_KEY, azure.ServiceClient.DEVSTORE_BLOB_HOST).withFilter(new azure.ExponentialRetryPolicyFilter());
+var blobClient = azure.createBlobService('UseDevelopmentStorage=true').withFilter(new azure.ExponentialRetryPolicyFilter());
var containerName = 'webpi';
//Configuration
View
@@ -33,7 +33,7 @@ var tableName = 'posts';
var partition = 'part1';
Blog = function () {
- this.tableClient = azure.createTableService(ServiceClient.DEVSTORE_STORAGE_ACCOUNT, ServiceClient.DEVSTORE_STORAGE_ACCESS_KEY, ServiceClient.DEVSTORE_TABLE_HOST);
+ this.tableClient = azure.createTableService('UseDevelopmentStorage=true');
};
Blog.prototype.findAll = function (callback) {
@@ -1,7 +1,7 @@
body {
font-family: Tahoma, "Helvetica Neue", Arial, Helvetica, sans-serif;
font-size: 13px;
- text-stroke: 1px rgba(255,255,255,0.10);
+ text-stroke: 1px rgba(255,255,255,0.1);
color: #555;
background-color: #f3f4f5;
}
@@ -2,11 +2,12 @@
"name": "geophoto"
, "version": "0.0.1"
, "dependencies": {
- "azure": ">= 0.5.1"
- , "express": "2.5.1"
+ "express": "2.5.1"
, "ejs": ">= 0.0.1"
, "socket.io": "0.8.7"
, "node-uuid": ">= 1.3.3"
, "nconf": ">= 0.5.1"
+ , "uglify-js": ">= 1.3.3"
+ , "azure": ">= 0.5.1"
}
}
@@ -19,8 +19,8 @@ if (!fs.existsSync) {
}
var azure;
-if (fs.existsSync('./../../lib/azure.js')) {
- azure = require('./../../lib/azure');
+if (fs.existsSync('./../../../lib/azure.js')) {
+ azure = require('./../../../lib/azure');
} else {
azure = require('azure');
}
@@ -14,11 +14,11 @@
<script type="text/javascript" src="socket.io/socket.io.js"></script>
<script type="text/javascript">
- var bingMapsCredentials = '<%= bingMapsCredentials %>';
+ var bingMapsCredentials = '<% if (locals.bingMapsCredentials) { %><%= bingMapsCredentials %><% } %>';
var initialPushpins = [
- <% pushpins.forEach(function(pushpin) { %>
+ <% if (locals.pushpins) { pushpins.forEach(function(pushpin) { %>
{ title: '<%= pushpin.title %>', description: '<%= pushpin.description %>', latitude: '<%= pushpin.latitude %>', longitude: '<%= pushpin.longitude %>', RowKey: '<%= pushpin.RowKey %>', PartitionKey: '<%= pushpin.PartitionKey %>', imageUrl: '<%= pushpin.imageUrl %>' },
- <% }) %>
+ <% }) } %>
];
</script>
@@ -11,8 +11,8 @@ var express = require('express')
var app = module.exports = express.createServer();
-var tableClient = azure.createTableService(ServiceClient.DEVSTORE_STORAGE_ACCOUNT, ServiceClient.DEVSTORE_STORAGE_ACCESS_KEY, ServiceClient.DEVSTORE_TABLE_HOST);
-var blobClient = azure.createBlobService(azure.ServiceClient.DEVSTORE_STORAGE_ACCOUNT, azure.ServiceClient.DEVSTORE_STORAGE_ACCESS_KEY, azure.ServiceClient.DEVSTORE_BLOB_HOST).withFilter(new azure.ExponentialRetryPolicyFilter());
+var tableClient = azure.createTableService('UseDevelopmentStorage=true');
+var blobClient = azure.createBlobService('UseDevelopmentStorage=true').withFilter(new azure.ExponentialRetryPolicyFilter());
// Create table and blob
tableClient.createTableIfNotExists('events', function(error) {
@@ -32,7 +32,7 @@ var Home = require('./home');
var ServiceClient = azure.ServiceClient;
var app = module.exports = express.createServer();
-var client = azure.createTableService(ServiceClient.DEVSTORE_STORAGE_ACCOUNT, ServiceClient.DEVSTORE_STORAGE_ACCESS_KEY, ServiceClient.DEVSTORE_TABLE_HOST);
+var client = azure.createTableService('UseDevelopmentStorage=true');
// table creation
client.createTableIfNotExists("tasks", function (res, created) {
View
@@ -150,6 +150,11 @@ 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');
+exports.StorageServiceSettings = require('./services/core/storageservicesettings');
+exports.ServiceBusSettings = require('./services/core/servicebussettings');
+exports.ServiceManagementSettings = require('./services/core/servicemanagementsettings');
+exports.Validate = require('./util/validate');
/*
* Convenience functions.
@@ -16,6 +16,7 @@
// Module dependencies.
var fs = require('fs');
var qs = require('qs');
+var url = require('url');
var path = require('path');
var util = require('util');
var crypto = require('crypto');
@@ -76,15 +77,14 @@ BlobService.incorrectEndByteOffsetErr = 'End byte offset must be a modulus of 51
* @param {object} [authenticationProvider] The authentication provider.
*/
function BlobService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
- if (!host) {
- if (ServiceClient.isEmulated()) {
- host = ServiceClient.DEVSTORE_BLOB_HOST;
- } else {
- host = ServiceClient.CLOUD_BLOB_HOST;
- }
- }
+ var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
- BlobService.super_.call(this, storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider);
+ BlobService.super_.call(this,
+ storageServiceSettings._name,
+ storageServiceSettings._key,
+ storageServiceSettings._blobEndpointUri,
+ storageServiceSettings._usePathStyleUri,
+ authenticationProvider);
if (!this.authenticationProvider) {
this.authenticationProvider = new SharedKey(this.storageAccount, this.storageAccessKey, this.usePathStyleUri);
@@ -2177,7 +2177,7 @@ BlobService.prototype.generateSharedAccessSignature = function (container, blob,
var resourceName = createResourceName(container, blob);
var signedQueryString = this.sharedAccessSignatureCredentials.generateSignedQueryString(resourceName, {}, resourceType, sharedAccessPolicy);
- var baseUrl = this.protocol + this._getHostname() + ':' + this.port;
+ var baseUrl = this.protocol + this.host + ':' + this.port;
var path = this._getPath('/' + resourceName);
return {
@@ -2204,7 +2204,7 @@ BlobService.prototype.getBlobUrl = function (container, blob) {
var resourceName = createResourceName(container, blob);
- var baseUrl = this.protocol + this._getHostname() + ':' + this.port;
+ var baseUrl = this.protocol + this.host + ':' + this.port;
var path = this._getPath('/' + resourceName);
return {
@@ -33,49 +33,18 @@ exports = module.exports = ServiceBusServiceClient;
* Creates a new ServiceBusServiceClient object.
*
* @constructor
+* @param {string} accessKey The password.
+* @param {string} issuer The issuer.
* @param {string} host The host for the service.
-* @param {string} [namespace] The service bus namespace.
-* @param {string} [accessKey] The password.
-* @param {string} [issuer] The issuer.
-* @param {string} [acsNamespace] The acs namespace. Usually the same as the sb namespace with "-sb" suffix.
+* @param {string} acsHost The acs host. Usually the same as the sb namespace with "-sb" suffix.
* @param {object} [authenticationProvider] The authentication provider.
*/
-function ServiceBusServiceClient(host, namespace, accessKey, issuer, acsNamespace, authenticationProvider) {
- this.namespace = namespace;
- if (!this.namespace) {
- this.namespace = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_NAMESPACE];
- }
-
- this.acsNamespace = acsNamespace;
- if (!this.acsNamespace) {
- this.acsNamespace = process.env[ServiceClient.EnvironmentVariables.AZURE_WRAP_NAMESPACE];
-
- if (!this.acsNamespace) {
- this.acsNamespace = this.namespace + ServiceClient.DEFAULT_WRAP_NAMESPACE_SUFFIX;
- }
- }
-
- this.issuer = issuer;
- if (!this.issuer) {
- this.issuer = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_ISSUER];
-
- if (!this.issuer) {
- this.issuer = ServiceClient.DEFAULT_SERVICEBUS_ISSUER;
- }
- }
-
- this.accessKey = accessKey;
- if (!this.accessKey) {
- this.accessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_ACCESS_KEY];
- }
-
+function ServiceBusServiceClient(accessKey, issuer, host, acsHost, authenticationProvider) {
ServiceBusServiceClient.super_.call(this, host, authenticationProvider);
- this.protocol = 'https://';
- this.port = 443;
-
+ this.authenticationProvider = authenticationProvider;
if (!this.authenticationProvider) {
- this.authenticationProvider = new Wrap(this.acsNamespace, this.issuer, this.accessKey);
+ this.authenticationProvider = new Wrap(acsHost, issuer, accessKey);
}
}
@@ -100,7 +69,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
}
webResource.addOptionalHeader(HeaderConstants.ACCEPT_CHARSET_HEADER, 'UTF-8');
- webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this._getHostname() + ':' + this.port);
+ webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this.host + ':' + this.port);
// Sets the request url in the web resource.
this._setRequestUrl(webResource);
@@ -121,7 +90,7 @@ ServiceBusServiceClient.prototype._buildRequestOptions = function (webResource,
requestOptions = {
url: url.format({
protocol: self._isHttps() ? 'https:' : 'http:',
- hostname: self._getHostname(),
+ hostname: self.host,
port: self.port,
pathname: webResource.path + webResource.getQueryString(true)
}),
@@ -152,13 +121,4 @@ ServiceBusServiceClient.prototype._getPath = function (path) {
}
return path;
-};
-
-/**
-* Retrives the hostname.
-*
-* @return {string} The hostname.
-*/
-ServiceBusServiceClient.prototype._getHostname = function () {
- return this.namespace + '.' + this.host;
};
@@ -0,0 +1,137 @@
+/**
+* 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 = ServiceBusSettings;
+
+var serviceBusEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME, Validate.isValidUri);
+var wrapEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.WRAP_ENDPOINT_NAME, Validate.isValidUri);
+var wrapNameSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME);
+var wrapPasswordSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_VALUE_NAME);
+
+var validKeys = [
+ ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
+ ConnectionStringKeys.WRAP_ENDPOINT_NAME,
+ ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
+ ConnectionStringKeys.SHARED_SECRET_VALUE_NAME
+];
+
+/**
+* Creates new service bus settings instance.
+*
+* @param {string} serviceBusEndpointUri The Service Bus endpoint uri.
+* @param {string} wrapEndpointUri The Service Bus endpoint uri.
+* @param {string} namespace The service namespace.
+* @param {string} wrapName The wrap name.
+* @param {string} wrapPassword The wrap password.
+*/
+function ServiceBusSettings(serviceBusEndpointUri, wrapEndpointUri, namespace, wrapName, wrapPassword) {
+ this._namespace = namespace;
+ this._serviceBusEndpointUri = serviceBusEndpointUri;
+
+ if (wrapEndpointUri) {
+ this._wrapEndpointUri = wrapEndpointUri;
+ } else {
+ this._wrapEndpointUri = 'https://' + namespace + '-sb.accesscontrol.windows.net:443/WRAPv0.9';
+ }
+
+ this._wrapName = wrapName;
+ this._wrapPassword = wrapPassword;
+}
+
+/**
+* Creates a ServiceBusSettings object from a set of settings.
+*
+* @param {object} settings The settings object.
+*
+* @return {ServiceBusSettings}
+*/
+ServiceBusSettings.createFromSettings = function (settings) {
+ var matchedSpecs = ServiceSettings.matchedSpecification(
+ settings,
+ ServiceSettings.allRequired(
+ serviceBusEndpointSetting,
+ wrapNameSetting,
+ wrapPasswordSetting
+ ),
+ ServiceSettings.optional(wrapEndpointSetting)
+ );
+
+ if (matchedSpecs) {
+ var endpoint = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
+ settings
+ );
+
+ var wrapEndpoint = util.tryGetValueInsensitive(
+ ConnectionStringKeys.WRAP_ENDPOINT_NAME,
+ settings
+ );
+
+ // Parse the namespace part from the URI
+ var parsedUrl = url.parse(endpoint);
+ var namespace = parsedUrl.host.split('.')[0];
+
+ var issuerName = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
+ settings
+ );
+
+ var issuerValue = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SHARED_SECRET_VALUE_NAME,
+ settings
+ );
+
+ return new ServiceBusSettings(
+ endpoint,
+ wrapEndpoint,
+ namespace,
+ issuerName,
+ issuerValue
+ );
+ }
+
+ ServiceSettings.noMatchSettings(settings);
+};
+
+/**
+* Creates a ServiceBusSettings object from the given connection string.
+*
+* @param {string} connectionString The storage settings connection string.
+*
+* @return {ServiceBusSettings}
+*/
+ServiceBusSettings.createFromConnectionString = function (connectionString) {
+ var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
+ try {
+ return ServiceBusSettings.createFromSettings(tokenizedSettings);
+ } catch (e) {
+ if (e instanceof ServiceSettings.NoMatchError) {
+ // Replace no match settings exception by no match connection string one.
+ ServiceSettings.noMatchConnectionString(connectionString);
+ } else {
+ throw e;
+ }
+ }
+};
Oops, something went wrong.

0 comments on commit 6cfaa1a

Please sign in to comment.