Skip to content

Commit

Permalink
chore(ci): move to gh actions (#53)
Browse files Browse the repository at this point in the history
move to standard
  • Loading branch information
wraithgar authored Apr 23, 2021
1 parent 8f347fe commit eddf5fc
Show file tree
Hide file tree
Showing 7 changed files with 5,132 additions and 406 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

105 changes: 48 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,68 @@
'use strict';

const Assert = require('assert');
const Dns = require('dns');
const Http = require('http');
const Https = require('https');
const IPRangeCheck = require('ip-range-check');
'use strict'

const Assert = require('assert')
const Dns = require('dns')
const Http = require('http')
const Https = require('https')
const IPRangeCheck = require('ip-range-check')

const lookup = function (settings) {
Assert(settings.type === 'whitelist' || settings.type === 'blacklist', 'type must be whitelist or blacklist')

Assert(settings.type === 'whitelist' || settings.type === 'blacklist', 'type must be whitelist or blacklist');

const filter = function (hostname, options, callback) {

if (arguments.length === 2) {
callback = options;
options = {};
}

Dns.lookup(hostname, options, (err, address, family) => {
const filter = function (hostname, options, callback) {
if (arguments.length === 2) {
callback = options
options = {}
}

if (err) {
callback(err);
return;
}
Dns.lookup(hostname, options, (err, address, family) => {
if (err) {
callback(err)
return
}

const ip_test = IPRangeCheck(address, settings.iplist);
const ipTest = IPRangeCheck(address, settings.iplist)

if (ip_test && settings.type === 'whitelist') { //IP on whitelist, pass
callback(err, address, family);
return;
}
if (ipTest && settings.type === 'whitelist') { // IP on whitelist, pass
callback(err, address, family)
return
}

if (!ip_test && settings.type === 'blacklist') { //IP not on blacklist, pass
callback(err, address, family);
return;
}
//Fail
if (!ipTest && settings.type === 'blacklist') { // IP not on blacklist, pass
callback(err, address, family)
return
}
// Fail

callback(new Error(`Connection to IP ${address} not allowed`));
return;
});
};
callback(new Error(`Connection to IP ${address} not allowed`))
})
}

return filter;
};
return filter
}

exports.http = function (settings) {
const httpAgent = new Http.Agent(settings.agent)

const httpAgent = new Http.Agent(settings.agent);
httpAgent._oldCreateConnection_ = httpAgent.createConnection
httpAgent.createConnection = function (options, ...args) {
options.lookup = lookup(settings)

httpAgent._oldCreateConnection_ = httpAgent.createConnection;
httpAgent.createConnection = function (options, ...args) {
return this._oldCreateConnection_(options, ...args)
}

options.lookup = lookup(settings);

return this._oldCreateConnection_(options, ...args);
};

return httpAgent;
};
return httpAgent
}

exports.https = function (settings) {
const httpsAgent = new Https.Agent(settings.agent)

const httpsAgent = new Https.Agent(settings.agent);

httpsAgent._oldCreateConnection_ = httpsAgent.createConnection;
httpsAgent.createConnection = function (options, ...args) {

options.lookup = lookup(settings);
httpsAgent._oldCreateConnection_ = httpsAgent.createConnection
httpsAgent.createConnection = function (options, ...args) {
options.lookup = lookup(settings)

return this._oldCreateConnection_(options, ...args);
};
return this._oldCreateConnection_(options, ...args)
}

return httpsAgent;
};
return httpsAgent
}
Loading

0 comments on commit eddf5fc

Please sign in to comment.