pub mod allowlist;
pub mod decode;
pub mod redact;
pub mod render;
pub mod schema;
pub mod transport;
pub mod with;
pub use with::{AsJson, AsPath};
use std::future::Future;
use serde_json::{Map, Value};
pub use allowlist::ensure_url_allowed;
pub use decode::{DecodedBody, decode_response};
pub use redact::Redactor;
pub use render::TemplateRenderer;
pub use schema::{AllowRule, CommandMode, ResultDecode, ResultExtract, ResultTemplate};
pub use transport::ResolvedTransport;
#[derive(Debug, Clone)]
pub enum PreparedBody {
Empty,
Json(Value),
Form(Vec<(String, String)>),
Multipart(Vec<PreparedMultipartPart>),
RawBytes {
bytes: Vec<u8>,
content_type: Option<String>,
},
}
#[derive(Debug, Clone)]
pub struct PreparedMultipartPart {
pub name: String,
pub bytes: Vec<u8>,
pub content_type: Option<String>,
pub filename: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ExecutionResult {
pub status: u16,
pub url: String,
pub result: Value,
pub decoded: Value,
}
#[derive(Debug, Clone)]
pub struct RawExecutionResult {
pub status: u16,
pub url: String,
pub body: Vec<u8>,
pub content_type: Option<String>,
}
#[derive(Debug, Clone)]
pub struct StreamChunk {
pub data: Vec<u8>,
pub content_type: Option<String>,
}
#[derive(Debug, Clone)]
pub struct StreamMeta {
pub status: u16,
pub url: String,
}
#[derive(Debug, Clone)]
pub struct ExecutionContext {
pub key: String,
pub mode: CommandMode,
pub allow_rules: Vec<AllowRule>,
pub transport: ResolvedTransport,
pub result_template: ResultTemplate,
pub args: Map<String, Value>,
pub redactor: Redactor,
}
pub trait ProtocolExecutor {
type PreparedData: Clone + std::fmt::Debug + Send + Sync;
fn execute(
&mut self,
data: &Self::PreparedData,
context: &ExecutionContext,
) -> impl Future<Output = anyhow::Result<RawExecutionResult>> + Send;
}
pub trait StreamingProtocolExecutor {
type PreparedData: Clone + std::fmt::Debug + Send + Sync;
fn execute_stream(
&mut self,
data: &Self::PreparedData,
context: &ExecutionContext,
sender: tokio::sync::mpsc::Sender<StreamChunk>,
) -> impl Future<Output = anyhow::Result<StreamMeta>> + Send;
}