주요 콘텐츠로 건너뛰기

Watchers

etcd와 같은 분산 메시징 시스템의 사용을 지원하여 여러 Casbin enforcer 인스턴스 간의 일관성을 유지합니다. 이를 통해 사용자들이 동시에 여러 Casbin enforcer를 사용하여 대량의 권한 확인 요청을 처리할 수 있습니다.

정책 저장 어댑터와 마찬가지로, 주 라이브러리에 watcher 코드를 포함시키지 않습니다. 새로운 메시징 시스템에 대한 지원은 watcher로 구현되어야 합니다. Casbin watcher의 전체 목록은 아래에 제공됩니다. 새로운 watcher에 대한 제3자 기여를 환영하며, 알려주시면 이 목록에 추가하겠습니다:

Watcher Type Author Description
PostgreSQL WatcherEx Database @IguteChung WatcherEx for PostgreSQL
Redis WatcherEx KV store Casbin WatcherEx for Redis
Redis Watcher KV store @billcobbler Watcher for Redis
Etcd Watcher KV store Casbin Watcher for etcd
TiKV Watcher KV store Casbin Watcher for TiKV
Kafka Watcher Messaging system @wgarunap Watcher for Apache Kafka
NATS Watcher Messaging system Soluto Watcher for NATS
ZooKeeper Watcher Messaging system Grepsr Watcher for Apache ZooKeeper
NATS, RabbitMQ, GCP Pub/Sub, AWS SNS & SQS, Kafka, InMemory Messaging System @rusenask Watcher based on Go Cloud Dev Kit that works with leading cloud providers and self-hosted infrastructure
NATS, RabbitMQ, GCP Pub/Sub, AWS SNS & SQS, Kafka, InMemory Messaging System @bartventer WatcherEx based on Go Cloud Dev Kit that works with leading cloud providers and self-hosted infrastructure
RocketMQ Watcher Messaging system @fmyxyz Watcher for Apache RocketMQ

WatcherEx

In order to support incremental synchronization between multiple instances, we provide the WatcherEx interface. We hope it can notify other instances when the policy changes, but there is currently no implementation of WatcherEx. We recommend that you use dispatcher to achieve this.

Compared with Watcher interface, WatcherEx can distinguish what type of update action is received, e.g., AddPolicy and RemovePolicy.

WatcherEx Apis:

APIDescription
SetUpdateCallback(func(string)) errorSetUpdateCallback sets the callback function that the watcher will call, when the policy in DB has been changed by other instances. A classic callback is Enforcer.LoadPolicy().
Update() errorUpdate calls the update callback of other instances to synchronize their policy. It is usually called after changing the policy in DB, like Enforcer.SavePolicy(), Enforcer.AddPolicy(), Enforcer.RemovePolicy(), etc.
Close()Close stops and releases the watcher, the callback function will not be called any more.
UpdateForAddPolicy(sec, ptype string, params ...string) errorUpdateForAddPolicy calls the update callback of other instances to synchronize their policy. It is called after a policy is added via Enforcer.AddPolicy(), Enforcer.AddNamedPolicy(), Enforcer.AddGroupingPolicy() and Enforcer.AddNamedGroupingPolicy().
UpdateForRemovePolicy(sec, ptype string, params ...string) errorUPdateForRemovePolicy calls the update callback of other instances to synchronize their policy. It is called after a policy is removed by Enforcer.RemovePolicy(), Enforcer.RemoveNamedPolicy(), Enforcer.RemoveGroupingPolicy() and Enforcer.RemoveNamedGroupingPolicy().
UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) errorUpdateForRemoveFilteredPolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemoveFilteredPolicy(), Enforcer.RemoveFilteredNamedPolicy(), Enforcer.RemoveFilteredGroupingPolicy() and Enforcer.RemoveFilteredNamedGroupingPolicy().
UpdateForSavePolicy(model model.Model) errorUpdateForSavePolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.SavePolicy()
UpdateForAddPolicies(sec string, ptype string, rules ...[]string) errorUpdateForAddPolicies calls the update callback of other instances to synchronize their policy. It is called after Enforcer.AddPolicies(), Enforcer.AddNamedPolicies(), Enforcer.AddGroupingPolicies() and Enforcer.AddNamedGroupingPolicies().
UpdateForRemovePolicies(sec string, ptype string, rules ...[]string) errorUpdateForRemovePolicies calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemovePolicies(), Enforcer.RemoveNamedPolicies(), Enforcer.RemoveGroupingPolicies() and Enforcer.RemoveNamedGroupingPolicies().