casbin-couchdb-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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.

Package Sidebar

Install

npm i casbin-couchdb-adapter

Homepage

casbin.org

Weekly Downloads

0

Version

0.1.0

License

none

Unpacked Size

31.4 kB

Total Files

7

Last publish

Collaborators

  • hsluoyz