Permalink
Browse files

Merge pull request #562 from andrerod/dev

Sql Server Database wrappers
  • Loading branch information...
2 parents 799cf06 + aeeae1b commit db8ff69bfc530ece7ee1383e1cde3571516bdc66 André Rodrigues committed Jan 29, 2013
View
@@ -98,6 +98,27 @@ exports.createServiceBusService = function (namespaceOrConnectionString, accessK
};
/**
+* SqlService client exports.
+*/
+
+var SqlService = require('./services/sqlAzure/sqlservice');
+exports.SqlService = SqlService;
+
+/**
+* Creates a new SqlManagementService object.
+*
+* @param {string} serverName The SQL server name.
+* @param {string} administratorLogin The SQL Server administrator login.
+* @param {string} administratorLoginPassword The SQL Server administrator login password.
+* @param {string} [host] The host for the service.
+* @param {string} [acsHost] The acs host.
+* @param {object} [authenticationProvider] The authentication provider.
+*/
+exports.createSqlService = function(serverName, administratorLogin, administratorLoginPassword, host, acsHost, authenticationProvider) {
+ return new SqlService(serverName, administratorLogin, administratorLoginPassword, host, acsHost, authenticationProvider);
+};
+
+/**
* ServiceManagement client exports.
*/
@@ -127,14 +148,14 @@ exports.createServiceManagementService = function(subscriptionId, authentication
};
/**
-* SqlDatabaseService client exports.
+* SqlManagementService client exports.
*/
-var SqlDatabaseService = require('./services/serviceManagement/sqldatabaseservice');
-exports.SqlDatabaseService = SqlDatabaseService;
+var SqlManagementService = require('./services/serviceManagement/sqlmanagementservice');
+exports.SqlManagementService = SqlManagementService;
/**
-* Creates a new SqlDatabaseService object.
+* Creates a new SqlManagementService object.
*
* @param {string} subscriptionId The subscription ID for the account.
* @param {string} authentication The authentication object for the client.
@@ -151,8 +172,8 @@ exports.SqlDatabaseService = SqlDatabaseService;
* serializetype: 'XML'
* }
*/
-exports.createSqlDatabaseService = function(subscriptionId, authentication, hostOptions) {
- return new SqlDatabaseService(subscriptionId, authentication, hostOptions);
+exports.createSqlManagementService = function(subscriptionId, authentication, hostOptions) {
+ return new SqlManagementService(subscriptionId, authentication, hostOptions);
};
/**
@@ -72,6 +72,7 @@ ServiceClient.CLOUD_TABLE_HOST = 'table.core.windows.net';
ServiceClient.CLOUD_SERVICEBUS_HOST = 'servicebus.windows.net';
ServiceClient.CLOUD_ACCESS_CONTROL_HOST = 'accesscontrol.windows.net';
ServiceClient.CLOUD_SERVICE_MANAGEMENT_HOST = 'management.core.windows.net';
+ServiceClient.CLOUD_DATABASE_HOST = 'database.windows.net';
/**
* The default service bus issuer.
@@ -41,7 +41,7 @@ ServiceManagementClient.DefaultAPIVersion = '2012-03-01';
ServiceManagementClient.DefaultSerializeType = 'JSON';
/**
-* Creates a new ServiceClient object.
+* Creates a new ServiceManagementClient object.
*
* @constructor
* @param {string} hostOptions The host options to override defaults.
@@ -0,0 +1,125 @@
+/**
+* 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.
+*/
+
+// Module dependencies.
+var util = require('util');
+var url = require('url');
+
+var azureutil = require('../../util/util');
+
+var ServiceClient = require('./serviceclient');
+var SqlServerAcs = require('../sqlAzure/sqlserveracs');
+var Constants = require('../../util/constants');
+var HeaderConstants = Constants.HeaderConstants;
+var QueryStringConstants = Constants.QueryStringConstants;
+var HttpConstants = Constants.HttpConstants;
+
+// Expose 'SqlServiceClient'.
+exports = module.exports = SqlServiceClient;
+
+/**
+* Creates a new SqlServiceClient object.
+*
+* @constructor
+* @param {string} serverName The SQL server name.
+* @param {string} administratorLogin The SQL Server administrator login.
+* @param {string} administratorLoginPassword The SQL Server administrator login password.
+* @param {string} host The host for the service.
+* @param {string} acsHost The acs host. Usually the same as the sb namespace with "-sb" suffix.
+* @param {object} [authenticationProvider] The authentication provider.
+*/
+function SqlServiceClient(serverName, administratorLogin, administratorLoginPassword, host, acsHost, authenticationProvider) {
+ SqlServiceClient.super_.call(this, host, authenticationProvider);
+
+ this.authenticationProvider = authenticationProvider;
+ if (!this.authenticationProvider) {
+ this.authenticationProvider = new SqlServerAcs(acsHost, serverName, administratorLogin, administratorLoginPassword);
+ }
+}
+
+util.inherits(SqlServiceClient, ServiceClient);
+
+/**
+* Builds the request options to be passed to the http.request method.
+*
+* @param {WebResource} webResource The webresource where to build the options from.
+* @param {object} options The request options.
+* @param {function(error, requestOptions)} callback The callback function.
+*/
+SqlServiceClient.prototype._buildRequestOptions = function (webResource, options, callback) {
+ var self = this;
+
+ if (!webResource.headers || !webResource.headers[HeaderConstants.CONTENT_TYPE]) {
+ webResource.addOptionalHeader(HeaderConstants.CONTENT_TYPE, '');
+ }
+
+ if (!webResource.headers || !webResource.headers[HeaderConstants.CONTENT_LENGTH]) {
+ webResource.addOptionalHeader(HeaderConstants.CONTENT_LENGTH, 0);
+ }
+
+ webResource.addOptionalHeader(HeaderConstants.ACCEPT_CHARSET_HEADER, 'UTF-8');
+ webResource.addOptionalHeader(HeaderConstants.HOST_HEADER, this.host + ':' + this.port);
+
+ // Sets the request url in the web resource.
+ this._setRequestUrl(webResource);
+
+ // If wrap is used, make sure proxy settings are in sync
+ if (this.useProxy &&
+ this.authenticationProvider &&
+ this.authenticationProvider.wrapTokenManager &&
+ this.authenticationProvider.wrapTokenManager.wrapService) {
+ this.authenticationProvider.wrapTokenManager.wrapService.setProxy(this.proxyUrl, this.proxyPort);
+ }
+
+ // Now that the web request is finalized, sign it
+ this.authenticationProvider.signRequest(webResource, function (error) {
+ var requestOptions = null;
+
+ if (!error) {
+ requestOptions = {
+ url: url.format({
+ protocol: self._isHttps() ? 'https:' : 'http:',
+ hostname: self.host,
+ port: self.port,
+ pathname: webResource.path + webResource.getQueryString(true)
+ }),
+ method: webResource.httpVerb,
+ headers: webResource.headers
+ };
+
+ self._setRequestOptionsProxy(requestOptions);
+ }
+
+ callback(error, requestOptions);
+ });
+};
+
+/**
+* Retrieves the normalized path to be used in a request.
+* It adds a leading "/" to the path in case
+* it's not there before.
+*
+* @param {string} path The path to be normalized.
+* @return {string} The normalized path.
+*/
+SqlServiceClient.prototype._getPath = function (path) {
+ if (path === null || path === undefined) {
+ path = '/';
+ } else if (path.indexOf('/') !== 0) {
+ path = '/' + path;
+ }
+
+ return path;
+};
@@ -37,19 +37,6 @@ QueueResult.serialize = function (path, queue) {
}
};
- var atomQueue = {
- 'title': '',
- 'updated': ISO8061Date.format(new Date()),
- 'author': {
- name: ''
- },
- 'id': '',
- 'content': {
- '$': { type: 'application/xml' },
- QueueDescription: queueDescription
- }
- };
-
if (queue) {
if (queue[ServiceBusConstants.LOCK_DURATION]) {
queueDescription[ServiceBusConstants.LOCK_DURATION] = queue[ServiceBusConstants.LOCK_DURATION];
@@ -96,6 +83,19 @@ QueueResult.serialize = function (path, queue) {
}
}
+ var atomQueue = {
+ 'title': '',
+ 'updated': ISO8061Date.format(new Date()),
+ 'author': {
+ name: ''
+ },
+ 'id': '',
+ 'content': {
+ '$': { type: 'application/xml' },
+ QueueDescription: queueDescription
+ }
+ };
+
var atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue);
@@ -34,21 +34,6 @@ RuleResult.serialize = function (name, path, rule) {
}
};
- var atomRule = {
- 'title': {
- '$': {
- 'type': 'text'
- },
- '_': name
- },
- 'updated': ISO8061Date.format(new Date()),
- 'id': '',
- 'content': {
- '$': { type: 'application/xml' },
- RuleDescription: ruleDescription
- }
- };
-
if (rule) {
var filters = [];
if (rule.sqlExpressionFilter) {
@@ -122,6 +107,21 @@ RuleResult.serialize = function (name, path, rule) {
}
}
+ var atomRule = {
+ 'title': {
+ '$': {
+ 'type': 'text'
+ },
+ '_': name
+ },
+ 'updated': ISO8061Date.format(new Date()),
+ 'id': '',
+ 'content': {
+ '$': { type: 'application/xml' },
+ RuleDescription: ruleDescription
+ }
+ };
+
var atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomRule);
return xml;
@@ -35,19 +35,6 @@ SubscriptionResult.serialize = function (path, subscription) {
}
};
- var atomQueue = {
- 'title': '',
- 'updated': ISO8061Date.format(new Date()),
- 'author': {
- name: ''
- },
- 'id': '',
- 'content': {
- '$': { type: 'application/xml' },
- SubscriptionDescription: subscriptionDescription
- }
- };
-
if (subscription) {
if (subscription[ServiceBusConstants.LOCK_DURATION]) {
subscriptionDescription[ServiceBusConstants.LOCK_DURATION] = subscription[ServiceBusConstants.LOCK_DURATION];
@@ -86,6 +73,19 @@ SubscriptionResult.serialize = function (path, subscription) {
}
}
+ var atomQueue = {
+ 'title': '',
+ 'updated': ISO8061Date.format(new Date()),
+ 'author': {
+ name: ''
+ },
+ 'id': '',
+ 'content': {
+ '$': { type: 'application/xml' },
+ SubscriptionDescription: subscriptionDescription
+ }
+ };
+
var atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue);
@@ -35,19 +35,6 @@ TopicResult.serialize = function (path, topic) {
}
};
- var atomQueue = {
- 'title': '',
- 'updated': ISO8061Date.format(new Date()),
- 'author': {
- name: ''
- },
- 'id': '',
- 'content': {
- '$': { type: 'application/xml' },
- TopicDescription: topicDescription
- }
- };
-
if (topic) {
if (topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE]) {
topicDescription[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE] = topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE];
@@ -74,6 +61,19 @@ TopicResult.serialize = function (path, topic) {
}
}
+ var atomQueue = {
+ 'title': '',
+ 'updated': ISO8061Date.format(new Date()),
+ 'author': {
+ name: ''
+ },
+ 'id': '',
+ 'content': {
+ '$': { type: 'application/xml' },
+ TopicDescription: topicDescription
+ }
+ };
+
var atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue);
return xml;
Oops, something went wrong.

0 comments on commit db8ff69

Please sign in to comment.