pub struct WorkflowPlugin {
rules: Vec<Rule>,
}Expand description
Evaluates ordered rules; the first rule whose case matches applies its
action. Rules without a case always match. No matching rule means
passthrough.
Fields§
§rules: Vec<Rule>Implementations§
Source§impl WorkflowPlugin
impl WorkflowPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds the plugin from node config. All expressions and action parameters are validated here at config load.
Accepted keys:
rules(array, required, non-empty): evaluated in order.case(array, optional): APISIX triple-array condition, rules AND-ed (e.g.[["uri", "==", "/v1"], ["arg_debug", "==", "1"]]). Omit to match every request.actions(array, required):[[name, params]]. Only the first action is applied (APISIX supports exactly one). Supported:"return"— params{code}(integer 100-599, required). Rejects with that status and body{"error_msg":"rejected by workflow"}."limit-count"— params:count(integer > 0, required): allowed requests per window.time_window(number > 0, seconds, required).key(string, default"$remote_addr"):$vartemplate resolved per request into the counter key.rejected_code(integer 200-599, default503).rejected_msg(string, optional): when set, the rejection body is{"error_msg": "<msg>"}; empty body otherwise.policy(string, default"local"): counter backend name.
type: workflow
config:
rules:
- case:
- ["uri", "~~", "^/admin"]
actions:
- ["return", { "code": 403 }]
- actions:
- ["limit-count", { "count": 100, "time_window": 60, "key": "$remote_addr" }]Sourcefn reject(
ctx: Context,
status: u16,
body: Bytes,
code: &str,
message: &str,
) -> Result<PluginOutput, PluginExecutionError>
fn reject( ctx: Context, status: u16, body: Bytes, code: &str, message: &str, ) -> Result<PluginOutput, PluginExecutionError>
Writes a JSON rejection onto the response and returns the error result so the graph engine routes through the error port.
Trait Implementations§
Source§impl Plugin for WorkflowPlugin
impl Plugin for WorkflowPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”).
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the plugin logic against the request/response context. Read more
Auto Trait Implementations§
impl Freeze for WorkflowPlugin
impl !RefUnwindSafe for WorkflowPlugin
impl Send for WorkflowPlugin
impl Sync for WorkflowPlugin
impl Unpin for WorkflowPlugin
impl UnsafeUnpin for WorkflowPlugin
impl !UnwindSafe for WorkflowPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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