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

Watchers

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

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

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() の後に呼び出されます。