Skip to content

Commit

Permalink
compute:createFirewall: add protocol options (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and callmehiphop committed Jun 6, 2016
1 parent 43ae6ea commit cd46837
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions lib/compute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ nodeutil.inherits(Compute, Service);
* @param {object} config.protocols - A map of protocol to port range. The keys
* of the object refer to a protocol (e.g. `tcp`, `udp`) and the value for
* the key are the ports/port-ranges that are allowed to make a connection.
* If a `true` value, that means all ports on that protocol will be opened.
* If `false`, all traffic on that protocol will be blocked.
* @param {string[]} config.ranges - The IP address blocks that this rule
* applies to, expressed in
* [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
Expand Down Expand Up @@ -210,11 +212,15 @@ Compute.prototype.createFirewall = function(name, config, callback) {
IPProtocol: protocol
};

var ports = arrify(body.protocols[protocol]);
if (ports.length > 0) {
allowedConfig.ports = ports;
var ports = body.protocols[protocol];

if (ports === false || ports.length === 0) {
continue;
}

// If the port is `true`, open up all ports on this protocol.
allowedConfig.ports = ports === true ? [] : arrify(ports);

body.allowed.push(allowedConfig);
}

Expand Down
5 changes: 3 additions & 2 deletions system-test/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ describe('Compute', function() {
var CONFIG = {
protocols: {
tcp: [3000],
udp: []
icmp: true, // This should open all ports on this protocol
udp: [] // This should not open ports on this protocol at all
},

ranges: ['0.0.0.0/0']
Expand All @@ -248,7 +249,7 @@ describe('Compute', function() {
ports: ['3000']
},
{
IPProtocol: 'udp'
IPProtocol: 'icmp'
}
],

Expand Down
6 changes: 4 additions & 2 deletions test/compute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ describe('Compute', function() {
protocols: {
https: [8080, 9000],
ssh: 22,
ftp: []
ftp: [],
ah: false,
icmp: true
}
};

Expand All @@ -220,7 +222,7 @@ describe('Compute', function() {
{ IPProtocol: 'http', ports: [8000] },
{ IPProtocol: 'https', ports: [8080, 9000] },
{ IPProtocol: 'ssh', ports: [22] },
{ IPProtocol: 'ftp' }
{ IPProtocol: 'icmp', ports: [] }
]);
assert.strictEqual(reqOpts.json.protocols, undefined);
done();
Expand Down

0 comments on commit cd46837

Please sign in to comment.