0.1.0 • Published 1 year ago

casbin-couchdb-adapter v0.1.0

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

CouchDB Adapter

NPM version NPM download ci Coverage Status Gitter

CouchDB policy storage, implemented as an adapter for node-casbin.

Installation

NPM:

npm install casbin-couchdb-adapter --save

Yarn:

yarn add casbin-couchdb-adapter

Simple Example

import { newEnforcer } from 'casbin';
import { CouchdbAdapter } from 'casbin-couchdb-adapter';
import { join } from 'path';

async function myFunction() {
    // Initialize a CouchdbAdapter adapter and use it in a Node-Casbin enforcer:
    const adapter = await CouchdbAdapter.newAdapter("http://admin:password@localhost:5984");

    // The location of your Casbin model configuration file
    const model = join(__dirname, 'casbin_conf/model.conf');

    const enforcer = await newEnforcer(model, adapter);

    // Check the permission.
    enforcer.enforce('alice', 'data1', 'read');

    // Modify the policy.
    // await enforcer.addPolicy(...);
    // await enforcer.removePolicy(...);

    // Save the policy back to DB.
    await enforcer.savePolicy();
}

Configuration

You need to create a database named "casbin" and a document like this:

{
  "_id": "policies",
  "value": []
}

CouchdbAdapter.newAdapter() takes the following parameters as an object to establish the connection with couchdb-server

databaseUrl: string = "http://{admin}:{password}@{ip}:{port}"

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.