Skip to content

Commit ce45daa

Browse files
authored
update for cedar#1452 (#532)
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
1 parent ead3c16 commit ce45daa

File tree

10 files changed

+45
-38
lines changed

10 files changed

+45
-38
lines changed

cedar-drt/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ publish = false
88
env_logger = "0.10"
99
log = "0.4"
1010
libfuzzer-sys = "0.4"
11-
cedar-policy = { path = "../cedar/cedar-policy", version = "4.*" }
12-
cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "protobufs", "datetime"] }
13-
cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "protobufs", "datetime"] }
11+
cedar-policy = { path = "../cedar/cedar-policy", version = "4.*", features = ["protobufs"] }
12+
cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "datetime"] }
13+
cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "datetime"] }
1414
cedar-policy-formatter = { path = "../cedar/cedar-policy-formatter", version = "4.*" }
1515
cedar-testing = { path = "../cedar/cedar-testing", version = "4.*" }
1616
lean-sys = { version = "0.0.7", features = ["small_allocator"], default-features = false }

cedar-drt/build.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ fn main() {
3333
println!("cargo:rerun-if-changed={LEAN_BUILD_DIR}");
3434

3535
let mut config = prost_build::Config::new();
36-
config.extern_path(".cedar_policy_core", "::cedar_policy_core::ast::proto");
37-
config.extern_path(".cedar_policy_validator", "::cedar_policy_validator::proto");
36+
config.extern_path(".cedar_policy_core", "::cedar_policy::proto::models");
37+
config.extern_path(".cedar_policy_validator", "::cedar_policy::proto::models");
3838
config
3939
.compile_protos(
4040
&["./protobuf_schema/Messages.proto"],
41-
&[
42-
"./protobuf_schema",
43-
"../cedar/cedar-policy-core/protobuf_schema",
44-
"../cedar/cedar-policy-validator/protobuf_schema",
45-
],
41+
&["./protobuf_schema", "../cedar/cedar-policy/protobuf_schema"],
4642
)
4743
.unwrap();
4844
}

cedar-drt/fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ serde = { version = "1.0", feature = ["derive"] }
1515
serde_json = "1.0"
1616
cedar-drt = { version = "4.0.0", path = ".." }
1717
cedar-policy = { path = "../../cedar/cedar-policy", version = "4.*", features = ["protobufs"] }
18-
cedar-policy-core = { path = "../../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "protobufs", "datetime"] }
19-
cedar-policy-validator = { path = "../../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "entity-manifest", "protobufs", "datetime"] }
18+
cedar-policy-core = { path = "../../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "datetime"] }
19+
cedar-policy-validator = { path = "../../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "entity-manifest", "datetime"] }
2020
cedar-policy-formatter = { path = "../../cedar/cedar-policy-formatter", version = "4.*" }
2121
cedar-testing = { path = "../../cedar/cedar-testing", version = "4.*" }
2222
cedar-policy-generators = { path = "../../cedar-policy-generators", version = "4.*" }

cedar-drt/fuzz/fuzz_targets/protobuf-roundtrip.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::arbitrary::Arbitrary;
2424
use crate::arbitrary::Unstructured;
2525
use cedar_drt::{AuthorizationRequestMsg, OwnedAuthorizationRequestMsg};
2626
use cedar_drt_inner::{fuzz_target, schemas::Equiv};
27+
use cedar_policy::proto;
2728
use cedar_policy_core::{
2829
ast, entities::Entities, entities::NoEntitiesSchema, entities::TCComputation,
2930
extensions::Extensions,
@@ -147,13 +148,13 @@ fn roundtrip_authz_request_msg(auth_request: AuthorizationRequestMsg) {
147148

148149
fn roundtrip_schema(schema: cedar_policy_validator::ValidatorSchema) {
149150
// AST -> Protobuf bytes
150-
let schema_proto = cedar_policy_validator::proto::ValidatorSchema::from(&schema);
151+
let schema_proto = proto::models::ValidatorSchema::from(&schema);
151152

152153
// Protobuf -> Bytes
153154
let buf = schema_proto.encode_to_vec();
154155

155156
// Bytes -> Protobuf
156-
let roundtripped_proto = cedar_policy_validator::proto::ValidatorSchema::decode(&buf[..])
157+
let roundtripped_proto = proto::models::ValidatorSchema::decode(&buf[..])
157158
.expect("Failed to deserialize Schema from proto");
158159

159160
// Protobuf -> AST

cedar-drt/fuzz/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,15 @@ fn test_run_auth_test() {
445445
.unwrap();
446446
let entity_view = Entity::new_with_attr_partial_value(
447447
EntityUID::with_eid_and_type("Action", "view").unwrap(),
448-
std::collections::HashMap::new(),
448+
[],
449449
std::collections::HashSet::new(),
450+
[],
450451
);
451452
let entity_vacation = Entity::new_with_attr_partial_value(
452453
EntityUID::with_eid_and_type("Photo", "vacation").unwrap(),
453-
std::collections::HashMap::new(),
454+
[],
454455
std::collections::HashSet::new(),
456+
[],
455457
);
456458
let entities = Entities::from_entities(
457459
vec![entity_alice, entity_view, entity_vacation],

cedar-drt/fuzz/src/schemas.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,12 @@ fn either_empty<N>(spec: &json_schema::ApplySpec<N>) -> bool {
575575
impl Equiv for cedar_policy_validator::ValidatorSchema {
576576
fn equiv(lhs: &Self, rhs: &Self) -> Result<(), String> {
577577
Equiv::equiv(
578-
&lhs.entity_types().collect::<HashMap<_, _>>(),
579-
&rhs.entity_types().collect::<HashMap<_, _>>(),
578+
&lhs.entity_types()
579+
.map(|et| (et.name(), et))
580+
.collect::<HashMap<_, _>>(),
581+
&rhs.entity_types()
582+
.map(|et| (et.name(), et))
583+
.collect::<HashMap<_, _>>(),
580584
)
581585
.map_err(|e| format!("entity attributes are not equivalent: {e}"))?;
582586
Equiv::equiv(

cedar-drt/protobuf_schema/Messages.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
syntax = "proto3";
22
package cedar_drt;
3-
import "AST.proto";
4-
import "Validator.proto";
3+
import "core.proto";
4+
import "validator.proto";
55

66
message AuthorizationRequestMsg {
77
cedar_policy_core.Request request = 1;

cedar-drt/src/definitional_request_types.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ pub struct AuthorizationRequestMsg<'a> {
3535
impl From<&AuthorizationRequestMsg<'_>> for proto::AuthorizationRequestMsg {
3636
fn from(v: &AuthorizationRequestMsg<'_>) -> Self {
3737
Self {
38-
request: Some(ast::proto::Request::from(v.request)),
39-
policies: Some(ast::proto::LiteralPolicySet::from(v.policies)),
40-
entities: Some(ast::proto::Entities::from(v.entities)),
38+
request: Some(cedar_policy::proto::models::Request::from(v.request)),
39+
policies: Some(cedar_policy::proto::models::LiteralPolicySet::from(
40+
v.policies,
41+
)),
42+
entities: Some(cedar_policy::proto::models::Entities::from(v.entities)),
4143
}
4244
}
4345
}
@@ -72,11 +74,11 @@ pub struct ValidationRequestMsg<'a> {
7274
impl From<&ValidationRequestMsg<'_>> for proto::ValidationRequestMsg {
7375
fn from(v: &ValidationRequestMsg<'_>) -> Self {
7476
Self {
75-
schema: Some(cedar_policy_validator::proto::ValidatorSchema::from(
76-
v.schema,
77+
schema: Some(cedar_policy::proto::models::ValidatorSchema::from(v.schema)),
78+
policies: Some(cedar_policy::proto::models::LiteralPolicySet::from(
79+
v.policies,
7780
)),
78-
policies: Some(ast::proto::LiteralPolicySet::from(v.policies)),
79-
mode: cedar_policy_validator::proto::ValidationMode::from(&v.mode).into(),
81+
mode: cedar_policy::proto::models::ValidationMode::from(&v.mode).into(),
8082
}
8183
}
8284
}

cedar-lean/UnitTest/CedarProto-test-data/generate-protodata/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ edition = "2021"
88
repository = "https://github.com/cedar-policy/cedar-spec"
99

1010
[dependencies]
11-
cedar-policy-core = { git = "https://github.com/cedar-policy/cedar", version = "*", features = ["protobufs"] }
12-
cedar-policy-validator = { git = "https://github.com/cedar-policy/cedar", version = "*", features = ["protobufs"] }
11+
cedar-policy-core = { git = "https://github.com/cedar-policy/cedar", version = "*" }
12+
cedar-policy-validator = { git = "https://github.com/cedar-policy/cedar", version = "*" }
13+
cedar-policy = { git = "https://github.com/cedar-policy/cedar", version = "*", features = ["protobufs"] }
1314
miette = { version = "7.1.0", features = ["fancy"] }
1415
prost = "0.13"
1516

cedar-lean/UnitTest/CedarProto-test-data/generate-protodata/src/main.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cedar_policy_core::{
44
parser::{parse_policy, parse_policy_or_template, parse_policyset, Loc},
55
};
66
use cedar_policy_validator::types as validator_types;
7+
use cedar_policy::proto;
78
use prost::Message;
89
use std::collections::{BTreeMap, HashMap, HashSet};
910
use std::path::{Path, PathBuf};
@@ -18,7 +19,7 @@ fn output_dir() -> PathBuf {
1819
#[track_caller]
1920
fn encode_expr(path: impl AsRef<Path>, e: &str) {
2021
let expr: ast::Expr = e.parse().unwrap();
21-
let proto: ast::proto::Expr = (&expr).into();
22+
let proto: proto::models::Expr = (&expr).into();
2223
let encoded = proto.encode_to_vec();
2324
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
2425
}
@@ -27,56 +28,56 @@ fn encode_expr(path: impl AsRef<Path>, e: &str) {
2728
#[track_caller]
2829
fn encode_policy_as_template(path: impl AsRef<Path>, p: &str) {
2930
let policy: ast::Template = parse_policy_or_template(None, p).unwrap().into();
30-
let proto: ast::proto::TemplateBody = (&policy).into();
31+
let proto: proto::models::TemplateBody = (&policy).into();
3132
let encoded = proto.encode_to_vec();
3233
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
3334
}
3435

3536
#[track_caller]
3637
fn encode_policyset(path: impl AsRef<Path>, ps: &ast::PolicySet) {
37-
let proto: ast::proto::LiteralPolicySet = ps.into();
38+
let proto: proto::models::LiteralPolicySet = ps.into();
3839
let encoded = proto.encode_to_vec();
3940
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
4041
}
4142

4243
#[track_caller]
4344
fn encode_request(path: impl AsRef<Path>, r: &ast::Request) {
44-
let proto: ast::proto::Request = r.into();
45+
let proto: proto::models::Request = r.into();
4546
let encoded = proto.encode_to_vec();
4647
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
4748
}
4849

4950
#[track_caller]
5051
fn encode_entity(path: impl AsRef<Path>, e: &ast::Entity) {
51-
let proto: ast::proto::Entity = e.into();
52+
let proto: proto::models::Entity = e.into();
5253
let encoded = proto.encode_to_vec();
5354
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
5455
}
5556

5657
#[track_caller]
5758
fn encode_entities(path: impl AsRef<Path>, es: &entities::Entities) {
58-
let proto: ast::proto::Entities = es.into();
59+
let proto: proto::models::Entities = es.into();
5960
let encoded = proto.encode_to_vec();
6061
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
6162
}
6263

6364
#[track_caller]
6465
fn encode_val_type(path: impl AsRef<Path>, ty: &validator_types::Type) {
65-
let proto: cedar_policy_validator::proto::Type = ty.into();
66+
let proto: proto::models::Type = ty.into();
6667
let encoded = proto.encode_to_vec();
6768
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
6869
}
6970

7071
#[track_caller]
7172
fn encode_schema(path: impl AsRef<Path>, s: &str) {
72-
let (schema, warnings) = cedar_policy_validator::ValidatorSchema::from_cedarschema_str(
73+
let (schema, warnings) = proto::models::ValidatorSchema::from_cedarschema_str(
7374
s,
7475
&Extensions::all_available(),
7576
)
7677
.map_err(|e| format!("{:?}", miette::Report::new(e)))
7778
.unwrap();
7879
assert_eq!(warnings.count(), 0);
79-
let proto: cedar_policy_validator::proto::ValidatorSchema = (&schema).into();
80+
let proto: proto::models::ValidatorSchema = (&schema).into();
8081
let encoded = proto.encode_to_vec();
8182
std::fs::write(output_dir().join(path.as_ref()), encoded).unwrap();
8283
}

0 commit comments

Comments
 (0)