Documentation
¶
Index ¶
- Constants
- Variables
- func IdentityChangedSubject(service string) string
- type ApplyResult
- type BadgerStore
- func (s *BadgerStore) AckHook(ctx context.Context, id string) error
- func (s *BadgerStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
- func (s *BadgerStore) Close() error
- func (s *BadgerStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)
- func (s *BadgerStore) Current(ctx context.Context, key IdentityKey) (State, error)
- func (s *BadgerStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error
- func (s *BadgerStore) MarkPendingHookReady(ctx context.Context, id string) error
- func (s *BadgerStore) PendingHooks(ctx context.Context, limit int) ([]PendingHook, error)
- func (s *BadgerStore) SavePendingHook(ctx context.Context, hook PendingHook) error
- func (s *BadgerStore) SaveSnapshot(ctx context.Context, state State) error
- type EventBridge
- type IdentityKey
- type Manager
- func (m *Manager) AckHook(ctx context.Context, id string) error
- func (m *Manager) ApplyEvent(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
- func (m *Manager) Authorize(ctx context.Context, identity types.AuthIdentity) error
- func (m *Manager) BeginClose()
- func (m *Manager) Close() error
- func (m *Manager) ConfirmActive(ctx context.Context, identity types.AuthIdentity, expectedGeneration uint64) (State, error)
- func (m *Manager) Current(ctx context.Context, identity types.AuthIdentity) (State, error)
- func (m *Manager) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error
- func (m *Manager) PendingHooks(ctx context.Context, limit int) ([]PendingHook, error)
- func (m *Manager) ProcessEvent(ctx context.Context, value types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
- func (m *Manager) SavePendingHook(ctx context.Context, hook PendingHook) error
- type Option
- type PendingHook
- type RedisEvalClient
- type RedisStore
- func (*RedisStore) AckHook(context.Context, string) error
- func (s *RedisStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
- func (*RedisStore) Close() error
- func (s *RedisStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)
- func (s *RedisStore) Current(ctx context.Context, key IdentityKey) (State, error)
- func (s *RedisStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error
- func (*RedisStore) MarkPendingHookReady(context.Context, string) error
- func (*RedisStore) PendingHooks(context.Context, int) ([]PendingHook, error)
- func (*RedisStore) SavePendingHook(context.Context, PendingHook) error
- func (s *RedisStore) SaveSnapshot(context.Context, State) error
- type State
- type Store
Constants ¶
const (
IdentityChangedEventType = types.CasdoorIdentityChangedEventType
)
Variables ¶
Functions ¶
func IdentityChangedSubject ¶
IdentityChangedSubject 返回服务专属的 Casdoor 身份控制主题。
Types ¶
type ApplyResult ¶
ApplyResult 区分首次应用、重复/乱序事件及控制通知是否已发布。
type BadgerStore ¶
type BadgerStore struct {
// contains filtered or unexported fields
}
BadgerStore 是单节点模式的权威存储,也是共享模式的已确认快照与 Hook 重试存储。
func OpenBadgerStore ¶
func OpenBadgerStore(path string) (*BadgerStore, error)
func (*BadgerStore) Apply ¶
func (s *BadgerStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
func (*BadgerStore) Close ¶
func (s *BadgerStore) Close() error
func (*BadgerStore) ConfirmActive ¶
func (s *BadgerStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)
func (*BadgerStore) Current ¶
func (s *BadgerStore) Current(ctx context.Context, key IdentityKey) (State, error)
func (*BadgerStore) MarkControlPublished ¶
func (s *BadgerStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error
func (*BadgerStore) MarkPendingHookReady ¶
func (s *BadgerStore) MarkPendingHookReady(ctx context.Context, id string) error
func (*BadgerStore) PendingHooks ¶
func (s *BadgerStore) PendingHooks(ctx context.Context, limit int) ([]PendingHook, error)
func (*BadgerStore) SavePendingHook ¶
func (s *BadgerStore) SavePendingHook(ctx context.Context, hook PendingHook) error
func (*BadgerStore) SaveSnapshot ¶
func (s *BadgerStore) SaveSnapshot(ctx context.Context, state State) error
type EventBridge ¶
type IdentityKey ¶
type IdentityKey struct {
Service string `json:"service"`
AuthType types.AuthType `json:"auth_type"`
Provider string `json:"provider"`
Subject string `json:"subject"`
}
IdentityKey 唯一标识某服务某认证域中的外部身份。
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 将权威撤销状态与本地已确认快照组合为请求授权边界。
func NewManager ¶
func (*Manager) ApplyEvent ¶
func (m *Manager) ApplyEvent(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
func (*Manager) BeginClose ¶
func (m *Manager) BeginClose()
BeginClose 立即拒绝新认证并停止事件订阅,但保留存储到 ServiceContext 完成其他组件清理。
func (*Manager) ConfirmActive ¶
func (*Manager) MarkControlPublished ¶
func (*Manager) PendingHooks ¶
func (*Manager) ProcessEvent ¶
func (m *Manager) ProcessEvent(ctx context.Context, value types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
ProcessEvent 原子应用权威状态,并等待控制通知被事件桥接受后再返回。 内置 shared 桥使用瞬时广播;接受不等于各副本已处理,漏通知由权威检查补偿。
func (*Manager) SavePendingHook ¶
func (m *Manager) SavePendingHook(ctx context.Context, hook PendingHook) error
type Option ¶
type Option func(*managerOptions)
func WithCasdoorEventHook ¶
func WithCasdoorEventHook(hook types.ICasdoorEventHookProvider) Option
WithCasdoorEventHook 为 Manager 配置持久化重试的业务事件 Hook。
func WithEventBridge ¶
func WithEventBridge(bridge EventBridge) Option
WithEventBridge 为撤销 Manager 绑定 ServiceContext 专属的本地/外部事件桥。
type PendingHook ¶
type PendingHook struct {
ID string `json:"id"`
Event types.CasdoorEvent `json:"event"`
Ready bool `json:"ready"`
Attempts int `json:"attempts"`
NextAttempt time.Time `json:"next_attempt"`
}
PendingHook 是已完成框架撤销、待重试业务事件 Hook 的标准记录。
type RedisEvalClient ¶
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore 使用 go-zero Redis 客户端和 Lua 作为共享模式的权威存储。
func NewConfiguredRedisStore ¶
func NewConfiguredRedisStore(cfg config.AuthRevocationRedisConfig) (*RedisStore, error)
func NewRedisStore ¶
func NewRedisStore(client RedisEvalClient, prefix string) *RedisStore
func (*RedisStore) Apply ¶
func (s *RedisStore) Apply(ctx context.Context, event types.CasdoorEvent, retention time.Duration) (ApplyResult, error)
func (*RedisStore) Close ¶
func (*RedisStore) Close() error
func (*RedisStore) ConfirmActive ¶
func (s *RedisStore) ConfirmActive(ctx context.Context, key IdentityKey, expectedGeneration uint64) (State, error)
func (*RedisStore) Current ¶
func (s *RedisStore) Current(ctx context.Context, key IdentityKey) (State, error)
func (*RedisStore) MarkControlPublished ¶
func (s *RedisStore) MarkControlPublished(ctx context.Context, event types.CasdoorEvent) error
func (*RedisStore) MarkPendingHookReady ¶
func (*RedisStore) MarkPendingHookReady(context.Context, string) error
func (*RedisStore) PendingHooks ¶
func (*RedisStore) PendingHooks(context.Context, int) ([]PendingHook, error)
func (*RedisStore) SavePendingHook ¶
func (*RedisStore) SavePendingHook(context.Context, PendingHook) error
func (*RedisStore) SaveSnapshot ¶
func (s *RedisStore) SaveSnapshot(context.Context, State) error
type State ¶
type State struct {
Key IdentityKey `json:"key"`
Generation uint64 `json:"generation"`
Blocked bool `json:"blocked"`
EventOrder int64 `json:"event_order"`
UID string `json:"uid,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
State 是身份撤销权威中的单调状态。
type Store ¶
type Store interface {
Current(context.Context, IdentityKey) (State, error)
Apply(context.Context, types.CasdoorEvent, time.Duration) (ApplyResult, error)
ConfirmActive(context.Context, IdentityKey, uint64) (State, error)
SaveSnapshot(context.Context, State) error
MarkControlPublished(context.Context, types.CasdoorEvent) error
SavePendingHook(context.Context, PendingHook) error
MarkPendingHookReady(context.Context, string) error
PendingHooks(context.Context, int) ([]PendingHook, error)
AckHook(context.Context, string) error
Close() error
}
Store 是本地 Badger 与共享 Redis 共用的撤销权威契约。