From 3097a74b45f476f7dfcc4ac71475fdc02aed9abf Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Tue, 7 Jan 2025 12:08:34 -0300 Subject: [PATCH 1/2] chore: improve godocs of model graph --- pkg/go/graph/weighted_graph.go | 6 ++---- pkg/go/graph/weighted_graph_edge.go | 6 +++--- pkg/go/graph/weighted_graph_node.go | 15 ++++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/go/graph/weighted_graph.go b/pkg/go/graph/weighted_graph.go index 27954f74..5f8a9285 100644 --- a/pkg/go/graph/weighted_graph.go +++ b/pkg/go/graph/weighted_graph.go @@ -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 } @@ -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 @@ -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 { diff --git a/pkg/go/graph/weighted_graph_edge.go b/pkg/go/graph/weighted_graph_edge.go index 065601e6..1682eea2 100644 --- a/pkg/go/graph/weighted_graph_edge.go +++ b/pkg/go/graph/weighted_graph_edge.go @@ -14,7 +14,7 @@ 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 @@ -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 } @@ -40,7 +40,7 @@ func (edge *WeightedAuthorizationModelEdge) GetTo() *WeightedAuthorizationModelN return edge.to } -// GetWildcards returns the wildcards. +// GetWildcards returns an array of types. func (edge *WeightedAuthorizationModelEdge) GetWildcards() []string { return edge.wildcards } diff --git a/pkg/go/graph/weighted_graph_node.go b/pkg/go/graph/weighted_graph_node.go index 8df4d436..08cef4b8 100644 --- a/pkg/go/graph/weighted_graph_node.go +++ b/pkg/go/graph/weighted_graph_node.go @@ -3,9 +3,9 @@ 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" } // GetWeights returns the entire weights map. @@ -13,7 +13,7 @@ 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 @@ -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. func (node *WeightedAuthorizationModelNode) GetWildcards() []string { return node.wildcards } From 5c1850e45df34ce793c002c6ce69f501127c9c04 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Tue, 7 Jan 2025 12:42:06 -0300 Subject: [PATCH 2/2] improve wildcard godoc --- pkg/go/graph/weighted_graph_edge.go | 4 ++-- pkg/go/graph/weighted_graph_node.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/go/graph/weighted_graph_edge.go b/pkg/go/graph/weighted_graph_edge.go index 1682eea2..28da3664 100644 --- a/pkg/go/graph/weighted_graph_edge.go +++ b/pkg/go/graph/weighted_graph_edge.go @@ -6,7 +6,7 @@ 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. @@ -40,7 +40,7 @@ func (edge *WeightedAuthorizationModelEdge) GetTo() *WeightedAuthorizationModelN return edge.to } -// GetWildcards returns an array of types. +// 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 } diff --git a/pkg/go/graph/weighted_graph_node.go b/pkg/go/graph/weighted_graph_node.go index 08cef4b8..b9ebab08 100644 --- a/pkg/go/graph/weighted_graph_node.go +++ b/pkg/go/graph/weighted_graph_node.go @@ -5,7 +5,7 @@ type WeightedAuthorizationModelNode struct { nodeType NodeType label string // e.g. "group#member", UnionOperator, IntersectionOperator, ExclusionOperator uniqueLabel string // e.g. "group#member", or "union:01JH0MR4H1MBFGVN37E4PRMPM3" - wildcards []string // e.g. "user" + wildcards []string // e.g. "user". This means that from this node there is a path to node user:* } // GetWeights returns the entire weights map. @@ -35,7 +35,7 @@ func (node *WeightedAuthorizationModelNode) GetUniqueLabel() string { return node.uniqueLabel } -// GetWildcards returns an array of types. +// 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 }