Commit 96c29c89 authored by A. Koch's avatar A. Koch

updated mongodb settings, use mongodb adapter directly for acl

parent 85814510
......@@ -12,10 +12,8 @@
},
"acl": {
"mongodb": {
"name": "acl",
"prefix": "acl_",
"url": "mongodb://localhost:27017/motionbank-api",
"dbName": "motionbank-api"
"url": "mongodb://localhost:27017",
"dbName": "motionbank-api-acl"
}
},
"profiles": {
......
......@@ -12,17 +12,15 @@
},
"acl": {
"mongodb": {
"name": "acl",
"prefix": "acl_",
"url": "mongodb://localhost:27017/motionbank-api-dev",
"dbName": "motionbank-api-dev"
"url": "mongodb://localhost:27017",
"dbName": "motionbank-api-acl-dev"
}
},
"profiles": {
"mongodb": {
"prefix": "sys_",
"url": "mongodb://localhost:27017/motionbank-api-dev",
"dbName": "motionbank-api-dev"
"url": "mongodb://localhost:27017/motionbank-api-sys-dev",
"dbName": "motionbank-api-sys-dev"
}
},
"auth": {
......
......@@ -2,22 +2,30 @@ const
Acl = require('acl'),
config = require('config'),
Backend = Acl.mongodbBackend,
{ MongoDB } = require('mbjs-persistence'),
MongoClient = require('mongodb').MongoClient,
send = require('@polka/send-type')
const setupACL = async function (app) {
const cfg = config.get('acl.mongodb')
cfg.logger = console
const client = new MongoDB(cfg, 'uuid')
await client.connect()
const acl = new Acl(new Backend(client.db.s.db, cfg.prefix))
const db = await new Promise((resolve, reject) => {
MongoClient.connect(cfg.url, function (err, client) {
if (err) return reject(err)
cfg.logger.info(`ACL connected at ${cfg.url}/${cfg.dbName}`)
const db = client.db(cfg.dbName)
resolve(db)
})
})
const acl = new Acl(new Backend(db))
/**
* Manage permissions
*/
app.get('/acl/:role/:resource', (req, res, next) => {
acl.allowedPermissions(req.params.role, req.resource, (err, result) => {
acl.allowedPermissions(req.params.role, req.params.resource, (err, result) => {
if (err) next(err)
else if (result) send(res, 200, result)
else send(res, 404)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment