Skip to content

Commit 1dc3376

Browse files
compute:createFirewall: add protocol options
1 parent 43ae6ea commit 1dc3376

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

lib/compute/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ nodeutil.inherits(Compute, Service);
155155
* @param {object} config.protocols - A map of protocol to port range. The keys
156156
* of the object refer to a protocol (e.g. `tcp`, `udp`) and the value for
157157
* the key are the ports/port-ranges that are allowed to make a connection.
158+
* If a `true` value, that means all ports on that protocol will be opened.
159+
* If `false`, all traffic on that protocol will be blocked.
158160
* @param {string[]} config.ranges - The IP address blocks that this rule
159161
* applies to, expressed in
160162
* [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
@@ -210,11 +212,15 @@ Compute.prototype.createFirewall = function(name, config, callback) {
210212
IPProtocol: protocol
211213
};
212214

213-
var ports = arrify(body.protocols[protocol]);
214-
if (ports.length > 0) {
215-
allowedConfig.ports = ports;
215+
var ports = body.protocols[protocol];
216+
217+
if (ports === false || ports.length === 0) {
218+
continue;
216219
}
217220

221+
// If the port is `true`, open up all ports on this protocol.
222+
allowedConfig.ports = ports === true ? [] : arrify(ports);
223+
218224
body.allowed.push(allowedConfig);
219225
}
220226

system-test/compute.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ describe('Compute', function() {
235235
var CONFIG = {
236236
protocols: {
237237
tcp: [3000],
238-
udp: []
238+
icmp: true, // This should open all ports on this protocol
239+
udp: [] // This should not open ports on this protocol at all
239240
},
240241

241242
ranges: ['0.0.0.0/0']
@@ -248,7 +249,7 @@ describe('Compute', function() {
248249
ports: ['3000']
249250
},
250251
{
251-
IPProtocol: 'udp'
252+
IPProtocol: 'icmp'
252253
}
253254
],
254255

test/compute/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ describe('Compute', function() {
211211
protocols: {
212212
https: [8080, 9000],
213213
ssh: 22,
214-
ftp: []
214+
ftp: [],
215+
ah: false,
216+
icmp: true
215217
}
216218
};
217219

@@ -220,7 +222,7 @@ describe('Compute', function() {
220222
{ IPProtocol: 'http', ports: [8000] },
221223
{ IPProtocol: 'https', ports: [8080, 9000] },
222224
{ IPProtocol: 'ssh', ports: [22] },
223-
{ IPProtocol: 'ftp' }
225+
{ IPProtocol: 'icmp', ports: [] }
224226
]);
225227
assert.strictEqual(reqOpts.json.protocols, undefined);
226228
done();

0 commit comments

Comments
 (0)