Skip to content

Commit

Permalink
chore: rename methods for clarity and improve godocs of model graph (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
miparnisari authored Jan 8, 2025
2 parents 9688431 + 5c1850e commit fda1cab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 2 additions & 4 deletions pkg/go/graph/weighted_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func (wg *WeightedAuthorizationModelGraph) GetEdges() map[string][]*WeightedAuth
return wg.edges
}

// GetEdges returns the edges map.
func (wg *WeightedAuthorizationModelGraph) GetEdgesByNode(node *WeightedAuthorizationModelNode) ([]*WeightedAuthorizationModelEdge, bool) {
func (wg *WeightedAuthorizationModelGraph) GetEdgesFromNode(node *WeightedAuthorizationModelNode) ([]*WeightedAuthorizationModelEdge, bool) {
v, ok := wg.edges[node.uniqueLabel]
return v, ok
}
Expand All @@ -36,7 +35,6 @@ func (wg *WeightedAuthorizationModelGraph) GetNodes() map[string]*WeightedAuthor
return wg.nodes
}

// GetNodes returns the nodes map.
func (wg *WeightedAuthorizationModelGraph) GetNodeByID(uniqueLabel string) (*WeightedAuthorizationModelNode, bool) {
v, ok := wg.nodes[uniqueLabel]
return v, ok
Expand All @@ -50,7 +48,7 @@ func NewWeightedAuthorizationModelGraph() *WeightedAuthorizationModelGraph {
}
}

// AddNode adds a node to the graph with optional operationType and weight.
// AddNode adds a node to the graph with optional nodeType and weight.
func (wg *WeightedAuthorizationModelGraph) AddNode(uniqueLabel, label string, nodeType NodeType) {
wildcards := make([]string, 0)
if nodeType == SpecificTypeWildcard {
Expand Down
8 changes: 4 additions & 4 deletions pkg/go/graph/weighted_graph_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ type WeightedAuthorizationModelEdge struct {
conditionedOn string
from *WeightedAuthorizationModelNode
to *WeightedAuthorizationModelNode
wildcards []string
wildcards []string // e.g. "user". This means that in the direction of this edge there is a path to node user:*
}

// GetWeights returns the entire weights map.
func (edge *WeightedAuthorizationModelEdge) GetWeights() map[string]int {
return edge.weights
}

// GetWeight returns the weight for a specific key.
// GetWeight returns the weight for a specific type. It can return Infinite to indicate recursion.
func (edge *WeightedAuthorizationModelEdge) GetWeight(key string) (int, bool) {
weight, exists := edge.weights[key]
return weight, exists
Expand All @@ -25,7 +25,7 @@ func (edge *WeightedAuthorizationModelEdge) GetEdgeType() EdgeType {
return edge.edgeType
}

// GetConditionedOn returns the conditionedOn field.
// GetConditionedOn returns the conditionedOn field, e.g. "document#parent".
func (edge *WeightedAuthorizationModelEdge) GetConditionedOn() string {
return edge.conditionedOn
}
Expand All @@ -40,7 +40,7 @@ func (edge *WeightedAuthorizationModelEdge) GetTo() *WeightedAuthorizationModelN
return edge.to
}

// GetWildcards returns the wildcards.
// GetWildcards returns an array of types, e.g. "user". This means that in the direction of this edge there is a path to node user:*
func (edge *WeightedAuthorizationModelEdge) GetWildcards() []string {
return edge.wildcards
}
15 changes: 8 additions & 7 deletions pkg/go/graph/weighted_graph_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package graph
type WeightedAuthorizationModelNode struct {
weights map[string]int
nodeType NodeType
label string // e.g. "group#member", UnionOperator, IntersectionOperator, ExclusionOperator
uniqueLabel string
wildcards []string
label string // e.g. "group#member", UnionOperator, IntersectionOperator, ExclusionOperator
uniqueLabel string // e.g. "group#member", or "union:01JH0MR4H1MBFGVN37E4PRMPM3"
wildcards []string // e.g. "user". This means that from this node there is a path to node user:*
}

// GetWeights returns the entire weights map.
func (node *WeightedAuthorizationModelNode) GetWeights() map[string]int {
return node.weights
}

// GetWeight returns the weight for a specific key.
// GetWeight returns the weight for a specific type. It can return Infinite to indicate recursion.
func (node *WeightedAuthorizationModelNode) GetWeight(key string) (int, bool) {
weight, exists := node.weights[key]
return weight, exists
Expand All @@ -24,17 +24,18 @@ func (node *WeightedAuthorizationModelNode) GetNodeType() NodeType {
return node.nodeType
}

// GetLabel returns the label.
// GetLabel returns the label, e.g. "user", "group#member", UnionOperator, IntersectionOperator or ExclusionOperator.
func (node *WeightedAuthorizationModelNode) GetLabel() string {
return node.label
}

// GetUniqueLabel returns the unique label.
// GetUniqueLabel returns the unique label. It is the same as GetLabel, except for operation nodes,
// where it takes the form "operation:ULID".
func (node *WeightedAuthorizationModelNode) GetUniqueLabel() string {
return node.uniqueLabel
}

// GetWildcards returns the wildcards.
// GetWildcards returns an array of types, e.g. "user". This means that from this node there is a path to node user:*
func (node *WeightedAuthorizationModelNode) GetWildcards() []string {
return node.wildcards
}

0 comments on commit fda1cab

Please sign in to comment.