Permissions are applied on a user email, you must include an authentication library such as panda.
The client requires node 4.3 or newer.
Installation
npm install --save node-permissions-client
Usage
const permissions = require('node-permissions-client')({ app: 'application name, should match what is in permissions model', s3Bucket: 'permissions-cache-s3-bucket', s3BucketPrefix: 'STAGE', s3PermissionsFile: 'permissions.json', s3Region: 'eu-west-1', // Optional values: sendStatus: true, // If `true` the middleware responds with status `403`. If false it forwards the error. logger: console, // or any other object implementing .info .warn .error s3Client: null, // instance of AWS.S3 in case you want to override the default updateInterval: 60, // seconds, how often should the cache update onUpdate: function () {} // callback to be notified after the cache gets updated});app.post('/api/sensitive/action',
Advanced usage
Custom logger
If your application is using a custom logger like winston or bunyan you can use the following code, by default it logs to the console.
If your application runs a different account from permissions, you can use this code
const parmissionClient = require('node-permissions-client');const AWS = require('aws-sdk');const chain = new AWS.CredentialProviderChain();chain.providers = [ // use a profile for local development new AWS.SharedIniFileCredentials({ profile: 'permission' }), // and STS Assume Role for your instances new AWS.TemporaryCredentials({ RoleArn: 'arn:...' })];const permissions = client({ app: 'application', s3Bucket: 'bucket', s3BucketPrefix: 'STAGE',
Contributing
Local development
Clone the repo
npm test
Run tests on change with nodemon --exec "tap test"