graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package graph provides utilities for querying the code knowledge graph.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterEdges

func FilterEdges(edges []*graph.Edge, filter EdgeFilter) []*graph.Edge

FilterEdges filters a slice of edges.

func FilterNodes

func FilterNodes(nodes []*graph.Node, filter NodeFilter) []*graph.Node

FilterNodes filters a slice of nodes.

Types

type AttackPath

type AttackPath struct {
	// FromID is the starting node.
	FromID string `json:"from_id"`

	// ToID is the ending node.
	ToID string `json:"to_id"`

	// Nodes are the node IDs in the path.
	Nodes []string `json:"nodes"`

	// Edges are the edges traversed.
	Edges []*graph.Edge `json:"edges"`

	// Depth is the number of hops.
	Depth int `json:"depth"`

	// EdgeTypes used in the query.
	EdgeTypes []string `json:"edge_types,omitempty"`
}

AttackPath represents a path from entry point to vulnerable code.

func (*AttackPath) String

func (p *AttackPath) String() string

String returns a human-readable representation.

type EdgeFilter

type EdgeFilter func(*graph.Edge) bool

EdgeFilter is a predicate for filtering edges.

func EdgeByType

func EdgeByType(edgeType string) EdgeFilter

EdgeByType returns a filter for edges of a specific type.

func EdgeByTypes

func EdgeByTypes(types ...string) EdgeFilter

EdgeByTypes returns a filter for edges of any of the specified types.

func EdgeFrom

func EdgeFrom(nodeID string) EdgeFilter

EdgeFrom returns a filter for edges from a specific node.

func EdgeTo

func EdgeTo(nodeID string) EdgeFilter

EdgeTo returns a filter for edges to a specific node.

type NodeFilter

type NodeFilter func(*graph.Node) bool

NodeFilter is a predicate for filtering nodes.

func And

func And(filters ...NodeFilter) NodeFilter

And combines filters with AND logic.

func AttrContains

func AttrContains(key, substring string) NodeFilter

AttrContains returns a filter for nodes where an attribute contains a substring.

func ByAttr

func ByAttr(key, value string) NodeFilter

ByAttr returns a filter for nodes with a specific attribute value.

func ByType

func ByType(nodeType string) NodeFilter

ByType returns a filter for nodes of a specific type.

func ByTypes

func ByTypes(types ...string) NodeFilter

ByTypes returns a filter for nodes of any of the specified types.

func HasAttr

func HasAttr(key string) NodeFilter

HasAttr returns a filter for nodes that have a specific attribute.

func IDContains

func IDContains(substring string) NodeFilter

IDContains returns a filter for nodes whose ID contains a substring.

func IsAPIEndpoint

func IsAPIEndpoint() NodeFilter

IsAPIEndpoint returns a filter for API endpoint nodes.

func IsAuthRelated

func IsAuthRelated() NodeFilter

IsAuthRelated returns a filter for authentication-related nodes.

func IsEntryPoint

func IsEntryPoint() NodeFilter

IsEntryPoint returns a filter for entry point nodes.

func IsFunction

func IsFunction() NodeFilter

IsFunction returns a filter for function nodes.

func IsPackage

func IsPackage() NodeFilter

IsPackage returns a filter for package nodes.

func IsPublic

func IsPublic() NodeFilter

IsPublic returns a filter for public nodes.

func LabelContains

func LabelContains(substring string) NodeFilter

LabelContains returns a filter for nodes whose label contains a substring.

func Not

func Not(filter NodeFilter) NodeFilter

Not negates a filter.

func Or

func Or(filters ...NodeFilter) NodeFilter

Or combines filters with OR logic.

func RequiresAuth

func RequiresAuth() NodeFilter

RequiresAuth returns a filter for nodes that require authentication.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query wraps graphfs traversal with security-focused utilities.

func NewQuery

func NewQuery(g *graph.Graph) *Query

NewQuery creates a new query wrapper.

func (*Query) CanReachFromAPI

func (q *Query) CanReachFromAPI(targetID string) (*AttackPath, bool)

CanReachFromAPI checks if target is reachable from any API endpoint.

func (*Query) CanReachFromEntryPoint

func (q *Query) CanReachFromEntryPoint(targetID string) (*AttackPath, bool)

CanReachFromEntryPoint checks if target is reachable from any entry point.

func (*Query) FindAPIEndpoints

func (q *Query) FindAPIEndpoints() []*graph.Node

FindAPIEndpoints returns all API endpoint nodes.

func (*Query) FindAllPaths

func (q *Query) FindAllPaths(sourceID string, targetIDs []string, edgeTypes []string, maxDepth int) []*AttackPath

FindAllPaths finds all paths from source to any of the targets.

func (*Query) FindEntryPoints

func (q *Query) FindEntryPoints() []*graph.Node

FindEntryPoints returns all nodes that are entry points.

func (*Query) FindFunctionNodes

func (q *Query) FindFunctionNodes() []*graph.Node

FindFunctionNodes returns all function/method nodes.

func (*Query) FindPackageNodes

func (q *Query) FindPackageNodes() []*graph.Node

FindPackageNodes returns all package nodes.

func (*Query) FindPath

func (q *Query) FindPath(fromID, toID string, edgeTypes []string) *AttackPath

FindPath finds the shortest path between two nodes.

func (*Query) GetDependencyDepth

func (q *Query) GetDependencyDepth(packageID string) int

GetDependencyDepth returns the depth of a package from the root. Returns -1 if not found.

func (*Query) Graph

func (q *Query) Graph() *graph.Graph

Graph returns the underlying graph.

func (*Query) HasNode

func (q *Query) HasNode(id string) bool

HasNode checks if a node exists.

func (*Query) HasPackage

func (q *Query) HasPackage(packageName string) bool

HasPackage checks if a package exists in the graph.

func (*Query) IsReachable

func (q *Query) IsReachable(sourceID, targetID string, edgeTypes []string) bool

IsReachable checks if target is reachable from source.

func (*Query) NodeByID

func (q *Query) NodeByID(id string) *graph.Node

NodeByID returns a node by ID.

func (*Query) NodesByIDs

func (q *Query) NodesByIDs(ids []string) []*graph.Node

NodesByIDs returns nodes by IDs.

func (*Query) NodesWhere

func (q *Query) NodesWhere(predicate func(*graph.Node) bool) []*graph.Node

NodesWhere returns nodes matching the predicate.

func (*Query) Traverser

func (q *Query) Traverser() *query.Traverser

Traverser returns the underlying traverser.

Jump to

Keyboard shortcuts

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