https://github.com/sebastianliu/etcd-adapter
ETCD adapter for Casbin https://github.com/casbin/casbin
https://github.com/sebastianliu/etcd-adapter
adapter authorization casbin etcd rbac
Last synced: 5 months ago
JSON representation
ETCD adapter for Casbin https://github.com/casbin/casbin
- Host: GitHub
- URL: https://github.com/sebastianliu/etcd-adapter
- Owner: sebastianliu
- License: apache-2.0
- Created: 2018-11-12T02:35:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-31T13:18:36.000Z (over 3 years ago)
- Last Synced: 2025-08-13T22:09:04.026Z (11 months ago)
- Topics: adapter, authorization, casbin, etcd, rbac
- Language: Go
- Size: 39.1 KB
- Stars: 7
- Watchers: 3
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
etcd-adapter
====
[](https://travis-ci.org/sebastianliu/etcd-adapter)
[](https://coveralls.io/github/sebastianliu/etcd-adapter)
[](https://godoc.org/github.com/sebastianliu/etcd-adapter)
ETCD adapter is the policy storage adapter for [Casbin](https://github.com/casbin/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
```bash
go get github.com/sebastianliu/etcd-adapter
```
## Sample Example
```go
package main
import (
"github.com/sebastianliu/etcd-adapter"
"github.com/casbin/casbin"
)
func main() {
// Initialize a casbin etcd adapter and use it in a Casbin enforcer:
// The adapter will use the ETCD and a named path with the key you give.
// If not provided, the adapter will try to use the default value casbin_policy.
// If you have namespace to distinguish keys in your etcd, you can use your_namespace/casbin_root_path
a := etcdadapter.NewAdapter([]string{"http://127.0.0.1:2379"}, "casbin_policy_test") // Your etcd endpoints and the path key.
e := casbin.NewEnforcer("rbac_model.conf", a)
// Load the policy from ETCD.
e.LoadPolicy()
// Check the permission.
e.Enforce("alice", "data1", "read")
// Modify the policy.
// e.AddPolicy(...)
// e.RemovePolicy(...)
// Save the policy back to DB.
e.SavePolicy()
}
```