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))]
20 #[serde(rename = "1")]
21 V1,
22}
23
24#[configurable_component]
26#[derive(Clone, Debug)]
27pub struct LuaConfigV1 {
28 version: Option<V1>,
32
33 #[serde(flatten)]
34 config: v1::LuaConfig,
35}
36
37#[configurable_component]
39#[derive(Clone, Debug)]
40enum V2 {
41 #[serde(rename = "2")]
43 V2,
44}
45
46#[configurable_component]
48#[derive(Clone, Debug)]
49pub struct LuaConfigV2 {
50 version: V2,
54
55 #[serde(flatten)]
56 config: v2::LuaConfig,
57}
58
59#[configurable_component(transform(
61 "lua",
62 "Modify event data using the Lua programming language."
63))]
64#[derive(Clone, Debug)]
65#[serde(untagged)]
66pub enum LuaConfig {
67 V1(LuaConfigV1),
69
70 V2(LuaConfigV2),
72}
73
74impl GenerateConfig for LuaConfig {
75 fn generate_config() -> toml::Value {
76 toml::from_str(
77 r#"version = "2"
78 hooks.process = """#,
79 )
80 .unwrap()
81 }
82}
83
84#[async_trait::async_trait]
85#[typetag::serde(name = "lua")]
86impl TransformConfig for LuaConfig {
87 async fn build(&self, context: &TransformContext) -> crate::Result<Transform> {
88 let key = context
89 .key
90 .as_ref()
91 .map_or_else(|| ComponentKey::from("lua"), Clone::clone);
92 match self {
93 LuaConfig::V1(v1) => v1.config.build(),
94 LuaConfig::V2(v2) => v2.config.build(key),
95 }
96 }
97
98 fn input(&self) -> Input {
99 match self {
100 LuaConfig::V1(v1) => v1.config.input(),
101 LuaConfig::V2(v2) => v2.config.input(),
102 }
103 }
104
105 fn outputs(
106 &self,
107 _: &TransformContext,
108 input_definitions: &[(OutputId, schema::Definition)],
109 ) -> Vec<TransformOutput> {
110 match self {
111 LuaConfig::V1(v1) => v1.config.outputs(input_definitions),
112 LuaConfig::V2(v2) => v2.config.outputs(input_definitions),
113 }
114 }
115}
116
117#[cfg(test)]
118mod test {
119 #[test]
120 fn generate_config() {
121 crate::test_util::test_generate_config::<super::LuaConfig>();
122 }
123}