5 releases
0.1.1 | Apr 3, 2024 |
---|---|
0.1.1-alpha.7 | Feb 23, 2024 |
0.1.1-alpha.6 | Feb 22, 2024 |
#643 in Authentication
425 downloads per month
36KB
233 lines
Kiwi SDK
This crate provides utilities necessary for writing Kiwi plugins.
Examples
Intercept
//! A simple intercept hook that discards odd numbers from all counter sources
use kiwi_sdk::hook::intercept::{intercept, Action, Context, CounterEventCtx, EventCtx};
/// You must use the `#[intercept]` macro to define an intercept hook.
#[intercept]
fn handle(ctx: Context) -> Action {
match ctx.event {
// We only care about counter sources in this example
EventCtx::Counter(CounterEventCtx {
source_id: _,
count,
}) => {
if count % 2 == 0 {
// Returning `Action::Forward` instructs Kiwi to forward the event
// to the associated client.
return Action::Forward;
} else {
// Returning `Action::Discard` instructs Kiwi to discard the event,
// preventing it from reaching the associated client.
return Action::Discard;
}
}
_ => {}
}
Action::Forward
}
Authenticate
//! A simple authenticate hook that allows all incoming HTTP requests
use kiwi_sdk::hook::authenticate::{authenticate, Outcome};
use kiwi_sdk::http::Request;
/// You must use the `#[authenticate]` macro to define an authenticate hook.
#[authenticate]
fn handle(req: Request<()>) -> Outcome {
// Returning `Outcome::Authenticate` instructs Kiwi to allow the connection to be established.
Outcome::Authenticate
}
Dependencies
~2.5MB
~53K SLoC