Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Wells <[email protected]>
  • Loading branch information
andrewmwells-amazon committed Nov 20, 2024
1 parent b214c0e commit 4431da6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
2 changes: 2 additions & 0 deletions cedar-policy-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fn generate_schemas() {
".cedar_policy_validator",
"crate::cedar_policy_validator::proto",
);
// PANIC SAFETY: compile-time unwrap
#[allow(clippy::unwrap_used)]
config
.compile_protos(
&["protobuf_schema/CLI.proto"],
Expand Down
62 changes: 40 additions & 22 deletions cedar-policy-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,37 +1741,55 @@ pub mod serialization {
pub new_policies: &'a PolicySet,
}

pub fn write_drt_json_for_equivalence(args: EquivalenceArgs) -> Result<()> {
let schema = &read_schema_from_file(&args.schema_file)?;
let old_policies = &read_policies_from_file(&args.old_policies_file)?;
let new_policies = &read_policies_from_file(&args.new_policies_file)?;

let s: String = serde_json::to_string(&EquivRequest {
schema,
old_policies,
new_policies,
})
.expect("failed to serialize schema or policies");

println!("{s}");
Ok(())
pub fn write_drt_json_for_equivalence(args: EquivalenceArgs) -> CedarExitCode {
let schema = &read_schema_from_file(&args.schema_file);
let old_policies = &read_policies_from_file(&args.old_policies_file);
let new_policies = &read_policies_from_file(&args.new_policies_file);

match (&schema, &old_policies, &new_policies) {
(Ok(schema), Ok(old_policies), Ok(new_policies)) => {
match serde_json::to_string(&EquivRequest {
schema,
old_policies,
new_policies,
}) {
Ok(s) => {
println!("{s}");
CedarExitCode::Success
}
Err(e) => {
eprintln!("{e}");
CedarExitCode::Failure
}
}
}
(_, _, _) => {
if let Some(e) = schema.as_ref().err() {
eprintln!("{e}");
}
if let Some(e) = old_policies.as_ref().err() {
eprintln!("{e}");
}
if let Some(e) = new_policies.as_ref().err() {
eprintln!("{e}");
}
CedarExitCode::Failure
}
}
}

pub fn write_drt_json(acmd: AnalysisCommands) -> CedarExitCode {
let res = match acmd {
match acmd {
AnalysisCommands::Equivalence(args) => write_drt_json_for_equivalence(args),
};
match res {
Ok(()) => CedarExitCode::Success,
Err(e) => {
eprintln!("{e}");
CedarExitCode::Failure
}
}
}

#[cfg(feature = "protobufs")]
pub mod protobuf {
// PANIC SAFETY experimental feature
#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]

use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
Expand Down

0 comments on commit 4431da6

Please sign in to comment.