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