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"}
cedar-policy-validator = { package= "cedar-policy-validator", git = "https://github.com/cedar-policy/cedar.git", branch = "main", version = "4.1"}
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved
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 = "0.13"
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved

[build-dependencies]
prost-build = "0.13"

[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 = ["cedar-policy/protobufs", "cedar-policy-core/protobufs", "cedar-policy-validator/protobufs"]
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved

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

/// Reads protobuf schema files (.proto) and generates Rust modules
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",
"../cedar-policy-core/protobuf_schema",
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved
"../cedar-policy-validator/protobuf_schema",
],
)
.unwrap();
}
35 changes: 35 additions & 0 deletions cedar-policy-cli/protobuf_schema/CLI.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright Cedar Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

syntax = "proto3";
package amzn_cedar_internal_cli;
andrewmwells-amazon marked this conversation as resolved.
Show resolved Hide resolved

import "AST.proto";
import "Validator.proto";

message ValidationRequestMsg {
cedar_policy_validator.ValidatorSchema schema = 1;
cedar_policy_core.LiteralPolicySet policies = 2;
cedar_policy_validator.ValidationMode mode = 3;
}

message EquivRequestMsg {
cedar_policy_validator.ValidatorSchema schema = 1;
cedar_policy_core.LiteralPolicySet old_policies = 2;
cedar_policy_core.LiteralPolicySet new_policies = 3;
}


Loading
Loading