expand

package
v0.4.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEntitlement = errors.New("no entitlement found")
)

Functions

This section is empty.

Types

type Edge

type Edge struct {
	EdgeID          int      `json:"id"`
	SourceID        int      `json:"sid"`
	DestinationID   int      `json:"did"`
	IsExpanded      bool     `json:"e"`
	IsShallow       bool     `json:"s"`
	ResourceTypeIDs []string `json:"rtids"`
}

func (*Edge) Str

func (edge *Edge) Str() string

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) ComputeCyclicComponents added in v0.3.49

func (g *EntitlementGraph) ComputeCyclicComponents(ctx context.Context) ([][]int, *scc.Metrics)

ComputeCyclicComponents runs SCC once and returns only cyclic components. A component is cyclic if len>1 or a singleton with a self-loop.

func (*EntitlementGraph) DeleteEdge added in v0.2.64

func (g *EntitlementGraph) DeleteEdge(ctx context.Context, srcEntitlementID string, dstEntitlementID string) error

func (*EntitlementGraph) FixCycles

func (g *EntitlementGraph) FixCycles(ctx context.Context) error

func (*EntitlementGraph) FixCyclesFromComponents added in v0.3.49

func (g *EntitlementGraph) FixCyclesFromComponents(ctx context.Context, cyclic [][]int) error

FixCyclesFromComponents merges all provided cyclic components in one pass.

func (*EntitlementGraph) ForEachEdgeFrom added in v0.3.51

func (g *EntitlementGraph) ForEachEdgeFrom(src int, fn func(dst int) bool)

ForEachEdgeFrom implements scc.Source iteration of outgoing edges for src. It enumerates unique destination node IDs.

func (*EntitlementGraph) ForEachNode added in v0.3.51

func (g *EntitlementGraph) ForEachNode(fn func(id int) bool)

ForEachNode implements scc.Source iteration over nodes (including isolated nodes). It does not import scc; matching the method names/signatures is sufficient.

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(ctx context.Context) []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) HasCycles added in v0.3.49

func (g *EntitlementGraph) HasCycles(ctx context.Context) bool

HasCycles returns true if the graph contains any cycle.

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.

type EntitlementGraphAction

type EntitlementGraphAction struct {
	SourceEntitlementID     string   `json:"sid"`
	DescendantEntitlementID string   `json:"did"`
	Shallow                 bool     `json:"s"`
	ResourceTypeIDs         []string `json:"rtids"`
	PageToken               string   `json:"pt"`
}

type Node

type Node struct {
	Id             int      `json:"id"`
	EntitlementIDs []string `json:"eids"` // List of entitlements.
}

Node represents a list of entitlements. It is the base element of the graph.

func (*Node) Str

func (node *Node) Str() string

Directories

Path Synopsis
Package scc provides an iterative FW–BW SCC condensation for directed graphs, adapted for Baton’s entitlement graph.
Package scc provides an iterative FW–BW SCC condensation for directed graphs, adapted for Baton’s entitlement graph.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL