vector_vrl_functions/
remove_secret.rs1use vrl::prelude::*;
2
3fn remove_secret(ctx: &mut Context, key: Value) -> std::result::Result<Value, ExpressionError> {
4 let key_str = key.as_str().expect("argument must be a string");
5 ctx.target_mut().remove_secret(key_str.as_ref());
6 Ok(Value::Null)
7}
8
9#[derive(Clone, Copy, Debug)]
10pub struct RemoveSecret;
11
12impl Function for RemoveSecret {
13 fn identifier(&self) -> &'static str {
14 "remove_secret"
15 }
16
17 fn usage(&self) -> &'static str {
18 "Removes a secret from an event."
19 }
20
21 fn parameters(&self) -> &'static [Parameter] {
22 &[Parameter {
23 keyword: "key",
24 kind: kind::BYTES,
25 required: true,
26 }]
27 }
28
29 fn examples(&self) -> &'static [Example] {
30 &[example!(
31 title: "Remove the datadog api key",
32 source: r#"remove_secret("datadog_api_key")"#,
33 result: Ok("null"),
34 )]
35 }
36
37 fn compile(
38 &self,
39 _state: &TypeState,
40 _ctx: &mut FunctionCompileContext,
41 arguments: ArgumentList,
42 ) -> Compiled {
43 let key = arguments.required("key");
44 Ok(RemoveSecretFn { key }.as_expr())
45 }
46}
47
48#[derive(Debug, Clone)]
49struct RemoveSecretFn {
50 key: Box<dyn Expression>,
51}
52
53impl FunctionExpression for RemoveSecretFn {
54 fn resolve(&self, ctx: &mut Context) -> Resolved {
55 let key = self.key.resolve(ctx)?;
56 remove_secret(ctx, key)
57 }
58
59 fn type_def(&self, _: &TypeState) -> TypeDef {
60 TypeDef::null().infallible().impure()
61 }
62}