Skip to content

Commit

Permalink
chore: introduce constant for operators
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari committed Sep 25, 2024
1 parent 0e33e96 commit 74f8dcb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/go/graph/graph_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ func checkRewrite(graphBuilder *AuthorizationModelGraphBuilder, parentNode *Auth

return
case *openfgav1.Userset_Union:
operator = "union"
operator = UnionOperator
children = rw.Union.GetChild()

case *openfgav1.Userset_Intersection:
operator = "intersection"
operator = IntersectionOperator
children = rw.Intersection.GetChild()

case *openfgav1.Userset_Difference:
operator = "exclusion"
operator = ExclusionOperator
children = []*openfgav1.Userset{
rw.Difference.GetBase(),
rw.Difference.GetSubtract(),
Expand Down
7 changes: 5 additions & 2 deletions pkg/go/graph/graph_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const (
SpecificTypeAndRelation NodeType = 1 // e.g. `group#viewer`
OperatorNode NodeType = 2 // e.g. union
SpecificTypeWildcard NodeType = 3 // e.g. `group:*`

UnionOperator = "union"
IntersectionOperator = "intersection"
ExclusionOperator = "exclusion"
)

type AuthorizationModelNode struct {
graph.Node

// custom attributes
label string // e.g. `union`, for DOT
label string // e.g. "group#member", UnionOperator, IntersectionOperator, ExclusionOperator
nodeType NodeType
uniqueLabel string // e.g. `union:01J54ND7WHGAAJTGDMFWP4FZTR`
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/go/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ func TestGetNodeTypes(t *testing.T) {
}

switch node.label {
case "union":
case UnionOperator:
unionNodes = append(unionNodes, node)
case "intersection":
case IntersectionOperator:
intersectionNodes = append(intersectionNodes, node)
case "exclusion":
case ExclusionOperator:
differenceNodes = append(differenceNodes, node)
}
}
Expand Down

0 comments on commit 74f8dcb

Please sign in to comment.