casbin KV store adapter for casbin
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
README.md Fix errors in readme Jun 28, 2017
adapter.go Add test, add error handling Jun 30, 2017
adapter_test.go Modify adapter BadPort test Jul 1, 2017

README.md

consul_adapter

casbin KV store adapter for casbin

Usage

package main

import (
	"github.com/casbin/casbin"
	"github.com/ankitm123/consul-adapter"
)

func main() {
	//This is how it should ideally work:
    // Initialize a consul adapter and use it in a Casbin enforcer:
    
	a := consuladapter.NewDBAdapter()
	e := casbin.NewEnforcer("examples/rbac_model.conf", a)
	
	// Load the policy from consul KV store.
	e.LoadPolicy()
	
	// Check the permission.
	e.Enforce("alice", "data1", "read")
	
	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)
	
	// Save the policy back to consul KV store.
	e.SavePolicy()

    //This is how it works now. We have a csv file which is read by the adpater using savepolicy
    e := casbin.NewEnforcer("./rbac/rbac_model.conf", "./rbac/rbac_policy.csv")
	//a := ConsulAdapter.NewDBAdapter()
	a.SavePolicy(e.GetModel())
	//a.LoadPolicy(e.GetModel())
	e = casbin.NewEnforcer("./rbac/rbac_model.conf", a)

	e.LoadPolicy()
}