From a4284d310a8d955cfb71c204918dc54e5c79ace0 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Thu, 8 Nov 2012 15:18:17 +0000 Subject: [PATCH 1/2] Adding missing storage account operations --- .../models/servicemanagementserialize.js | 75 +++++++++++++++ .../servicemanagementservice.js | 92 ++++++++++++++++++- 2 files changed, 166 insertions(+), 1 deletion(-) diff --git a/lib/services/serviceManagement/models/servicemanagementserialize.js b/lib/services/serviceManagement/models/servicemanagementserialize.js index dad6a7d17..175a2d6e0 100644 --- a/lib/services/serviceManagement/models/servicemanagementserialize.js +++ b/lib/services/serviceManagement/models/servicemanagementserialize.js @@ -130,6 +130,81 @@ ServiceManagementSerialize.prototype.buildCreateStorageAccount = function(servic } }; +/** +* Create the message body for UpdateStorageAccount +* +* @param {string} serviceName The name of the service. +* @param {object} serviceOptions The properties for the new service. +* @param {object} client The servicemanagement object. +*/ +ServiceManagementSerialize.prototype.buildUpdateStorageAccount = function(serviceName, serviceOptions, client) { + var encLabel = undefined; + if (serviceOptions.Label) { + encLabel = new Buffer(serviceOptions.Label).toString('base64'); + } + + if (client.serializetype === 'XML') { + var doc = _createXmlRoot('UpdateStorageServiceInput'); + _addDefinedValueXml(doc, 'ServiceName', serviceName); + + if (encLabel) { + _addDefinedValueXml(doc, 'Label', encLabel); + } + + if (serviceOptions.Description) { + _addDefinedValueXml(doc, 'Description', serviceOptions.Description); + } + + if (serviceOptions.GeoReplicationEnabled) { + _addDefinedValueXml(doc, 'GeoReplicationEnabled', serviceOptions.GeoReplicationEnabled); + } + + return doc.toString(); + } else { + var jdoc = { + ServiceName: serviceName + }; + + if (encLabel) { + jdoc.Label = encLabel; + } + + if (serviceOptions.Description) { + jdoc.Description = serviceOptions.Description; + } + + if (serviceOptions.GeoReplicationEnabled) { + jdoc.GeoReplicationEnabled = serviceOptions.GeoReplicationEnabled; + } + + return JSON.stringify(jdoc); + } +}; + +/** +* Create the message body for RegenerateStorageKeys +* +* @param {string} serviceName The name of the service. +* @param {string} keyType The key type. +* @param {object} client The servicemanagement object. +*/ +ServiceManagementSerialize.prototype.buildRegenerateStorageKeys = function(serviceName, keyType, client) { + if (client.serializetype === 'XML') { + var doc = _createXmlRoot('RegenerateKeys'); + doc.ele('KeyType').txt(keyType); + + return doc.toString(); + } else { + var jdoc = { + RegenerateKeys: { + KeyType: keyType + } + }; + + return JSON.stringify(jdoc); + } +}; + /** * Create the message body for CreateOSImage * Use the specified serialization - for now only XML. diff --git a/lib/services/serviceManagement/servicemanagementservice.js b/lib/services/serviceManagement/servicemanagementservice.js index 3243c1130..aae84029e 100644 --- a/lib/services/serviceManagement/servicemanagementservice.js +++ b/lib/services/serviceManagement/servicemanagementservice.js @@ -570,7 +570,7 @@ ServiceManagementService.prototype.deleteHostedService = function(serviceName, c }; /** -* Returns keys of specified storage account. +* Creates a new storage account. * * @param {string} serviceName The name of the storage service. Required. * @param {string} serviceOptions Object with properties for the service. Optional @@ -628,6 +628,44 @@ ServiceManagementService.prototype.createStorageAccount = function(serviceName, }); }; +/** +* Updates a storage account. +* +* @param {string} serviceName The name of the storage service. Required. +* @param {string} serviceOptions Object with properties for the service. Optional +* { +* Description: optional. Defaults to 'Service host' +* Label: optional. Defaults to serviceName +* GeoReplicationEnabled: optional. Indicates if the geo replication is enabled. +* } +* @param {function} callback The callback function called on completion. Required. +*/ +ServiceManagementService.prototype.updateStorageAccount = function(serviceName, serviceOptions, callback) { + if (!callback) { + if (typeof serviceOptions === 'function') { + callback = serviceOptions; + serviceOptions = null; + } + } + + validateStringArgument(serviceName, 'serviceName', 'updateStorageAccount'); + validateObjectArgument(callback, 'callback', 'updateStorageAccount'); + + var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName; + var webResource = WebResource.put(path); + webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true); + + var outbody = this.serialize.buildUpdateStorageAccount(serviceName, serviceOptions, this); + this.performRequest(webResource, outbody, null, function (responseObject, next) { + + var finalCallback = function (returnObject) { + callback(returnObject.error, returnObject.response); + }; + + next(responseObject, finalCallback); + }); +}; + /** * Returns keys of specified storage account. * @@ -679,6 +717,58 @@ ServiceManagementService.prototype.getStorageAccountProperties = function(servic }); }; +/** +* Regenerates a storage account's keys +* +* @param {string} serviceName The name of the hosted service. Required. +* @param {string} keyType The storage key type (primary or secondary). Required. +* @param {function} callback The callback function called on completion. Required. +*/ +ServiceManagementService.prototype.regenerateStorageAccountKeys = function(serviceName, keyType, callback) { + validateStringArgument(serviceName, 'serviceName', 'deleteDeployment'); + validateObjectArgument(callback, 'callback', 'deleteDeployment'); + + var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName + '/keys?action=regenerate'; + var webResource = WebResource.post(path); + webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true); + var outbody = this.serialize.buildRegenerateStorageKeys(serviceName, keyType, this); + + + + this.performRequest(webResource, outbody, null, function (responseObject, next) { + + var finalCallback = function (returnObject) { + callback(returnObject.error, returnObject.response); + }; + + next(responseObject, finalCallback); + }); +}; + +/** +* Deletes a storage account +* +* @param {string} serviceName The name of the hosted service. Required. +* @param {function} callback The callback function called on completion. Required. +*/ +ServiceManagementService.prototype.deleteStorageAccount = function(serviceName, callback) { + validateStringArgument(serviceName, 'serviceName', 'deleteDeployment'); + validateObjectArgument(callback, 'callback', 'deleteDeployment'); + + var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName; + var webResource = WebResource.del(path); + webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true); + + this.performRequest(webResource, null, null, function (responseObject, next) { + + var finalCallback = function (returnObject) { + callback(returnObject.error, returnObject.response); + }; + + next(responseObject, finalCallback); + }); +}; + /** * Gets deployment properties for named deployment * From 42e71f5f9f9930f565aad13c74e07acad3017657 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Wed, 14 Nov 2012 16:58:31 +0000 Subject: [PATCH 2/2] Applying review comments. --- lib/services/serviceManagement/servicemanagementservice.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/services/serviceManagement/servicemanagementservice.js b/lib/services/serviceManagement/servicemanagementservice.js index aae84029e..9fac7e13a 100644 --- a/lib/services/serviceManagement/servicemanagementservice.js +++ b/lib/services/serviceManagement/servicemanagementservice.js @@ -728,6 +728,10 @@ ServiceManagementService.prototype.regenerateStorageAccountKeys = function(servi validateStringArgument(serviceName, 'serviceName', 'deleteDeployment'); validateObjectArgument(callback, 'callback', 'deleteDeployment'); + if (keyType.toLowerCase() !== 'primary' && keyType.toLowerCase() !== 'secondary') { + throw new Error('Invalid storage account type'); + } + var path = '/' + this.subscriptionId + '/services/storageservices/' + serviceName + '/keys?action=regenerate'; var webResource = WebResource.post(path); webResource.withOkCode(HttpConstants.HttpResponseCodes.OK_CODE, true);