Skip to content

Commit

Permalink
Code style updates, linted code according to new rules, fixed minor b…
Browse files Browse the repository at this point in the history
…ug on aggregated lists
  • Loading branch information
mziccard committed Jul 21, 2015
1 parent 53e10fd commit f6f35d6
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 363 deletions.
23 changes: 3 additions & 20 deletions lib/compute/disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
*/
var util = require('../common/util.js');

/**
* @const {string}
* @private
*/
var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';

/**
* Create a Disk object to interact with a Google Compute Engine disk.
*
Expand All @@ -40,7 +34,7 @@ var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';
*
* @throws {Error} if a disk name or a zone are not provided.
*
* @param {module:zone} zone - The Google Compute Engine zone this
* @param {module:zone} zone - The Google Compute Engine zone this
* disk belongs to.
* @param {number=} sizeGb - Size of the disk in GB.
* @param {object=} metadata - Disk metadata.
Expand Down Expand Up @@ -128,19 +122,8 @@ Disk.prototype.createSnapshot = function(name, description, callback) {
* @param {function} callback - The callback function.
*/
Disk.prototype.makeReq_ = function(method, path, query, body, callback) {
var reqOpts = {
method: method,
qs: query,
uri: COMPUTE_BASE_URL + this.zone.compute.projectId +
'/zones/' + this.zone.name +
'/disks/' + this.name + path
};

if (body) {
reqOpts.json = body;
}

this.zone.compute.makeAuthorizedRequest_(reqOpts, callback);
path = '/disks/' + this.name + path;
this.zone.makeReq_(method, path, query, body, callback);
};

module.exports = Disk;
114 changes: 34 additions & 80 deletions lib/compute/firewall.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@

'use strict';

var extend = require('extend');

/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util.js');

/**
* @const {string}
* @private
*/
var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';

/**
* Create a Firewall object to interact with a Google Compute Engine firewall.
*
Expand All @@ -40,19 +36,19 @@ var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';
*
* @throws {Error} if a firewall name isn't provided.
*
* @param {module:compute} compute - The Google Compute Engine instance this
* @param {module:compute} compute - The Google Compute Engine instance this
* firewall belongs to.
* @param {string} name - Name of the firewall.
* @param {object} options - Firewall options.
* @param {string=} options.description - Description of the firewall.
* @param {string=} options.network - Network to which the firewall applies.
* @param {string=} options.network - Network to which the firewall applies.
* Default value is 'global/networks/default'.
* @param {object[]=} options.allowed - List of allowed protocols and ports.
* @param {string[]=} options.sourceRanges - IP address blocks to which this
* rule applies (in CIDR format).
* @param {string[]=} options.sourceRanges - IP address blocks to which this
* rule applies (in CIDR format).
* @param {string[]=} options.sourceTags - List of instance tags to which
* @param {string[]=} options.sourceTags - List of instance tags to which
* this rule applies.
* @param {string[]=} options.targetTags - List of instance tags indicating
* instances that may process connections according to this rule.
Expand All @@ -69,37 +65,18 @@ var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';
function Firewall(compute, name, options) {
this.name = name;
this.compute = compute;
this.description = '';
this.network = 'global/networks/default';
this.allowed = [];
this.sourceRanges = [];
this.sourceTags = [];
this.targetTags = [];

if (!this.name) {
throw new Error('A name is needed to use Google Cloud Compute Firewall.');
}

if (options) {
if (util.is(options.description, 'string')) {
this.description = options.description;
}
if (util.is(options.network, 'string')) {
this.network = options.network;
}
if (util.is(options.allowed, 'array')) {
this.allowed = options.allowed;
}
if (util.is(options.sourceRanges, 'array')) {
this.sourceRanges = options.sourceRanges;
}
if (util.is(options.sourceTags, 'array')) {
this.sourceTags = options.sourceTags;
}
if (util.is(options.targetTags, 'array')) {
this.targetTags = options.targetTags;
}
}
options = options || {};
this.description = options.description || '';
this.network = options.network || 'global/networks/default';
this.allowed = options.allowed || [];
this.sourceRanges = options.sourceRanges || [];
this.sourceTags = options.sourceTags || [];
this.targetTags = options.targetTags || [];
}

/**
Expand All @@ -118,25 +95,25 @@ Firewall.prototype.delete = function(callback) {
/**
* Update the firewall rule.
*
* @throws {Error} if firewall options are not provided, if no allowed
* protocols are specified or none of source ranges and source tags are
* @throws {Error} if firewall options are not provided, if no allowed
* protocols are specified or none of source ranges and source tags are
* provided
*
* @param {module:compute} compute - The Google Compute Engine instance this
* @param {module:compute} compute - The Google Compute Engine instance this
* this firewall belongs to.
* @param {string} name - Name of the firewall.
* @param {object} options - Firewall options.
* @param {boolean} options.patch - If true update is performed according to
* the patch semantics (default is false).
* @param {string=} options.description - Description of the firewall.
* @param {string=} options.network - Network to which the firewall applies.
* @param {string=} options.network - Network to which the firewall applies.
* Default value is 'global/networks/default'.
* @param {object[]=} options.allowed - List of allowed protocols and ports.
* @param {string[]=} options.sourceRanges - IP address blocks to which this
* rule applies (in CIDR format).
* @param {string[]=} options.sourceRanges - IP address blocks to which this
* rule applies (in CIDR format).
* @param {string[]=} options.sourceTags - List of instance tags to which
* @param {string[]=} options.sourceTags - List of instance tags to which
* this rule applies.
* @param {string[]=} options.targetTags - List of instance tags indicating
* instances that may process connections according to this rule.
Expand All @@ -154,18 +131,18 @@ Firewall.prototype.delete = function(callback) {
* }, callback);
*/
Firewall.prototype.update = function(options, callback) {
if (!options) {
if (!util.is(options, 'object')) {
throw new Error('Firewall rule options must be provided.');
}

var method = 'PUT';
if (options.patch) {
method = 'PATCH';
} else {
if(!util.is(options.allowed, 'array')) {
if (!util.is(options.allowed, 'array')) {
throw new Error('Allowed protocols and ports must be provided.');
}
if (!util.is(options.sourceRanges, 'array') &&
if (!util.is(options.sourceRanges, 'array') &&
!util.is(options.sourceTags, 'array')) {
throw new Error('Source ranges or source tags must be provided.');
}
Expand All @@ -177,56 +154,43 @@ Firewall.prototype.update = function(options, callback) {
} else {
body.name = this.name;
}
var newFirewall = this.compute.firewall(body.name);
if (util.is(options.description, 'string')) {
body.description = options.description;
newFirewall.description = body.description;
} else {
newFirewall.description = this.description;
}
body.network = this.network;
if (util.is(options.network, 'string')) {
body.network = options.network;
newFirewall.network = body.network;
} else {
body.network = this.network;
newFirewall.network = this.network;
}
if (util.is(options.allowed, 'array')) {
body.allowed = options.allowed;
newFirewall.allowed = body.allowed;
} else {
newFirewall.allowed = this.allowed;
}
if (util.is(options.sourceRanges, 'array')) {
body.sourceRanges = options.sourceRanges;
newFirewall.sourceRanges = body.sourceRanges;
} else {
newFirewall.sourceRanges = this.sourceRanges;
}
if (util.is(options.sourceTags, 'array')) {
body.sourceTags = options.sourceTags;
newFirewall.sourceTags = body.sourceTags;
} else {
newFirewall.sourceTags = this.sourceTags;
}
if (util.is(options.targetTags, 'array')) {
body.targetTags = options.targetTags;
newFirewall.targetTags = body.targetTags;
} else {
newFirewall.targetTags = this.targetTags;
}

var newOptions = body;
if (options.patch) {
newOptions = extend(this, body);
}
var newFirewall = new Firewall(this.compute, body.name, newOptions);

this.makeReq_(
method,
'',
null,
method,
'',
null,
body, function(err, resp) {
if (err) {
callback(err);
return;
return;
}
callback(null, newFirewall, resp);
}.bind(this));
});
};

/**
Expand All @@ -242,18 +206,8 @@ Firewall.prototype.update = function(options, callback) {
* @param {function} callback - The callback function.
*/
Firewall.prototype.makeReq_ = function(method, path, query, body, callback) {
var reqOpts = {
method: method,
qs: query,
uri: COMPUTE_BASE_URL + this.compute.projectId +
'/global/firewalls/' + this.name
};

if (body) {
reqOpts.json = body;
}

this.compute.makeAuthorizedRequest_(reqOpts, callback);
path = '/global/firewalls/' + this.name;
this.compute.makeReq_(method, path, query, body, callback);
};

module.exports = Firewall;
Loading

0 comments on commit f6f35d6

Please sign in to comment.