https://github.com/casbin/tikv-watcher
TiKV watcher for Casbin
https://github.com/casbin/tikv-watcher
abac acl auth authorization authz casbin go golang rbac tidb tikv watcher
Last synced: 3 months ago
JSON representation
TiKV watcher for Casbin
- Host: GitHub
- URL: https://github.com/casbin/tikv-watcher
- Owner: casbin
- License: apache-2.0
- Created: 2021-07-04T14:10:43.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-18T08:25:06.000Z (almost 4 years ago)
- Last Synced: 2024-10-29T12:34:34.767Z (7 months ago)
- Topics: abac, acl, auth, authorization, authz, casbin, go, golang, rbac, tidb, tikv, watcher
- Language: Go
- Homepage: https://github.com/casbin/casbin
- Size: 43 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TiKV Watcher
[](https://github.com/casbin/tikv-watcher/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/casbin/tikv-watcher)
[](https://pkg.go.dev/github.com/casbin/tikv-watcher)TiKV Watcher is the [TiKV](https://github.com/tikv/tikv) watcher for Casbin. With this library, Casbin can synchronize the policy with the TiKV database in multiple enforcer instances.
*Note: Considering that TiKV doesn't have watch mechanism like etcd or channel like Redis, this ugly implementation uses polling to achieve monitoring a certain key, which may cause some performance trouble*
### Installation:
```shell
go get github.com/casbin/tikv-watcher
```### Single Example:
start the TiKV service before run this example:
```golang
package mainimport (
"fmt"
"time"watcher "github.com/casbin/tikv-watcher"
casbin "github.com/casbin/casbin/v2"
)func main() {
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
w, err := watcher.NewWatcher(
"testkey",
100*time.Millisecond,
"127.0.0.1:2379",
)
if err != nil {
panic(err)
return
}
e.SetWatcher(w)
w.SetUpdateCallback(
func(s string) {
fmt.Println("===================get" + s)
},
)
e.SavePolicy()
time.Sleep(10 * time.Second)}
```
### License:
This project is under Apache 2.0 License. See the LICENSE file for the full license text.