Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement the logic for checking a collection of cloud providers
- Loading branch information
Benjamin Coe
committed
Jun 3, 2016
1 parent
c521eb0
commit a4b7bf9
Showing
6 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const parallel = require('async').parallel | ||
const ipRangeCheck = require('ip-range-check') | ||
const azure = require('./azure') | ||
const aws = require('./aws') | ||
|
||
module.exports = function (ip, done) { | ||
var name = 'unknown' | ||
parallel([ | ||
function (cb) { | ||
check(ip, azure(), function (err, _name) { | ||
if (err) return cb(err) | ||
else { | ||
if (_name) name = _name | ||
return cb() | ||
} | ||
}) | ||
}, | ||
function (cb) { | ||
check(ip, aws(), function (err, _name) { | ||
if (err) return cb(err) | ||
else { | ||
if (_name) name = _name | ||
return cb() | ||
} | ||
}) | ||
} | ||
], function (err) { | ||
if (err) return done(err) | ||
else return done(null, name) | ||
}) | ||
} | ||
|
||
function check (ip, cloud, cb) { | ||
cloud.list(function (err, ranges) { | ||
if (err) return cb(err) | ||
else if (ipRangeCheck(ip, ranges)) { | ||
return cb(null, cloud.name) | ||
} else { | ||
return cb() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* global describe, it */ | ||
|
||
require('chai').should() | ||
|
||
const which = require('../lib/which') | ||
|
||
describe('which', function () { | ||
it('returns appropriate response for azure ip', function (done) { | ||
which('94.245.97.0', function (err, name) { | ||
if (err) return done(err) | ||
name.should.equal('azure') | ||
return done() | ||
}) | ||
}) | ||
|
||
it('returns appropriate response for aws ip', function (done) { | ||
which('54.173.231.160', function (err, name) { | ||
if (err) return done(err) | ||
name.should.equal('aws') | ||
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) | ||
name.should.equal('unknown') | ||
return done() | ||
}) | ||
}) | ||
}) |