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 @@ ...@@ -12,10 +12,8 @@
}, },
"acl": { "acl": {
"mongodb": { "mongodb": {
"name": "acl", "url": "mongodb://localhost:27017",
"prefix": "acl_", "dbName": "motionbank-api-acl"
"url": "mongodb://localhost:27017/motionbank-api",
"dbName": "motionbank-api"
} }
}, },
"profiles": { "profiles": {
......
...@@ -12,17 +12,15 @@ ...@@ -12,17 +12,15 @@
}, },
"acl": { "acl": {
"mongodb": { "mongodb": {
"name": "acl", "url": "mongodb://localhost:27017",
"prefix": "acl_", "dbName": "motionbank-api-acl-dev"
"url": "mongodb://localhost:27017/motionbank-api-dev",
"dbName": "motionbank-api-dev"
} }
}, },
"profiles": { "profiles": {
"mongodb": { "mongodb": {
"prefix": "sys_", "prefix": "sys_",
"url": "mongodb://localhost:27017/motionbank-api-dev", "url": "mongodb://localhost:27017/motionbank-api-sys-dev",
"dbName": "motionbank-api-dev" "dbName": "motionbank-api-sys-dev"
} }
}, },
"auth": { "auth": {
......
...@@ -2,22 +2,30 @@ const ...@@ -2,22 +2,30 @@ const
Acl = require('acl'), Acl = require('acl'),
config = require('config'), config = require('config'),
Backend = Acl.mongodbBackend, Backend = Acl.mongodbBackend,
{ MongoDB } = require('mbjs-persistence'), MongoClient = require('mongodb').MongoClient,
send = require('@polka/send-type') send = require('@polka/send-type')
const setupACL = async function (app) { const setupACL = async function (app) {
const cfg = config.get('acl.mongodb') const cfg = config.get('acl.mongodb')
cfg.logger = console cfg.logger = console
const client = new MongoDB(cfg, 'uuid')
await client.connect() const db = await new Promise((resolve, reject) => {
const acl = new Acl(new Backend(client.db.s.db, cfg.prefix)) 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 * Manage permissions
*/ */
app.get('/acl/:role/:resource', (req, res, next) => { 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) if (err) next(err)
else if (result) send(res, 200, result) else if (result) send(res, 200, result)
else send(res, 404) 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