Skip to content

Commit

Permalink
feat: add support for Google Compute Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Jun 3, 2016
1 parent 91efc03 commit 925ca10
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Expand Up @@ -2,6 +2,7 @@ const parallel = require('async').parallel
const ipRangeCheck = require('ip-range-check')
const azure = require('./lib/azure')
const aws = require('./lib/aws')
const gce = require('./lib/gce')

module.exports = function (ip, done) {
var name = 'unknown'
Expand All @@ -23,6 +24,15 @@ module.exports = function (ip, done) {
return cb()
}
})
},
function (cb) {
check(ip, gce(), function (err, _name) {
if (err) return cb(err)
else {
if (_name) name = _name
return cb()
}
})
}
], function (err) {
if (err) return done(err)
Expand Down
18 changes: 18 additions & 0 deletions lib/gce.js
@@ -0,0 +1,18 @@
const assign = require('lodash.assign')
const GCEIP = require('gce-ips')

function GCE (opts) {
assign(this, {
name: 'gce'
}, opts)
}

GCE.prototype.list = function (cb) {
GCEIP().lookup(function (err, ips) {
return cb(err, ips)
})
}

module.exports = function (opts) {
return new GCE(opts)
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
},
"dependencies": {
"async": "^1.5.2",
"gce-ips": "^1.0.1",
"ip-range-check": "0.0.1",
"lodash.assign": "^4.0.9",
"request": "^2.72.0",
Expand Down
16 changes: 16 additions & 0 deletions test/gce.js
@@ -0,0 +1,16 @@
/* global describe, it */

require('chai').should()

const GCE = require('../lib/gce')

describe('GCE', function () {
it('returns a list of IP ranges for GCE', function (done) {
const gce = GCE()
gce.list(function (err, ranges) {
if (err) return done(err)
ranges.should.include('8.34.208.0/20')
return done()
})
})
})
8 changes: 8 additions & 0 deletions test/which.js
Expand Up @@ -21,6 +21,14 @@ describe('which', function () {
})
})

it('returns appropriate response for gce ip', function (done) {
which('104.196.27.39', function (err, name) {
if (err) return done(err)
name.should.equal('gce')
return done()
})
})

it("returns 'unknown' if ip is not recognized", function (done) {
which('9.9.9.9', function (err, name) {
if (err) return done(err)
Expand Down

0 comments on commit 925ca10

Please sign in to comment.