项目作者: sebastianliu

项目描述 :
ETCD adapter for Casbin https://github.com/casbin/casbin
高级语言: Go
项目地址: git://github.com/sebastianliu/etcd-adapter.git
创建时间: 2018-11-12T02:35:58Z
项目社区:https://github.com/sebastianliu/etcd-adapter

开源协议:Apache License 2.0

下载


etcd-adapter

Build Status
Coverage Status
Godoc

ETCD adapter is the policy storage adapter for Casbin. With this library, Casbin can load policy from ETCD and save policy to it. ETCD adapter support the Auto-Save feature for Casbin policy. This means it can support adding a single policy rule to the storage, or removing a single policy rule from the storage.

Installation

  1. go get github.com/sebastianliu/etcd-adapter

Sample Example

  1. package main
  2. import (
  3. "github.com/sebastianliu/etcd-adapter"
  4. "github.com/casbin/casbin"
  5. )
  6. func main() {
  7. // Initialize a casbin etcd adapter and use it in a Casbin enforcer:
  8. // The adapter will use the ETCD and a named path with the key you give.
  9. // If not provided, the adapter will try to use the default value casbin_policy.
  10. // If you have namespace to distinguish keys in your etcd, you can use your_namespace/casbin_root_path
  11. a := etcdadapter.NewAdapter([]string{"http://127.0.0.1:2379"}, "casbin_policy_test") // Your etcd endpoints and the path key.
  12. e := casbin.NewEnforcer("rbac_model.conf", a)
  13. // Load the policy from ETCD.
  14. e.LoadPolicy()
  15. // Check the permission.
  16. e.Enforce("alice", "data1", "read")
  17. // Modify the policy.
  18. // e.AddPolicy(...)
  19. // e.RemovePolicy(...)
  20. // Save the policy back to DB.
  21. e.SavePolicy()
  22. }