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

Watchers

We support the use of distributed messaging systems like etcd to maintain consistency between multiple Casbin enforcer instances. This allows our users to concurrently use multiple Casbin enforcers to handle a large number of permission checking requests.

Similar to policy storage adapters, we do not include watcher code in the main library. 新しいメッセージングシステムのサポートは、ウォッチャーとして実装する必要があります。 A complete list of Casbin watchers is provided below. We welcome any third-party contributions for a new watcher, please inform us and we will add it to this list:)

Watcherタイプ作成者説明
PostgreSQL WatcherExDatabase@IguteChungWatcherEx for PostgreSQL
Redis WatcherExKV ストアCasbinWatcherEx for Redis
Redis WatcherKV ストア@billcobblerRedis のウォッチャー
Etcd WatcherKV ストアCasbinetcd の監視者
TiKVウォッチャーKV ストアCasbinTiKV の監視人
Kafka WatcherSMSシステム@wgarunapApache Kafka の腕時計
NATS WatcherSMSシステムSolutoNATS の監視人
ZooKeeperウォッチャーSMSシステムGrepsrApache ZooKeeper の腕時計
NATS, RabbitMQ, GCP Pub/Sub, AWS SNS & SQS, Kafka, InMemorySMSシステム@rusenask主要なクラウドプロバイダーと自己ホストインフラストラクチャで動作する Go Cloud Dev Kit に基づくウォッチャー
RocketMQウォッチャーSMSシステム@fmyxyzApache RocketMQ の腕時計

WatcherEx

複数のインスタンス間の増分同期をサポートするために、 WatcherEx インターフェイスを提供します。 ポリシーが変更されたときに他のインスタンスに通知できることを願っていますが、 WatcherEx の実装は現在ありません。 これを達成するためにディスパッチャを使用することをお勧めします。

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

WatcherEx Apis:

API説明
SetUpdateCallback(func(string)) errorSetUpdateCallback sets the callback function that the watcher will call, when the policy in DB has been changed by other instances. 古典的なコールバックは Enforcer.LoadPolicy() です。
Update() errorUpdate calls the update callback of other instances to synchronize their policy. これは通常、DB 内のポリシーを変更した後に呼び出されます。例えば Enforcer.SavePolicy() や Enforcer.AddPolicy() や Enforcer.RemovePolicy() など。
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. これは、ポリシーがEnforcer.AddPolicy(), Enforcer.AddNamedPolicy(), Enforcer.AddGroupingPolicy(), Enforcer.AddNamedGroupingPolicy(), Enforcer.AddNamedGroupingPolicy() および Enforcer.AddNamedGroupingPolicy().
UpdateForRemovePolicy(sec, ptype string, params ...string) errorUPdateForRemovePolicy calls the update callback of other instances to synchronize their policy. ポリシーがEnforcer.RemovePolicy(), Enforcer.RemoveNamedPolicy(), Enforcer.RemoveGroupingPolicy() および Enforcer.RemoveNamedGroupingPolicy() によって削除された後に呼び出されます。
UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) errorUpdateForRemoveFilteredPolicy calls the update callback of other instances to synchronize their policy. これは、Enforcer.RemoveFilteredPolicy(), Enforcer.RemoveFilteredNamedPolicy(), Enforcer.RemoveFilteredGroupingPolicy() および Enforcer.RemoveFilteredNamedGroupingPolicy() の後に呼び出されます。
UpdateForSavePolicy(model model.Model) errorUpdateForSavePolicy calls the update callback of other instances to synchronize their policy. Enforcer.SavePolicy() の後に呼び出されます。
UpdateForAddPolicies(sec string, ptype string, rules ...[]string) errorUpdateForAddPolicies calls the update callback of other instances to synchronize their policy. これは、Enforcer.AddPolicies(), Enforcer.AddNamedPolicies(), Enforcer.AddGroupingPolicies() および Enforcer.AddNamedGroupingPolicies() の後に呼び出されます。
UpdateForRemovePolicies(sec string, ptype string, rules ...[]string) errorUpdateForRemovePolicies calls the update callback of other instances to synchronize their policy. これは、Enforcer.RemovePolicies(), Enforcer.RemoveNamedPolicies(), Enforcer.RemoveGroupingPolicies() および Enforcer.RemoveNamedGroupingPolicies() の後に呼び出されます。