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 parameters(&self) -> &'static [Parameter] {
18 &[Parameter {
19 keyword: "key",
20 kind: kind::BYTES,
21 required: true,
22 }]
23 }
24
25 fn examples(&self) -> &'static [Example] {
26 &[Example {
27 title: "Remove the datadog api key",
28 source: r#"remove_secret("datadog_api_key")"#,
29 result: Ok("null"),
30 }]
31 }
32
33 fn compile(
34 &self,
35 _state: &TypeState,
36 _ctx: &mut FunctionCompileContext,
37 arguments: ArgumentList,
38 ) -> Compiled {
39 let key = arguments.required("key");
40 Ok(RemoveSecretFn { key }.as_expr())
41 }
42}
43
44#[derive(Debug, Clone)]
45struct RemoveSecretFn {
46 key: Box<dyn Expression>,
47}
48
49impl FunctionExpression for RemoveSecretFn {
50 fn resolve(&self, ctx: &mut Context) -> Resolved {
51 let key = self.key.resolve(ctx)?;
52 remove_secret(ctx, key)
53 }
54
55 fn type_def(&self, _: &TypeState) -> TypeDef {
56 TypeDef::null().infallible().impure()
57 }
58}