Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #562 from andrerod/dev
Browse files Browse the repository at this point in the history
Sql Server Database wrappers
  • Loading branch information
André Rodrigues committed Jan 29, 2013
2 parents 799cf06 + aeeae1b commit db8ff69
Show file tree
Hide file tree
Showing 18 changed files with 830 additions and 79 deletions.
33 changes: 27 additions & 6 deletions lib/azure.js
Expand Up @@ -97,6 +97,27 @@ exports.createServiceBusService = function (namespaceOrConnectionString, accessK
return new ServiceBusService(namespaceOrConnectionString, accessKey, issuer, acsNamespace, host, authenticationProvider); return new ServiceBusService(namespaceOrConnectionString, accessKey, issuer, acsNamespace, host, authenticationProvider);
}; };


/**
* 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. * ServiceManagement client exports.
*/ */
Expand Down Expand Up @@ -127,14 +148,14 @@ exports.createServiceManagementService = function(subscriptionId, authentication
}; };


/** /**
* SqlDatabaseService client exports. * SqlManagementService client exports.
*/ */


var SqlDatabaseService = require('./services/serviceManagement/sqldatabaseservice'); var SqlManagementService = require('./services/serviceManagement/sqlmanagementservice');
exports.SqlDatabaseService = SqlDatabaseService; exports.SqlManagementService = SqlManagementService;


/** /**
* Creates a new SqlDatabaseService object. * Creates a new SqlManagementService object.
* *
* @param {string} subscriptionId The subscription ID for the account. * @param {string} subscriptionId The subscription ID for the account.
* @param {string} authentication The authentication object for the client. * @param {string} authentication The authentication object for the client.
Expand All @@ -151,8 +172,8 @@ exports.SqlDatabaseService = SqlDatabaseService;
* serializetype: 'XML' * serializetype: 'XML'
* } * }
*/ */
exports.createSqlDatabaseService = function(subscriptionId, authentication, hostOptions) { exports.createSqlManagementService = function(subscriptionId, authentication, hostOptions) {
return new SqlDatabaseService(subscriptionId, authentication, hostOptions); return new SqlManagementService(subscriptionId, authentication, hostOptions);
}; };


/** /**
Expand Down
1 change: 1 addition & 0 deletions lib/services/core/serviceclient.js
Expand Up @@ -72,6 +72,7 @@ ServiceClient.CLOUD_TABLE_HOST = 'table.core.windows.net';
ServiceClient.CLOUD_SERVICEBUS_HOST = 'servicebus.windows.net'; ServiceClient.CLOUD_SERVICEBUS_HOST = 'servicebus.windows.net';
ServiceClient.CLOUD_ACCESS_CONTROL_HOST = 'accesscontrol.windows.net'; ServiceClient.CLOUD_ACCESS_CONTROL_HOST = 'accesscontrol.windows.net';
ServiceClient.CLOUD_SERVICE_MANAGEMENT_HOST = 'management.core.windows.net'; ServiceClient.CLOUD_SERVICE_MANAGEMENT_HOST = 'management.core.windows.net';
ServiceClient.CLOUD_DATABASE_HOST = 'database.windows.net';


/** /**
* The default service bus issuer. * The default service bus issuer.
Expand Down
2 changes: 1 addition & 1 deletion lib/services/core/servicemanagementclient.js
Expand Up @@ -41,7 +41,7 @@ ServiceManagementClient.DefaultAPIVersion = '2012-03-01';
ServiceManagementClient.DefaultSerializeType = 'JSON'; ServiceManagementClient.DefaultSerializeType = 'JSON';


/** /**
* Creates a new ServiceClient object. * Creates a new ServiceManagementClient object.
* *
* @constructor * @constructor
* @param {string} hostOptions The host options to override defaults. * @param {string} hostOptions The host options to override defaults.
Expand Down
125 changes: 125 additions & 0 deletions lib/services/core/sqlserviceclient.js
@@ -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;
};
26 changes: 13 additions & 13 deletions lib/services/serviceBus/models/queueresult.js
Expand Up @@ -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) {
if (queue[ServiceBusConstants.LOCK_DURATION]) { if (queue[ServiceBusConstants.LOCK_DURATION]) {
queueDescription[ServiceBusConstants.LOCK_DURATION] = queue[ServiceBusConstants.LOCK_DURATION]; queueDescription[ServiceBusConstants.LOCK_DURATION] = queue[ServiceBusConstants.LOCK_DURATION];
Expand Down Expand Up @@ -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 atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue); var xml = atomHandler.serialize(atomQueue);


Expand Down
30 changes: 15 additions & 15 deletions lib/services/serviceBus/models/ruleresult.js
Expand Up @@ -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) { if (rule) {
var filters = []; var filters = [];
if (rule.sqlExpressionFilter) { if (rule.sqlExpressionFilter) {
Expand Down Expand Up @@ -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 atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomRule); var xml = atomHandler.serialize(atomRule);
return xml; return xml;
Expand Down
26 changes: 13 additions & 13 deletions lib/services/serviceBus/models/subscriptionresult.js
Expand Up @@ -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) {
if (subscription[ServiceBusConstants.LOCK_DURATION]) { if (subscription[ServiceBusConstants.LOCK_DURATION]) {
subscriptionDescription[ServiceBusConstants.LOCK_DURATION] = subscription[ServiceBusConstants.LOCK_DURATION]; subscriptionDescription[ServiceBusConstants.LOCK_DURATION] = subscription[ServiceBusConstants.LOCK_DURATION];
Expand Down Expand Up @@ -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 atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue); var xml = atomHandler.serialize(atomQueue);


Expand Down
26 changes: 13 additions & 13 deletions lib/services/serviceBus/models/topicresult.js
Expand Up @@ -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) {
if (topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE]) { if (topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE]) {
topicDescription[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE] = topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE]; topicDescription[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE] = topic[ServiceBusConstants.DEFAULT_MESSAGE_TIME_TO_LIVE];
Expand All @@ -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 atomHandler = new AtomHandler(null, null);
var xml = atomHandler.serialize(atomQueue); var xml = atomHandler.serialize(atomQueue);
return xml; return xml;
Expand Down

0 comments on commit db8ff69

Please sign in to comment.