Skip to content

Commit

Permalink
feat: add placeholder for JSON pointer late-binding in policy expr
Browse files Browse the repository at this point in the history
  • Loading branch information
j-lanson authored and mchernicoff committed Sep 12, 2024
1 parent df777c9 commit f622be4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hipcheck/src/policy_exprs/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum Expr {

/// Stores the name of the input variable, followed by the lambda body.
Lambda(Ident, Box<Expr>),

/// Stores a late-binding for a JSON value.
JsonPointer(JsonPointer),
}

/// Primitive data.
Expand All @@ -52,6 +55,13 @@ pub enum Primitive {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Ident(pub String);

/// A late-binding for a JSON pointer
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JsonPointer {
pointer: String,
value: Option<serde_json::Value>,
}

/// A non-NaN 64-bit floating point number.
pub type F64 = NotNan<f64>;

Expand All @@ -67,6 +77,7 @@ impl Display for Expr {
write!(f, "({} {})", ident, args)
}
Expr::Lambda(arg, body) => write!(f, "(lambda ({}) {}", arg, body),
Expr::JsonPointer(pointer) => write!(f, "${}", pointer.pointer),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions hipcheck/src/policy_exprs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) fn eval(env: &Env, program: &Expr) -> Result<Expr> {
}
}
Expr::Lambda(_, body) => Ok((**body).clone()),
Expr::JsonPointer(_) => unreachable!(),
};

log::debug!("input: {program:?}, output: {output:?}");
Expand Down

0 comments on commit f622be4

Please sign in to comment.