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

Add serialization to JSON/protobuf to CLI #1326

Merged
merged 10 commits into from
Nov 22, 2024
70 changes: 62 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cedar-policy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ repository.workspace = true
[dependencies]
cedar-policy = { version = "=4.1.0", path = "../cedar-policy" }
cedar-policy-formatter = { version = "=4.1.0", path = "../cedar-policy-formatter" }
cedar-policy-core = { package= "cedar-policy-core", git = "https://github.com/cedar-policy/cedar.git", branch = "main", version = "=4.1.0"}
cedar-policy-validator = { package= "cedar-policy-validator", git = "https://github.com/cedar-policy/cedar.git", branch = "main", version = "=4.1.0"}
clap = { version = "4", features = ["derive", "env"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
miette = { version = "7.1.0", features = ["fancy"] }
thiserror = "2.0"
semver = "1.0.23"
prost = {version = "0.13", optional = true}

[build-dependencies]
prost-build = {version = "0.13", optional = true}

[features]
default = []
experimental = ["permissive-validate", "partial-validate", "partial-eval"]
permissive-validate = ["cedar-policy/permissive-validate"]
partial-validate = ["cedar-policy/partial-validate"]
partial-eval = ["cedar-policy/partial-eval"]
protobufs = ["dep:prost", "dep:prost-build", "cedar-policy/protobufs", "cedar-policy-core/protobufs", "cedar-policy-validator/protobufs"]

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
20 changes: 20 additions & 0 deletions cedar-policy-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fn main() {
#[cfg(feature = "protobufs")]
generate_schemas();
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved
}

/// Reads protobuf schema files (.proto) and generates Rust modules
#[cfg(feature = "protobufs")]
fn generate_schemas() {
let mut config = prost_build::Config::new();
config.extern_path(".cedar_policy_core", "crate::cedar_policy_core::ast::proto");
config.extern_path(
".cedar_policy_validator",
"crate::cedar_policy_validator::proto",
);
// PANIC SAFETY: compile-time unwrap
#[allow(clippy::unwrap_used)]
config
.compile_protos(&["protobuf_schema/CLI.proto"], &["protobuf_schema"])
.unwrap();
}
Loading