Permalink
Browse files

Merge pull request #11 from andrerod/dev

#439: Add CRUD support for storage accounts
  • Loading branch information...
2 parents 6d0910a + 854f771 commit 10e7c235ff255f8276cda74b7bb0b0c674d1ea7c André Rodrigues committed Nov 14, 2012
Showing with 499 additions and 75 deletions.
  1. +59 −69 lib/commands/account.js
  2. +261 −0 lib/commands/storage.js
  3. +4 −5 lib/iaas/upload/pageBlob.js
  4. +173 −0 test/commands/cli.storage-tests.js
  5. +2 −1 test/testlist.txt
View
@@ -85,12 +85,11 @@ exports.init = function (cli) {
}
var subscriptionObject = filtered[0];
- var cfg = account.readConfig();
-
var subscriptionTag = importByName ? subscriptionObject.Name : subscriptionObject.Id;
log.info('Setting subscription to \'' + subscriptionTag + '\'');
- cfg.subscription = subscriptionObject.Id;
- account.writeConfig(cfg);
+
+ setSubscription(subscriptionObject.Id)
+
log.info('Changes saved.');
});
@@ -155,16 +154,11 @@ exports.init = function (cli) {
}
return callback();
- function convertPfx(pfx) {
- var pem = pfx2pem(pfx);
- utils.writeFileSyncMode(pemPath, pem.toString(), 'utf8');
- log.verbose('Converted PFX data to ' + pemPath);
- }
-
function processSettings(file, settings) {
if (!settings.PublishProfile ||
!settings.PublishProfile['@'] ||
- !settings.PublishProfile['@'].ManagementCertificate) {
+ (!settings.PublishProfile['@'].ManagementCertificate &&
+ !(settings.PublishProfile['@'].SchemaVersion === '2.0'))) {
throw new Error('Invalid publishSettings file. Use "azure account download" to download publishing credentials.');
}
@@ -176,6 +170,15 @@ exports.init = function (cli) {
subs = [subs];
}
+ if (subs.length === 0) {
+ log.warning('Importing profile with no subscriptions');
+ } else {
+ for (var index in subs) {
+ log.info('Found subscription:', subs[index]['@'].Name);
+ log.verbose(' Id:', subs[index]['@'].Id);
+ }
+ }
+
if (attribs.Url) {
var endpointInfo = utils.validateEndpoint(attribs.Url);
var config = account.readConfig();
@@ -184,29 +187,21 @@ exports.init = function (cli) {
log.info('Setting service endpoint to:', config.endpoint);
}
- if (subs.length === 0) {
- log.warning('Importing profile with no subscriptions');
- }
- else {
- for (var index in subs) {
- log.info('Found subscription:', subs[index]['@'].Name);
- log.verbose(' Id:', subs[index]['@'].Id);
- }
+ if (attribs.ManagementCertificate) {
+ log.verbose('Parsing management certificate');
+ var pfx = new Buffer(attribs.ManagementCertificate, 'base64');
+ convertPfx(pfx);
}
- log.verbose('Parsing management certificate');
- var pfx = new Buffer(attribs.ManagementCertificate, 'base64');
- convertPfx(pfx);
-
log.verbose('Storing account information at', publishSettingsFilePath);
utils.writeFileSyncMode(publishSettingsFilePath, readBuffer); // folder already created by convertPfx()
if (subs.length !== 0) {
log.info('Setting default subscription to:', subs[0]['@'].Name);
log.info('Use "azure account set" to change to a different one.')
- var config = account.readConfig();
- config.subscription = subs[0]['@'].Name;
- account.writeConfig(config);
+
+ setSubscription(subs[0]['@'].Id);
}
+
log.warn('The \'' + file + '\' file contains sensitive information.');
log.warn('Remember to delete it now that it has been imported.');
log.info('Account publish settings imported successfully');
@@ -286,44 +281,6 @@ exports.init = function (cli) {
}
account.listLAG = listLAG;
- var storage = account.category('storage')
- .description('Commands to manage your Azure storage account');
-
- storage.command('list')
- .description('List storage accounts available for your account')
- .execute(function (options, callback) {
- var channel = utils.createServiceManagementService(cli.category('account').lookupSubscriptionId(options.subscription),
- cli.category('account'), log);
-
- var progress = cli.progress('Fetching storage accounts');
- utils.doServiceManagementOperation(channel, 'listStorageAccounts', function (error, response) {
- progress.end();
- if (!error) {
- if (response.body.length > 0) {
- log.table(response.body, function (row, item) {
- row.cell('Name', item.ServiceName);
- var storageServiceProperties = item.StorageServiceProperties;
- if ('Label' in storageServiceProperties) {
- row.cell('Label', Buffer(storageServiceProperties.Label, 'base64').toString());
- }
- // This will display affinity group GUID and GeoPrimaryLocation (if present) if Location is not present
- // Affinity group or location display name is not present in the data
- row.cell('Location', storageServiceProperties.Location ||
- (storageServiceProperties.AffinityGroup || '') +
- (storageServiceProperties.GeoPrimaryRegion ? ' (' + storageServiceProperties.GeoPrimaryRegion + ')' : ''));
- });
- } else {
- if (log.format().json) {
- log.json([]);
- } else {
- log.info('No storage accounts found');
- }
- }
- }
- callback(error);
- });
- });
-
account.readPublishSettings = function () {
var publishSettings = {};
@@ -340,7 +297,7 @@ exports.init = function (cli) {
return publishSettings;
};
- account.readSubscriptions = function () {
+ function readSubscriptions () {
if (!utils.pathExistsSync(publishSettingsFilePath)) {
throw new Error('No publish settings file found. Please use "azure account import" first.');
}
@@ -375,10 +332,7 @@ exports.init = function (cli) {
} else {
var subscriptions = [];
for (var s in subs) {
- subscriptions[s] = {
- Name: subs[s]['@'].Name,
- Id: subs[s]['@'].Id
- };
+ subscriptions[s] = subs[s]['@'];
}
return subscriptions;
@@ -387,6 +341,42 @@ exports.init = function (cli) {
throw new Error('Invalid publish settings file.')
}
}
+ account.readSubscriptions = readSubscriptions;
+
+ function setSubscription (id) {
+ var subscriptions = readSubscriptions();
+ var subscription = subscriptions.filter(function (subscription) {
+ return subscription.Id === id;
+ })[0];
+
+ if (!subscription) {
+ throw new Error('Invalid subscription ' + id);
+ } else {
+ var config = account.readConfig();
+
+ if (subscription.ServiceManagementUrl && subscription.ServiceManagementUrl !== config.endpoint) {
+ var endpointInfo = utils.validateEndpoint(subscription.ServiceManagementUrl);
+ config.endpoint = endpointInfo;
+ log.info('Setting service endpoint to:', config.endpoint);
+ }
+
+ if (subscription.ManagementCertificate) {
+ log.verbose('Parsing management certificate');
+ var pfx = new Buffer(subscription.ManagementCertificate, 'base64');
+ convertPfx(pfx);
+ }
+
+ config.subscription = id;
+ account.writeConfig(config);
+ }
+ }
+ account.setSubscription = setSubscription;
+
+ function convertPfx(pfx) {
+ var pem = pfx2pem(pfx);
+ utils.writeFileSyncMode(pemPath, pem.toString(), 'utf8');
+ log.verbose('Converted PFX data to ' + pemPath);
+ }
account.defaultSubscriptionId = function () {
return account.readConfig().subscription;
Oops, something went wrong.

0 comments on commit 10e7c23

Please sign in to comment.