メインコンテンツにスキップ

Watchers

etcdのような分散メッセージングシステムの使用をサポートしており、複数のCasbinエンフォーサーインスタンス間で一貫性を維持します。 これにより、ユーザーは複数のCasbinエンフォーサーを同時に使用して、大量の権限チェックリクエストを処理することができます。

ポリシーストレージアダプターと同様に、メインライブラリにウォッチャーコードは含まれていません。 新しいメッセージングシステムのサポートは、ウォッチャーとして実装する必要があります。 Casbinウォッチャーの完全なリストは以下に提供されています。 新しいウォッチャーのための第三者からの貢献を歓迎します、私たちに知らせてください、そして私たちはそれをこのリストに追加します:

WatcherTypeAuthorDescription
PostgreSQL WatcherExDatabase@IguteChungWatcherEx for PostgreSQL
Redis WatcherExKV storeCasbinWatcherEx for Redis
Redis WatcherKV store@billcobblerWatcher for Redis
Etcd WatcherKV storeCasbinWatcher for etcd
TiKV WatcherKV storeCasbinWatcher for TiKV
Kafka WatcherMessaging system@wgarunapWatcher for Apache Kafka
NATS WatcherMessaging systemSolutoWatcher for NATS
ZooKeeper WatcherMessaging systemGrepsrWatcher for Apache ZooKeeper
NATS, RabbitMQ, GCP Pub/Sub, AWS SNS & SQS, Kafka, InMemoryMessaging System@rusenaskWatcher 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, InMemoryMessaging System@bartventerWatcherEx based on Go Cloud Dev Kit that works with leading cloud providers and self-hosted infrastructure
RocketMQ WatcherMessaging system@fmyxyzWatcher 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().