Skip to content

Commit

Permalink
Merge pull request #60 from kubewarden/debugging-builtins
Browse files Browse the repository at this point in the history
Implement debugging builtins
  • Loading branch information
ereslibre authored Sep 9, 2021
2 parents bfc5d5e + f1cb147 commit 9bc5bd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/burrego/src/opa/builtins/debugging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::{anyhow, Result};

#[tracing::instrument(skip(args))]
pub fn trace(args: &[serde_json::Value]) -> Result<serde_json::Value> {
if args.len() != 1 {
return Err(anyhow!("Wrong number of arguments given to trace"));
}

let message_str = args[0]
.as_str()
.ok_or_else(|| anyhow!("trace: 1st parameter is not a string"))?;

tracing::debug!("{}", message_str);

Ok(serde_json::Value::Null)
}
4 changes: 4 additions & 0 deletions crates/burrego/src/opa/builtins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use std::collections::HashMap;

pub mod debugging;
pub mod encoding;
pub mod regex;
pub mod strings;
Expand All @@ -11,6 +12,9 @@ pub type BuiltinFunctionsMap =
pub fn get_builtins() -> BuiltinFunctionsMap {
let mut functions: BuiltinFunctionsMap = HashMap::new();

// debugging
functions.insert("trace", debugging::trace);

// encoding
functions.insert(
"base64url.encode_no_pad",
Expand Down

0 comments on commit 9bc5bd8

Please sign in to comment.