Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add placeholder for JSON pointer late-binding in policy expr #399

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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