pdk-script-0.0.0-alpha.6 has been yanked.
PDK Script

pdk-script provides scripting utilities and helpers for PDK-based custom policies.
You may be looking for:
pdk-script in action
[dependencies]
pdk = { version = "1.6"}
mod generated {
use serde::Deserialize;
#[derive(Deserialize, Clone, Debug)]
pub struct Config {
#[serde(
alias = "exampleDateweaveProperty",
deserialize_with = "de_example_dateweave_property_0"
)]
pub example_dateweave_property: pdk::script::Script,
}
fn de_example_dateweave_property_0<'de, D>(
deserializer: D,
) -> Result<pdk::script::Script, D::Error>
where
D: serde::de::Deserializer<'de>,
{
let exp: pdk::script::Expression = serde::de::Deserialize::deserialize(
deserializer,
)?;
pdk::script::ScriptingEngine::script(&exp)
.input(pdk::script::Input::Attributes)
.input(pdk::script::Input::Authentication)
.input(pdk::script::Input::Payload(pdk::script::Format::Json))
.input(pdk::script::Input::Payload(pdk::script::Format::Xml))
.input(pdk::script::Input::Payload(pdk::script::Format::PlainText))
.input(pdk::script::Input::Vars("exampleVar"))
.compile()
.map_err(serde::de::Error::custom)
}
}
use std::collections::HashMap;
use anyhow::{anyhow, Result};
use pdk::authentication::{Authentication, AuthenticationHandler};
use pdk::hl::*;
use pdk::script::{EvaluationError, HandlerAttributesBinding, Value};
use crate::generated::config::Config;
async fn request_filter(request_state: RequestState, stream_properties: StreamProperties, authentication: Authentication, config: &Config) {
let headers_state = request_state.into_headers_state().await;
let mut eval = config.example_dateweave_property.evaluator();
eval.bind_attributes(&HandlerAttributesBinding::new(headers_state.handler(), &stream_properties));
eval.bind_authentication(&authentication.authentication());
let body_state = headers_state.into_body_state().await;
eval.bind_payload(&body_state);
eval.bind_vars("exampleVar", "exampleValue");
let result: Result<Value, EvaluationError> = eval.eval();
}
#[entrypoint]
async fn configure(launcher: Launcher, Configuration(bytes): Configuration) -> Result<()> {
let config: Config = serde_json::from_slice(&bytes).map_err(|err| {
anyhow!(
"Failed to parse configuration '{}'. Cause: {}",
String::from_utf8_lossy(&bytes),
err
)
})?;
let filter = on_request(|rs, stream_properties, authentication| request_filter(rs, stream_properties, authentication, &config));
launcher.launch(filter).await?;
Ok(())
}
License