Documentation
¶
Overview ¶
Package graph provides utilities for querying the code knowledge graph.
Index ¶
- func FilterEdges(edges []*graph.Edge, filter EdgeFilter) []*graph.Edge
- func FilterNodes(nodes []*graph.Node, filter NodeFilter) []*graph.Node
- type AttackPath
- type EdgeFilter
- type NodeFilter
- func And(filters ...NodeFilter) NodeFilter
- func AttrContains(key, substring string) NodeFilter
- func ByAttr(key, value string) NodeFilter
- func ByType(nodeType string) NodeFilter
- func ByTypes(types ...string) NodeFilter
- func HasAttr(key string) NodeFilter
- func IDContains(substring string) NodeFilter
- func IsAPIEndpoint() NodeFilter
- func IsAuthRelated() NodeFilter
- func IsEntryPoint() NodeFilter
- func IsFunction() NodeFilter
- func IsPackage() NodeFilter
- func IsPublic() NodeFilter
- func LabelContains(substring string) NodeFilter
- func Not(filter NodeFilter) NodeFilter
- func Or(filters ...NodeFilter) NodeFilter
- func RequiresAuth() NodeFilter
- type Query
- func (q *Query) CanReachFromAPI(targetID string) (*AttackPath, bool)
- func (q *Query) CanReachFromEntryPoint(targetID string) (*AttackPath, bool)
- func (q *Query) FindAPIEndpoints() []*graph.Node
- func (q *Query) FindAllPaths(sourceID string, targetIDs []string, edgeTypes []string, maxDepth int) []*AttackPath
- func (q *Query) FindEntryPoints() []*graph.Node
- func (q *Query) FindFunctionNodes() []*graph.Node
- func (q *Query) FindPackageNodes() []*graph.Node
- func (q *Query) FindPath(fromID, toID string, edgeTypes []string) *AttackPath
- func (q *Query) GetDependencyDepth(packageID string) int
- func (q *Query) Graph() *graph.Graph
- func (q *Query) HasNode(id string) bool
- func (q *Query) HasPackage(packageName string) bool
- func (q *Query) IsReachable(sourceID, targetID string, edgeTypes []string) bool
- func (q *Query) NodeByID(id string) *graph.Node
- func (q *Query) NodesByIDs(ids []string) []*graph.Node
- func (q *Query) NodesWhere(predicate func(*graph.Node) bool) []*graph.Node
- func (q *Query) Traverser() *query.Traverser
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 ¶
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 ¶
NodeFilter is a predicate for filtering nodes.
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 LabelContains ¶
func LabelContains(substring string) NodeFilter
LabelContains returns a filter for nodes whose label contains a substring.
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 (*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 ¶
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 ¶
FindEntryPoints returns all nodes that are entry points.
func (*Query) FindFunctionNodes ¶
FindFunctionNodes returns all function/method nodes.
func (*Query) FindPackageNodes ¶
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 ¶
GetDependencyDepth returns the depth of a package from the root. Returns -1 if not found.
func (*Query) HasPackage ¶
HasPackage checks if a package exists in the graph.
func (*Query) IsReachable ¶
IsReachable checks if target is reachable from source.
func (*Query) NodesByIDs ¶
NodesByIDs returns nodes by IDs.
func (*Query) NodesWhere ¶
NodesWhere returns nodes matching the predicate.