Giter Club home page Giter Club logo

couchdb-adapter's Introduction

CouchDB Adapter

NPM version NPM download ci Coverage Status Discord

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.

couchdb-adapter's People

Contributors

hsluoyz avatar selflocking avatar terry-xuan-gao avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

couchdb-adapter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.