vector/transforms/lua/
mod.rs1pub mod v1;
2pub mod v2;
3
4use vector_lib::config::{ComponentKey, LogNamespace};
5use vector_lib::configurable::configurable_component;
6
7use crate::{
8 config::{GenerateConfig, Input, OutputId, TransformConfig, TransformContext, TransformOutput},
9 schema,
10 transforms::Transform,
11};
12
13#[configurable_component]
15#[derive(Clone, Debug)]
16enum V1 {
17 #[configurable(metadata(deprecated))]
25 #[serde(rename = "1")]
26 V1,
27}
28
29#[configurable_component]
31#[derive(Clone, Debug)]
32pub struct LuaConfigV1 {
33 version: Option<V1>,
37
38 #[serde(flatten)]
39 config: v1::LuaConfig,
40}
41
42#[configurable_component]
44#[derive(Clone, Debug)]
45enum V2 {
46 #[serde(rename = "2")]
48 V2,
49}
50
51#[configurable_component]
53#[derive(Clone, Debug)]
54pub struct LuaConfigV2 {
55 version: V2,
59
60 #[serde(flatten)]
61 config: v2::LuaConfig,
62}
63
64#[configurable_component(transform(
66 "lua",
67 "Modify event data using the Lua programming language."
68))]
69#[derive(Clone, Debug)]
70#[serde(untagged)]
71pub enum LuaConfig {
72 V1(LuaConfigV1),
74
75 V2(LuaConfigV2),
77}
78
79impl GenerateConfig for LuaConfig {
80 fn generate_config() -> toml::Value {
81 toml::from_str(
82 r#"version = "2"
83 hooks.process = """#,
84 )
85 .unwrap()
86 }
87}
88
89#[async_trait::async_trait]
90#[typetag::serde(name = "lua")]
91impl TransformConfig for LuaConfig {
92 async fn build(&self, context: &TransformContext) -> crate::Result<Transform> {
93 let key = context
94 .key
95 .as_ref()
96 .map_or_else(|| ComponentKey::from("lua"), Clone::clone);
97 match self {
98 LuaConfig::V1(v1) => v1.config.build(),
99 LuaConfig::V2(v2) => v2.config.build(key),
100 }
101 }
102
103 fn input(&self) -> Input {
104 match self {
105 LuaConfig::V1(v1) => v1.config.input(),
106 LuaConfig::V2(v2) => v2.config.input(),
107 }
108 }
109
110 fn outputs(
111 &self,
112 _: vector_lib::enrichment::TableRegistry,
113 input_definitions: &[(OutputId, schema::Definition)],
114 _: LogNamespace,
115 ) -> Vec<TransformOutput> {
116 match self {
117 LuaConfig::V1(v1) => v1.config.outputs(input_definitions),
118 LuaConfig::V2(v2) => v2.config.outputs(input_definitions),
119 }
120 }
121}
122
123#[cfg(test)]
124mod test {
125 #[test]
126 fn generate_config() {
127 crate::test_util::test_generate_config::<super::LuaConfig>();
128 }
129}