Skip to content

Commit

Permalink
Add serialization to JSON/protobuf to CLI (#1326)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Wells <[email protected]>
  • Loading branch information
andrewmwells-amazon authored Nov 22, 2024
1 parent 264db6e commit 3166f9b
Show file tree
Hide file tree
Showing 9 changed files with 1,007 additions and 10 deletions.
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();
}

/// 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

0 comments on commit 3166f9b

Please sign in to comment.