expand

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 9 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:"edge_id"`
	SourceID        int      `json:"source_id"`
	DestinationID   int      `json:"destination_id"`
	IsExpanded      bool     `json:"expanded"`
	IsShallow       bool     `json:"shallow"`
	ResourceTypeIDs []string `json:"resource_type_ids"`
}

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"`
}

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.

type EntitlementGraphAction

type EntitlementGraphAction struct {
	SourceEntitlementID     string   `json:"source_entitlement_id"`
	DescendantEntitlementID string   `json:"descendant_entitlement_id"`
	Shallow                 bool     `json:"shallow"`
	ResourceTypeIDs         []string `json:"resource_types_ids"`
	PageToken               string   `json:"page_token"`
}

type Node

type Node struct {
	Id             int      `json:"id"`
	EntitlementIDs []string `json:"entitlementIds"` // 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

Jump to

Keyboard shortcuts

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