Documentation ¶
Index ¶
- Variables
- type Edge
- type EntitlementGraph
- func (g *EntitlementGraph) AddEdge(ctx context.Context, srcEntitlementID string, dstEntitlementID string, ...) error
- func (g *EntitlementGraph) AddEntitlement(entitlement *v2.Entitlement)
- func (g *EntitlementGraph) FixCycles() error
- func (g *EntitlementGraph) GetDescendantEntitlements(entitlementID string) map[string]*Edge
- func (g *EntitlementGraph) GetEntitlements() []string
- func (g *EntitlementGraph) GetFirstCycle() []int
- func (g *EntitlementGraph) GetNode(entitlementID string) *Node
- func (g *EntitlementGraph) HasEntitlement(entitlementID string) bool
- func (g *EntitlementGraph) HasUnexpandedAncestors(entitlementID string) bool
- func (g *EntitlementGraph) IsEntitlementExpanded(entitlementID string) bool
- func (g *EntitlementGraph) IsExpanded() bool
- func (g *EntitlementGraph) MarkEdgeExpanded(sourceEntitlementID string, descendantEntitlementID string)
- func (g *EntitlementGraph) Str() string
- func (g *EntitlementGraph) Validate() error
- type EntitlementGraphAction
- type Node
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoEntitlement = errors.New("no entitlement found")
)
Functions ¶
This section is empty.
Types ¶
type Edge ¶
type EntitlementGraph ¶
type EntitlementGraph struct { NextNodeID int `json:"next_node_id"` // Automatically incremented so that each node has a unique ID. NextEdgeID int `json:"next_edge_id"` // Automatically incremented so that each edge has a unique ID. Nodes map[int]Node `json:"nodes"` // The mapping of all node IDs to nodes. EntitlementsToNodes map[string]int `json:"entitlements_to_nodes"` // Internal mapping of entitlements to nodes for quicker lookup. SourcesToDestinations map[int]map[int]int `json:"sources_to_destinations"` // Internal mapping of outgoing edges by node ID. DestinationsToSources map[int]map[int]int `json:"destinations_to_sources"` // Internal mapping of incoming edges by node ID. Edges map[int]Edge `json:"edges"` // Adjacency list. Source node -> descendant node Loaded bool `json:"loaded"` Depth int `json:"depth"` Actions []*EntitlementGraphAction `json:"actions"` HasNoCycles bool `json:"has_no_cycles"` }
EntitlementGraph - a directed graph representing the relationships between entitlements and grants. This data structure is naïve to any business logic. Note that the data of each Node is actually a list or IDs, not a single ID. This is because the graph can have cycles, and we address them by reducing _all_ nodes in a cycle into a single node.
func NewEntitlementGraph ¶
func NewEntitlementGraph(_ context.Context) *EntitlementGraph
func (*EntitlementGraph) AddEdge ¶
func (g *EntitlementGraph) AddEdge( ctx context.Context, srcEntitlementID string, dstEntitlementID string, isShallow bool, resourceTypeIDs []string, ) error
AddEdge - given two entitlements, add an edge with resourceTypeIDs.
func (*EntitlementGraph) AddEntitlement ¶
func (g *EntitlementGraph) AddEntitlement(entitlement *v2.Entitlement)
AddEntitlement - add an entitlement's ID as an unconnected node in the graph.
func (*EntitlementGraph) FixCycles ¶
func (g *EntitlementGraph) FixCycles() error
FixCycles if any cycles of nodes exist, merge all nodes in that cycle into a single node and then repeat. Iteration ends when there are no more cycles.
func (*EntitlementGraph) GetDescendantEntitlements ¶
func (g *EntitlementGraph) GetDescendantEntitlements(entitlementID string) map[string]*Edge
GetDescendantEntitlements given an entitlementID, return a mapping of child entitlementIDs to edge data.
func (*EntitlementGraph) GetEntitlements ¶
func (g *EntitlementGraph) GetEntitlements() []string
GetEntitlements returns a combined list of _all_ entitlements from all nodes.
func (*EntitlementGraph) GetFirstCycle ¶ added in v0.2.0
func (g *EntitlementGraph) GetFirstCycle() []int
GetFirstCycle given an entitlements graph, return a cycle by node ID if it exists. Returns nil if no cycle exists. If there is a single node pointing to itself, that will count as a cycle.
func (*EntitlementGraph) GetNode ¶
func (g *EntitlementGraph) GetNode(entitlementID string) *Node
GetNode - returns the node that contains the given `entitlementID`.
func (*EntitlementGraph) HasEntitlement ¶
func (g *EntitlementGraph) HasEntitlement(entitlementID string) bool
func (*EntitlementGraph) HasUnexpandedAncestors ¶
func (g *EntitlementGraph) HasUnexpandedAncestors(entitlementID string) bool
HasUnexpandedAncestors returns true if the given entitlement has ancestors that have not been expanded yet.
func (*EntitlementGraph) IsEntitlementExpanded ¶
func (g *EntitlementGraph) IsEntitlementExpanded(entitlementID string) bool
IsEntitlementExpanded returns true if all the outgoing edges for the given entitlement have been expanded.
func (*EntitlementGraph) IsExpanded ¶
func (g *EntitlementGraph) IsExpanded() bool
IsExpanded returns true if all entitlements in the graph have been expanded.
func (*EntitlementGraph) MarkEdgeExpanded ¶
func (g *EntitlementGraph) MarkEdgeExpanded(sourceEntitlementID string, descendantEntitlementID string)
MarkEdgeExpanded given source and destination entitlements, mark the edge between them as "expanded".
func (*EntitlementGraph) Str ¶
func (g *EntitlementGraph) Str() string
Str lists every `node` line by line followed by every `edge`. Useful for debugging.
func (*EntitlementGraph) Validate ¶
func (g *EntitlementGraph) Validate() error
Validate checks every node and edge and returns an error if the graph is not valid.