Skip to content

Commit

Permalink
update for cedar#1506
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
  • Loading branch information
cdisselkoen committed Feb 26, 2025
1 parent 7f3e72a commit 9271f0b
Show file tree
Hide file tree
Showing 46 changed files with 61 additions and 136 deletions.
18 changes: 10 additions & 8 deletions cedar-lean/CedarProto/Entities.lean
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ namespace Cedar.Spec

def EntitiesProto : Type := Array EntityProto
deriving instance Inhabited for EntitiesProto
instance : HAppend EntitiesProto EntitiesProto EntitiesProto where
hAppend x y :=
let x : Array EntityProto := x
let y : Array EntityProto := y
x ++ y
instance : HAppend EntitiesProto (Array EntityProto) EntitiesProto where
hAppend x y :=
let x : Array EntityProto := x
x ++ y

namespace EntitiesProto

@[inline]
def mergeEntities (result : EntitiesProto) (x : Repeated EntityProto) : EntitiesProto :=
have x : Array EntityProto := x.map λ xi => { xi with data := xi.data.mkWf }
have result : Array EntityProto := result
def mergeEntities (result : EntitiesProto) (x : Array EntityProto) : EntitiesProto :=
result ++ x

@[inline]
def merge (x : EntitiesProto) (y : EntitiesProto) : EntitiesProto :=
have x : Array EntityProto := x
have y : Array EntityProto := y
x ++ y

@[inline]
Expand All @@ -52,7 +57,6 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntitiesProto) := do
| 1 =>
let x : Repeated EntityProto ← Field.guardedParse t
pure (pure $ mergeEntities · x)
-- Ignoring 3 | mode
| _ =>
t.wireType.skip
pure ignore
Expand All @@ -71,8 +75,6 @@ end EntitiesProto
namespace Entities
@[inline]
def merge (e1 : Entities) (e2 : Entities) : Entities :=
let e1 : Cedar.Data.Map EntityUID EntityData := e1
let e2 : Cedar.Data.Map EntityUID EntityData := e2
-- Don't sort if e1 is empty
match e1.kvs with
| [] => e2
Expand Down
21 changes: 1 addition & 20 deletions cedar-lean/CedarProto/Expr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -729,14 +729,6 @@ def merge (x1 x2 : ExprKind) : ExprKind :=
-- end of this file
end Proto.ExprKind

namespace Expr
-- There's one additinoal message wrapped around ExprKind
-- that we need to parse
@[inline]
def mergeExprKind (x1 : Expr) (x2 : Proto.ExprKind) : Expr :=
Expr.merge x1 x2
end Expr

-- Expr depends on ExprKind and ExprKind is a sum type
-- where many of the constructors depend on Expr
mutual
Expand Down Expand Up @@ -897,7 +889,7 @@ partial def Proto.ExprKind.Record.parseField (t : Proto.Tag) : BParsec (MergeFn
t.wireType.skip
pure ignore

partial def Proto.ExprKind.parseField (t : Proto.Tag) : BParsec (MergeFn Proto.ExprKind) := do
partial def Expr.parseField (t : Proto.Tag) : BParsec (MergeFn Expr) := do
have : Message Proto.ExprKind.If := { parseField := Proto.ExprKind.If.parseField, merge := Proto.ExprKind.If.merge }
have : Message Proto.ExprKind.And := { parseField := Proto.ExprKind.And.parseField, merge := Proto.ExprKind.And.merge }
have : Message Proto.ExprKind.Or := { parseField := Proto.ExprKind.Or.parseField, merge := Proto.ExprKind.Or.merge }
Expand All @@ -911,7 +903,6 @@ partial def Proto.ExprKind.parseField (t : Proto.Tag) : BParsec (MergeFn Proto.E
have : Message Proto.ExprKind.Set := { parseField := Proto.ExprKind.Set.parseField, merge := Proto.ExprKind.Set.merge }
have : Message Proto.ExprKind.Record := { parseField := Proto.ExprKind.Record.parseField, merge := Proto.ExprKind.Record.merge }


match t.fieldNum with
| 1 =>
let x : Prim ← Field.guardedParse t
Expand Down Expand Up @@ -959,16 +950,6 @@ partial def Proto.ExprKind.parseField (t : Proto.Tag) : BParsec (MergeFn Proto.E
t.wireType.skip
pure ignore

partial def Expr.parseField (t : Proto.Tag) : BParsec (MergeFn Expr) := do
have : Message Proto.ExprKind := { parseField := Proto.ExprKind.parseField, merge := Proto.ExprKind.merge }
match t.fieldNum with
| 1 =>
let x : Proto.ExprKind ← Field.guardedParse t
pure (pure $ Expr.mergeExprKind · x)
| _ =>
t.wireType.skip
pure ignore

end

instance : Message Expr := {
Expand Down
2 changes: 1 addition & 1 deletion cedar-lean/CedarProto/Request.lean
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def mergeContext (result : Request) (x : Value) : Request :=
match x with
| .record pairs =>
{result with
context := Data.Map.mk (result.context.kvs ++ pairs.kvs)
context := Data.Map.make (result.context.kvs ++ pairs.kvs)
}
| _ => panic!("Context is not of correct type")

Expand Down
1 change: 0 additions & 1 deletion cedar-lean/UnitTest/CedarProto-test-data/345.protodata
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@


�
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/abac.protodata
Binary file not shown.
3 changes: 1 addition & 2 deletions cedar-lean/UnitTest/CedarProto-test-data/action.protodata
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@



Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


"

WidgetApp123
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/complicated.protodata
Binary file not shown.
11 changes: 2 additions & 9 deletions cedar-lean/UnitTest/CedarProto-test-data/contains.protodata
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@

BB@+
)r'

B4#r!







"

Useralice
R

Useralice R
foo
16 changes: 5 additions & 11 deletions cedar-lean/UnitTest/CedarProto-test-data/decimal.protodata
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
J@

JJH


lessThan
J
lessThanJ

decimal


3.14
J
decimal
3.14J

decimal

decimal

3.1416
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/emptyrecord.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/emptyset.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/emptystring.protodata
Binary file not shown.
4 changes: 2 additions & 2 deletions cedar-lean/UnitTest/CedarProto-test-data/entities.protodata
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@



DEF234
ABC123



ABC123
DEF234
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/entity.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/false.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/has_and_get.protodata
Binary file not shown.
Binary file not shown.
15 changes: 5 additions & 10 deletions cedar-lean/UnitTest/CedarProto-test-data/ip.protodata
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

MJK
JC

isInRange
J
isInRangeJ

ip

 192.168.0.1
J
ip
 192.168.0.1J

ip

ip
 192.0.0.0/8
Expand Down
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/is.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/like.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/nested_record.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/nested_set.protodata
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/not_and_neg.protodata
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@

?B=!
B

 
R

count
B



B/B
 R
countB


Expand Down
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/policyset.protodata
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/rbac.protodata
Binary file not shown.
17 changes: 7 additions & 10 deletions cedar-lean/UnitTest/CedarProto-test-data/record.protodata
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

!z

ham



eggs


z

eggs


ham

8 changes: 3 additions & 5 deletions cedar-lean/UnitTest/CedarProto-test-data/request.protodata
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

Actionaccess

Folderdata"
z

foo

Folderdata"z

foo

Binary file modified cedar-lean/UnitTest/CedarProto-test-data/schema_attrs.protodata
Binary file not shown.
36 changes: 12 additions & 24 deletions cedar-lean/UnitTest/CedarProto-test-data/schema_basic.protodata
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@



B

B 


A



A
B ?
B


B


ActionReadX*
ActionWrite"


ActionReadX":
AB
BB
AA


ActionRead-
ActionReadX*
A2
A2
B%


ActionRead

ActionReadX"0


ActionWrite


ActionWrite"
ActionReadX
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/schema_tags.protodata
Binary file not shown.
5 changes: 1 addition & 4 deletions cedar-lean/UnitTest/CedarProto-test-data/set.protodata
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

#r!

r

���������



minustwo
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@


this is Cedar
Expand Down
1 change: 0 additions & 1 deletion cedar-lean/UnitTest/CedarProto-test-data/true.protodata
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@



6 changes: 2 additions & 4 deletions cedar-lean/UnitTest/CedarProto-test-data/type_bool.protodata
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@



E


E
attr
 

8 changes: 3 additions & 5 deletions cedar-lean/UnitTest/CedarProto-test-data/type_ip.protodata
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

&

E


E
attr

"
ipaddr 
*
ipaddr
6 changes: 2 additions & 4 deletions cedar-lean/UnitTest/CedarProto-test-data/type_long.protodata
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@



E


E
attr
 

Binary file modified cedar-lean/UnitTest/CedarProto-test-data/type_record.protodata
Binary file not shown.
Binary file not shown.
Binary file modified cedar-lean/UnitTest/CedarProto-test-data/type_string.protodata
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


"

Useralice

0 comments on commit 9271f0b

Please sign in to comment.