diff --git a/ast/ast_test.go b/ast/ast_test.go index 19d20969..cf73c172 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -57,10 +57,10 @@ func TestAstExamples(t *testing.T) { } _ = ast.Forbid(). When( - ast.Value(simpleRecord).Access("x").Equals(ast.String("value")), + ast.Value(simpleRecord).Access("x").Equal(ast.String("value")), ). When( - ast.Record(ast.Pairs{{Key: "x", Value: ast.Long(1).Add(ast.Context().Access("fooCount"))}}).Access("x").Equals(ast.Long(3)), + ast.Record(ast.Pairs{{Key: "x", Value: ast.Long(1).Add(ast.Context().Access("fooCount"))}}).Access("x").Equal(ast.Long(3)), ). When( ast.Set( @@ -245,13 +245,13 @@ func TestASTByTable(t *testing.T) { }, { "opEquals", - ast.Permit().When(ast.Long(42).Equals(ast.Long(43))), - internalast.Permit().When(internalast.Long(42).Equals(internalast.Long(43))), + ast.Permit().When(ast.Long(42).Equal(ast.Long(43))), + internalast.Permit().When(internalast.Long(42).Equal(internalast.Long(43))), }, { "opNotEquals", - ast.Permit().When(ast.Long(42).NotEquals(ast.Long(43))), - internalast.Permit().When(internalast.Long(42).NotEquals(internalast.Long(43))), + ast.Permit().When(ast.Long(42).NotEqual(ast.Long(43))), + internalast.Permit().When(internalast.Long(42).NotEqual(internalast.Long(43))), }, { "opLessThan", diff --git a/ast/operator.go b/ast/operator.go index 3dc649e4..6767d0aa 100644 --- a/ast/operator.go +++ b/ast/operator.go @@ -12,12 +12,12 @@ import ( // \____\___/|_| |_| |_| .__/ \__,_|_| |_|___/\___/|_| |_| // |_| -func (lhs Node) Equals(rhs Node) Node { - return wrapNode(lhs.Node.Equals(rhs.Node)) +func (lhs Node) Equal(rhs Node) Node { + return wrapNode(lhs.Node.Equal(rhs.Node)) } -func (lhs Node) NotEquals(rhs Node) Node { - return wrapNode(lhs.Node.NotEquals(rhs.Node)) +func (lhs Node) NotEqual(rhs Node) Node { + return wrapNode(lhs.Node.NotEqual(rhs.Node)) } func (lhs Node) LessThan(rhs Node) Node { diff --git a/internal/ast/ast_test.go b/internal/ast/ast_test.go index 87cded5b..f2d10918 100644 --- a/internal/ast/ast_test.go +++ b/internal/ast/ast_test.go @@ -56,11 +56,11 @@ func TestAstExamples(t *testing.T) { } _ = ast.Forbid(). When( - ast.Value(simpleRecord).Access("x").Equals(ast.String("value")), + ast.Value(simpleRecord).Access("x").Equal(ast.String("value")), ). When( ast.Record(ast.Pairs{{Key: "x", Value: ast.Long(1).Add(ast.Context().Access("fooCount"))}}). - Access("x").Equals(ast.Long(3)), + Access("x").Equal(ast.Long(3)), ). When( ast.Set( @@ -290,13 +290,13 @@ func TestASTByTable(t *testing.T) { }}, { "opEquals", - ast.Permit().When(ast.Long(42).Equals(ast.Long(43))), + ast.Permit().When(ast.Long(42).Equal(ast.Long(43))), ast.Policy{Effect: ast.EffectPermit, Principal: ast.ScopeTypeAll{}, Action: ast.ScopeTypeAll{}, Resource: ast.ScopeTypeAll{}, Conditions: []ast.ConditionType{{Condition: ast.ConditionWhen, Body: ast.NodeTypeEquals{BinaryNode: ast.BinaryNode{Left: ast.NodeValue{Value: types.Long(42)}, Right: ast.NodeValue{Value: types.Long(43)}}}}}}, }, { "opNotEquals", - ast.Permit().When(ast.Long(42).NotEquals(ast.Long(43))), + ast.Permit().When(ast.Long(42).NotEqual(ast.Long(43))), ast.Policy{Effect: ast.EffectPermit, Principal: ast.ScopeTypeAll{}, Action: ast.ScopeTypeAll{}, Resource: ast.ScopeTypeAll{}, Conditions: []ast.ConditionType{{Condition: ast.ConditionWhen, Body: ast.NodeTypeNotEquals{BinaryNode: ast.BinaryNode{Left: ast.NodeValue{Value: types.Long(42)}, Right: ast.NodeValue{Value: types.Long(43)}}}}}}, }, diff --git a/internal/ast/operator.go b/internal/ast/operator.go index 8d393805..07287f86 100644 --- a/internal/ast/operator.go +++ b/internal/ast/operator.go @@ -9,11 +9,11 @@ import "github.com/cedar-policy/cedar-go/types" // \____\___/|_| |_| |_| .__/ \__,_|_| |_|___/\___/|_| |_| // |_| -func (lhs Node) Equals(rhs Node) Node { +func (lhs Node) Equal(rhs Node) Node { return NewNode(NodeTypeEquals{BinaryNode: BinaryNode{Left: lhs.v, Right: rhs.v}}) } -func (lhs Node) NotEquals(rhs Node) Node { +func (lhs Node) NotEqual(rhs Node) Node { return NewNode(NodeTypeNotEquals{BinaryNode: BinaryNode{Left: lhs.v, Right: rhs.v}}) } diff --git a/internal/eval/compile.go b/internal/eval/compile.go index 7018bb97..a47de7c3 100644 --- a/internal/eval/compile.go +++ b/internal/eval/compile.go @@ -36,7 +36,7 @@ func scopeToNode(varNode ast.NodeTypeVariable, in ast.IsScopeNode) ast.Node { case ast.ScopeTypeAll: return ast.True() case ast.ScopeTypeEq: - return ast.NewNode(varNode).Equals(ast.Value(t.Entity)) + return ast.NewNode(varNode).Equal(ast.Value(t.Entity)) case ast.ScopeTypeIn: return ast.NewNode(varNode).In(ast.Value(t.Entity)) case ast.ScopeTypeInSet: diff --git a/internal/eval/compile_test.go b/internal/eval/compile_test.go index dad65f8c..4ff8a1a2 100644 --- a/internal/eval/compile_test.go +++ b/internal/eval/compile_test.go @@ -36,9 +36,9 @@ func TestPolicyToNode(t *testing.T) { ActionEq(types.NewEntityUID("Action", "test")). ResourceEq(types.NewEntityUID("Resource", "database")), - ast.Principal().Equals(ast.EntityUID("Account", "principal")).And( - ast.Action().Equals(ast.EntityUID("Action", "test")).And( - ast.Resource().Equals(ast.EntityUID("Resource", "database")), + ast.Principal().Equal(ast.EntityUID("Account", "principal")).And( + ast.Action().Equal(ast.EntityUID("Action", "test")).And( + ast.Resource().Equal(ast.EntityUID("Resource", "database")), ), ), }, @@ -81,7 +81,7 @@ func TestScopeToNode(t *testing.T) { "eq", ast.NewPrincipalNode(), ast.ScopeTypeEq{Entity: types.NewEntityUID("T", "42")}, - ast.Principal().Equals(ast.EntityUID("T", "42")), + ast.Principal().Equal(ast.EntityUID("T", "42")), }, { "in", diff --git a/internal/eval/convert_test.go b/internal/eval/convert_test.go index 70c8dc74..556bfb09 100644 --- a/internal/eval/convert_test.go +++ b/internal/eval/convert_test.go @@ -127,13 +127,13 @@ func TestToEval(t *testing.T) { }, { "equals", - ast.Long(42).Equals(ast.Long(43)), + ast.Long(42).Equal(ast.Long(43)), types.False, testutil.OK, }, { "notEquals", - ast.Long(42).NotEquals(ast.Long(43)), + ast.Long(42).NotEqual(ast.Long(43)), types.True, testutil.OK, }, diff --git a/internal/json/json_test.go b/internal/json/json_test.go index 65715d12..a8442584 100644 --- a/internal/json/json_test.go +++ b/internal/json/json_test.go @@ -81,7 +81,7 @@ func TestUnmarshalJSON(t *testing.T) { ActionEq(types.NewEntityUID("Action", "view")). ResourceIn(types.NewEntityUID("Folder", "abc")). When( - ast.Context().Access("tls_version").Equals(ast.String("1.3")), + ast.Context().Access("tls_version").Equal(ast.String("1.3")), ), testutil.OK, }, @@ -265,14 +265,14 @@ func TestUnmarshalJSON(t *testing.T) { "equals", `{"effect":"permit","principal":{"op":"All"},"action":{"op":"All"},"resource":{"op":"All"}, "conditions":[{"kind":"when","body":{"==":{"left":{"Value":42},"right":{"Value":24}}}}]}`, - ast.Permit().When(ast.Long(42).Equals(ast.Long(24))), + ast.Permit().When(ast.Long(42).Equal(ast.Long(24))), testutil.OK, }, { "notEquals", `{"effect":"permit","principal":{"op":"All"},"action":{"op":"All"},"resource":{"op":"All"}, "conditions":[{"kind":"when","body":{"!=":{"left":{"Value":42},"right":{"Value":24}}}}]}`, - ast.Permit().When(ast.Long(42).NotEquals(ast.Long(24))), + ast.Permit().When(ast.Long(42).NotEqual(ast.Long(24))), testutil.OK, }, { diff --git a/internal/json/json_unmarshal.go b/internal/json/json_unmarshal.go index cfe9f8dc..ef2b2a1e 100644 --- a/internal/json/json_unmarshal.go +++ b/internal/json/json_unmarshal.go @@ -177,9 +177,9 @@ func (j nodeJSON) ToNode() (ast.Node, error) { // Binary operators: ==, !=, in, <, <=, >, >=, &&, ||, +, -, *, contains, containsAll, containsAny case j.Equals != nil: - return j.Equals.ToNode(ast.Node.Equals) + return j.Equals.ToNode(ast.Node.Equal) case j.NotEquals != nil: - return j.NotEquals.ToNode(ast.Node.NotEquals) + return j.NotEquals.ToNode(ast.Node.NotEqual) case j.In != nil: return j.In.ToNode(ast.Node.In) case j.LessThan != nil: diff --git a/internal/parser/cedar_marshal.go b/internal/parser/cedar_marshal.go index 95383f53..bde5a4d3 100644 --- a/internal/parser/cedar_marshal.go +++ b/internal/parser/cedar_marshal.go @@ -34,7 +34,7 @@ func scopeToNode(varNode ast.NodeTypeVariable, in ast.IsScopeNode) ast.Node { case ast.ScopeTypeAll: return ast.True() case ast.ScopeTypeEq: - return ast.NewNode(varNode).Equals(ast.Value(t.Entity)) + return ast.NewNode(varNode).Equal(ast.Value(t.Entity)) case ast.ScopeTypeIn: return ast.NewNode(varNode).In(ast.Value(t.Entity)) case ast.ScopeTypeInSet: diff --git a/internal/parser/cedar_unmarshal.go b/internal/parser/cedar_unmarshal.go index f7fd4f2c..933a6c00 100644 --- a/internal/parser/cedar_unmarshal.go +++ b/internal/parser/cedar_unmarshal.go @@ -517,9 +517,9 @@ func (p *parser) relation() (ast.Node, error) { case ">=": operator = ast.Node.GreaterThanOrEqual case "!=": - operator = ast.Node.NotEquals + operator = ast.Node.NotEqual case "==": - operator = ast.Node.Equals + operator = ast.Node.Equal case "in": operator = ast.Node.In default: diff --git a/internal/parser/cedar_unmarshal_test.go b/internal/parser/cedar_unmarshal_test.go index 3b569421..98e975ea 100644 --- a/internal/parser/cedar_unmarshal_test.go +++ b/internal/parser/cedar_unmarshal_test.go @@ -257,13 +257,13 @@ when { 2 >= 42 };`, "equal", `permit ( principal, action, resource ) when { 2 == 42 };`, - ast.Permit().When(ast.Long(2).Equals(ast.Long(42))), + ast.Permit().When(ast.Long(2).Equal(ast.Long(42))), }, { "not equal", `permit ( principal, action, resource ) when { 2 != 42 };`, - ast.Permit().When(ast.Long(2).NotEquals(ast.Long(42))), + ast.Permit().When(ast.Long(2).NotEqual(ast.Long(42))), }, { "in", @@ -349,7 +349,7 @@ when { if true then true else false };`, `permit ( principal, action, resource ) when { ip("1.2.3.4") == ip("2.3.4.5") };`, ast.Permit().When( - ast.ExtensionCall("ip", ast.String("1.2.3.4")).Equals( + ast.ExtensionCall("ip", ast.String("1.2.3.4")).Equal( ast.ExtensionCall("ip", ast.String("2.3.4.5")), ), ), @@ -359,7 +359,7 @@ when { ip("1.2.3.4") == ip("2.3.4.5") };`, `permit ( principal, action, resource ) when { decimal("12.34") == decimal("23.45") };`, ast.Permit().When( - ast.ExtensionCall("decimal", ast.String("12.34")).Equals(ast.ExtensionCall("decimal", ast.String("23.45"))), + ast.ExtensionCall("decimal", ast.String("12.34")).Equal(ast.ExtensionCall("decimal", ast.String("23.45"))), ), }, { @@ -384,19 +384,19 @@ when { 1 + 1 < 3 };`, "mult over add precedence (rhs add)", `permit ( principal, action, resource ) when { 2 * 3 + 4 == 10 };`, - ast.Permit().When(ast.Long(2).Multiply(ast.Long(3)).Add(ast.Long(4)).Equals(ast.Long(10))), + ast.Permit().When(ast.Long(2).Multiply(ast.Long(3)).Add(ast.Long(4)).Equal(ast.Long(10))), }, { "mult over add precedence (lhs add)", `permit ( principal, action, resource ) when { 2 + 3 * 4 == 14 };`, - ast.Permit().When(ast.Long(2).Add(ast.Long(3).Multiply(ast.Long(4))).Equals(ast.Long(14))), + ast.Permit().When(ast.Long(2).Add(ast.Long(3).Multiply(ast.Long(4))).Equal(ast.Long(14))), }, { "unary over mult precedence", `permit ( principal, action, resource ) when { -2 * 3 == -6 };`, - ast.Permit().When(ast.Long(-2).Multiply(ast.Long(3)).Equals(ast.Long(-6))), + ast.Permit().When(ast.Long(-2).Multiply(ast.Long(3)).Equal(ast.Long(-6))), }, { "member over unary precedence", @@ -408,25 +408,25 @@ when { -context.num };`, "parens over unary precedence", `permit ( principal, action, resource ) when { -(2 + 3) == -5 };`, - ast.Permit().When(ast.Negate(ast.Long(2).Add(ast.Long(3))).Equals(ast.Long(-5))), + ast.Permit().When(ast.Negate(ast.Long(2).Add(ast.Long(3))).Equal(ast.Long(-5))), }, { "multiple parenthesized operations", `permit ( principal, action, resource ) when { (2 + 3 + 4) * 5 == 18 };`, - ast.Permit().When(ast.Long(2).Add(ast.Long(3)).Add(ast.Long(4)).Multiply(ast.Long(5)).Equals(ast.Long(18))), + ast.Permit().When(ast.Long(2).Add(ast.Long(3)).Add(ast.Long(4)).Multiply(ast.Long(5)).Equal(ast.Long(18))), }, { "parenthesized if", `permit ( principal, action, resource ) when { (if true then 2 else 3 * 4) == 2 };`, - ast.Permit().When(ast.IfThenElse(ast.True(), ast.Long(2), ast.Long(3).Multiply(ast.Long(4))).Equals(ast.Long(2))), + ast.Permit().When(ast.IfThenElse(ast.True(), ast.Long(2), ast.Long(3).Multiply(ast.Long(4))).Equal(ast.Long(2))), }, { "parenthesized if with trailing mult", `permit ( principal, action, resource ) when { (if true then 2 else 3) * 4 == 8 };`, - ast.Permit().When(ast.IfThenElse(ast.True(), ast.Long(2), ast.Long(3)).Multiply(ast.Long(4)).Equals(ast.Long(8))), + ast.Permit().When(ast.IfThenElse(ast.True(), ast.Long(2), ast.Long(3)).Multiply(ast.Long(4)).Equal(ast.Long(8))), }, } diff --git a/policy_test.go b/policy_test.go index 36e8845a..4f1e9b21 100644 --- a/policy_test.go +++ b/policy_test.go @@ -90,7 +90,7 @@ func TestPolicyAST(t *testing.T) { astExample := ast.Permit(). ActionEq(types.NewEntityUID("Action", "editPhoto")). - When(ast.Resource().Access("owner").Equals(ast.Principal())) + When(ast.Resource().Access("owner").Equal(ast.Principal())) _ = cedar.NewPolicyFromAST(astExample) }