pub mod v1;
pub mod v2;
use vector_lib::config::{ComponentKey, LogNamespace};
use vector_lib::configurable::configurable_component;
use crate::{
config::{GenerateConfig, Input, OutputId, TransformConfig, TransformContext, TransformOutput},
schema,
transforms::Transform,
};
#[configurable_component]
#[derive(Clone, Debug)]
enum V1 {
#[configurable(metadata(deprecated))]
#[serde(rename = "1")]
V1,
}
#[configurable_component]
#[derive(Clone, Debug)]
pub struct LuaConfigV1 {
version: Option<V1>,
#[serde(flatten)]
config: v1::LuaConfig,
}
#[configurable_component]
#[derive(Clone, Debug)]
enum V2 {
#[serde(rename = "2")]
V2,
}
#[configurable_component]
#[derive(Clone, Debug)]
pub struct LuaConfigV2 {
version: V2,
#[serde(flatten)]
config: v2::LuaConfig,
}
#[configurable_component(transform(
"lua",
"Modify event data using the Lua programming language."
))]
#[derive(Clone, Debug)]
#[serde(untagged)]
pub enum LuaConfig {
V1(LuaConfigV1),
V2(LuaConfigV2),
}
impl GenerateConfig for LuaConfig {
fn generate_config() -> toml::Value {
toml::from_str(
r#"version = "2"
hooks.process = """#,
)
.unwrap()
}
}
#[async_trait::async_trait]
#[typetag::serde(name = "lua")]
impl TransformConfig for LuaConfig {
async fn build(&self, context: &TransformContext) -> crate::Result<Transform> {
let key = context
.key
.as_ref()
.map_or_else(|| ComponentKey::from("lua"), Clone::clone);
match self {
LuaConfig::V1(v1) => v1.config.build(),
LuaConfig::V2(v2) => v2.config.build(key),
}
}
fn input(&self) -> Input {
match self {
LuaConfig::V1(v1) => v1.config.input(),
LuaConfig::V2(v2) => v2.config.input(),
}
}
fn outputs(
&self,
_: vector_lib::enrichment::TableRegistry,
input_definitions: &[(OutputId, schema::Definition)],
_: LogNamespace,
) -> Vec<TransformOutput> {
match self {
LuaConfig::V1(v1) => v1.config.outputs(input_definitions),
LuaConfig::V2(v2) => v2.config.outputs(input_definitions),
}
}
}
#[cfg(test)]
mod test {
#[test]
fn generate_config() {
crate::test_util::test_generate_config::<super::LuaConfig>();
}
}