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

Change log to log ESTs #151

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions cedar-drt/fuzz/fuzz_targets/eval-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#![no_main]
use cedar_drt::utils::expr_to_est;
use cedar_drt::*;
use cedar_drt_inner::*;
use cedar_policy_core::{
Expand Down Expand Up @@ -43,6 +44,7 @@ struct FuzzTargetInput {
#[serde(skip)]
pub entities: Entities,
/// generated expression
#[serde(serialize_with = "expr_to_est")]
pub expression: Expr,
/// the requests to try for this hierarchy and policy. We try 8 requests per
/// policy/hierarchy
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
mod cedar_test_impl;
mod dafny_java_impl;
mod logger;
pub mod utils;

pub use cedar_test_impl::*;
pub use dafny_java_impl::*;
Expand Down
14 changes: 11 additions & 3 deletions cedar-policy-generators/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::err::Result;
use crate::hierarchy::Hierarchy;
use crate::size_hint_utils::size_hint_for_ratio;
use arbitrary::{Arbitrary, Unstructured};
use cedar_policy_core::ast;
use cedar_policy_core::ast::{
Effect, EntityUID, Expr, Id, PolicyID, PolicySet, StaticPolicy, Template,
Effect, EntityUID, Expr, Id, Policy, PolicyID, PolicySet, StaticPolicy, Template,
};
use cedar_policy_core::{ast, est};
use serde::Serialize;
use smol_str::SmolStr;
use std::fmt::Display;
Expand All @@ -18,7 +18,7 @@ use std::fmt::Display;
// `arbitrary_for_hierarchy()`. But as of this writing, it feels like renaming
// `GeneratedPolicy` to something like `GeneratedTemplate` seems unduly
// disruptive.
#[serde(into = "String")]
#[serde(into = "est::Policy")]
pub struct GeneratedPolicy {
id: PolicyID,
// use String for the impl of Arbitrary
Expand All @@ -30,6 +30,14 @@ pub struct GeneratedPolicy {
abac_constraints: Expr,
}

impl From<GeneratedPolicy> for est::Policy {
fn from(gp: GeneratedPolicy) -> est::Policy {
let sp: StaticPolicy = gp.into();
let p: Policy = sp.into();
p.into()
Comment on lines +35 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is simultaneously beautiful and gross

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean 35 and 36 compile into no-ops, but I do wish the type system could figure out transitive into's

}
}

impl GeneratedPolicy {
/// Create a new `GeneratedPolicy` with these fields
pub fn new(
Expand Down
Loading