g4js-firewall

0.1.2 • Public • Published

g4js-firewall Build Status Code Climate Test Coverage

Simple pattern based firewall that supports roles and HTTP methods.

Install

$ npm install g4js-firewall

Usage

Require the module:

var Firewall = require('g4js-firewall').Firewall;

Add some rules:

var firewall = new Firewall();
 
// admin path restricted to admin role with all methods allowed
firewall.addRule('^/admin', 'admin', '*');
 
// admin path restricted to admin role with all methods allowed
firewall.addRule('^/orders', ['user','admin'], ['GET','PUT','POST']);
 
// signup path restricted to readonly role using POST method
firewall.addRule('^/signup', 'readonly', 'POST');
 
// shop path restricted to readonly role using GET method
firewall.addRule('^/shop', 'readonly', 'GET');

Run some checks:

// returns matching rule if match found
var matchingRule = firewall.check('/admin', ['admin'], 'GET');
 
// returns undefined if no matching rules found
var noBueno = firewall.check('/admin', 'hog_rider', 'GET');
 
// express middleware coming soon...
 

License

MIT

Contribute

Pull Requests always welcome, as well as any feedback or issues. Made with OSS <3 and brought to you by #teamgorgeous.

Dependencies (1)

Dev Dependencies (11)

Package Sidebar

Install

npm i g4js-firewall

Weekly Downloads

16

Version

0.1.2

License

MIT

Last publish

Collaborators

  • nesbert