Permalink
Browse files

Merge pull request #16 from andrerod/cli

#439: Add CRUD support for storage accounts
  • Loading branch information...
André Rodrigues
André Rodrigues committed Nov 14, 2012
2 parents 76ec049 + 42e71f5 commit 747db082aa12cbc1157cbfac17730c991651a6e8
@@ -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.
@@ -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,62 @@ 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');
+
+ 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);
+ 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
*

0 comments on commit 747db08

Please sign in to comment.