pub struct AuthRateLimiter { /* private fields */ }Expand description
认证入口限流器:来源 IP + 业务身份双维度的 Redis 原子计数。
Implementations§
Source§impl AuthRateLimiter
impl AuthRateLimiter
Sourcepub fn new(config: AuthRateLimitConfig) -> Self
pub fn new(config: AuthRateLimitConfig) -> Self
用独立参数结构创建限流器。
Sourcepub async fn check(
&self,
ctx: &ActionContext,
operation: AuthOperation,
identity: &str,
) -> Result<(), BaseError>
pub async fn check( &self, ctx: &ActionContext, operation: AuthOperation, identity: &str, ) -> Result<(), BaseError>
记录一次尝试并判定是否超限。
Sourcepub async fn record_failure(
&self,
ctx: &ActionContext,
operation: AuthOperation,
identity: &str,
) -> Result<(), BaseError>
pub async fn record_failure( &self, ctx: &ActionContext, operation: AuthOperation, identity: &str, ) -> Result<(), BaseError>
记录一次认证失败;失败计数超限同样返回限流错误。
Sourcepub async fn clear_failures(
&self,
ctx: &ActionContext,
operation: AuthOperation,
identity: &str,
) -> Result<(), BaseError>
pub async fn clear_failures( &self, ctx: &ActionContext, operation: AuthOperation, identity: &str, ) -> Result<(), BaseError>
认证成功后清除该身份的失败计数。
Trait Implementations§
Auto Trait Implementations§
impl Forget for AuthRateLimiter
impl Freeze for AuthRateLimiter
impl Move for AuthRateLimiter
impl RefUnwindSafe for AuthRateLimiter
impl Send for AuthRateLimiter
impl Sync for AuthRateLimiter
impl Unpin for AuthRateLimiter
impl UnsafeUnpin for AuthRateLimiter
impl UnwindSafe for AuthRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more