graph

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graph is the node and edge model every connector writes into and every fact reads from.

Index

Constants

View Source
const (
	KindTargetRepo    = "target_repo"
	KindGitHubRepo    = "github_repo"
	KindBranchRule    = "branch_rule"
	KindEnvironment   = "github_environment"
	KindActionsPerms  = "actions_permissions"
	KindIdentityUser  = "identity_user"
	KindPerson        = "person"
	KindAWSPrincipal  = "aws_principal"
	KindAWSKey        = "aws_key"
	KindGCPProject    = "gcp_project"
	KindGCPBinding    = "gcp_iam_binding"
	KindGCPBucket     = "gcp_bucket"
	KindGCPKey        = "gcp_sa_key"
	KindSecret        = "secret"
	KindSecretSeen    = "secret_occurrence"
	KindAgentConfig   = "agent_config"
	KindWorkflow      = "workflow"
	KindTFBucket      = "tf_bucket"
	KindFileDoc       = "file_doc"
	KindCodeowners    = "codeowners"
	KindSemgrep       = "semgrep_finding"
	KindHost          = "host"
	KindCNAME         = "dns_cname"
	KindDNSRecord     = "dns_record"
	KindWebResponse   = "web_response"
	KindSourceMap     = "public_source_map"
	KindAPIDoc        = "public_api_doc"
	KindLeaver        = "hr_leaver"
	KindConfigHost    = "config_host"
	KindConfigDomain  = "config_domain"
	KindScan          = "scan"
	KindConnectorFail = "connector_failure"
)

Node kinds. Facts read these and connectors write them.

View Source
const (
	EdgeMemberOf   = "member_of"
	EdgeAdminOf    = "admin_of"
	EdgeHolds      = "holds"
	EdgeFoundIn    = "found_in"
	EdgeSamePerson = "same_person"
	EdgeOwns       = "owns"
	EdgePointsTo   = "points_to"
	EdgeDeploysTo  = "deploys_to"
)

Edge kinds.

View Source
const CompactedName = "0000-compacted.json.gz"

CompactedName holds snapshots older than a year. It sorts first, so it merges before anything newer.

View Source
const GoneAfter = 3

GoneAfter is how many runs an item may be missing before it is marked gone.

Variables

This section is empty.

Functions

func Compact

func Compact(dir string, now time.Time) (int, error)

Compact folds snapshots older than a year into one, keeping the latest state of each item, then removes the originals. It returns how many it folded.

func SnapshotFiles

func SnapshotFiles(dir string) ([]string, error)

SnapshotFiles lists snapshot files under dir, oldest first.

func WriteScan

func WriteScan(w Writer, source, scanner, scope string, inspected int, partial string, at time.Time)

WriteScan records how many sources a scanner inspected. Partial, when not empty, says what could not be read.

func WriteSnapshot

func WriteSnapshot(dir string, s Snapshot) (string, error)

WriteSnapshot stores a snapshot as compressed JSON under dir.

Types

type Edge

type Edge struct {
	From   ID     `json:"from"`
	To     ID     `json:"to"`
	Kind   string `json:"kind"`
	Source string `json:"source"`
}

Edge links two nodes.

type Estate

type Estate struct {
	Items map[ID]*EstateItem
	Edges map[Edge]struct{}
}

Estate is the graph across runs.

func NewEstate

func NewEstate() *Estate

NewEstate returns an empty estate.

func RebuildEstate

func RebuildEstate(dir string, now time.Time) (*Estate, error)

RebuildEstate merges the compacted snapshot, then every snapshot newer than a year ago, oldest first.

func (*Estate) Merge

func (e *Estate) Merge(s Snapshot)

Merge folds one snapshot in. Snapshots must be merged oldest first.

func (*Estate) Sorted

func (e *Estate) Sorted() []*EstateItem

Sorted returns items in ID order.

type EstateItem

type EstateItem struct {
	ID        ID             `json:"id"`
	Kind      string         `json:"kind"`
	Attrs     map[string]any `json:"attrs,omitempty"`
	FirstSeen time.Time      `json:"first_seen"`
	LastSeen  time.Time      `json:"last_seen"`
	Missed    int            `json:"missed"`
	Gone      bool           `json:"gone"`
}

EstateItem is one thing across runs. Items missing for three runs in a row are marked gone and kept, so history survives.

type Graph

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

Graph is an in-memory graph, safe for concurrent writers.

func New

func New() *Graph

New returns an empty graph.

func (*Graph) Edge

func (g *Graph) Edge(e Edge)

Edge adds an edge.

func (*Graph) Edges

func (g *Graph) Edges(kind string) []Edge

Edges returns the edges of a kind in a stable order, or all edges when kind is empty.

func (*Graph) Get

func (g *Graph) Get(id ID) (Node, bool)

Get returns one node.

func (*Graph) Node

func (g *Graph) Node(n Node)

Node adds or replaces a node.

func (*Graph) Nodes

func (g *Graph) Nodes(kind string) []Node

Nodes returns the nodes of a kind sorted by ID, or all nodes when kind is empty.

type Hasher

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

Hasher turns secrets and emails into stable HMACs using the org's salt.

func NewHasher

func NewHasher(salt string) Hasher

NewHasher returns a Hasher for a salt.

func (Hasher) Email

func (h Hasher) Email(email string) string

Email hashes an email address after normalizing it.

func (Hasher) Fingerprint

func (h Hasher) Fingerprint() string

Fingerprint is a short value that identifies the salt without revealing it.

func (Hasher) Sum

func (h Hasher) Sum(v string) string

Sum returns the hex HMAC-SHA-256 of a value, shortened to 32 characters.

type ID

type ID string

ID is a stable node identifier made from a source system and that system's own identifier, so the same thing gets the same ID on every run.

func ScanID

func ScanID(scanner, scope string) ID

ScanID names the record of what a scanner inspected. Scope is a repo, a domain, or empty for a global scan.

type Node

type Node struct {
	ID      ID             `json:"id"`
	Kind    string         `json:"kind"`
	Attrs   map[string]any `json:"attrs,omitempty"`
	Private map[string]any `json:"-"`
	Source  string         `json:"source"`
	SeenAt  time.Time      `json:"seen_at"`
}

Node is one thing seen in a system. Private attributes live only for the current run and are never written to snapshots.

type Reader

type Reader interface {
	Get(id ID) (Node, bool)
	Nodes(kind string) []Node
	Edges(kind string) []Edge
}

Reader is how facts query the graph.

type Snapshot

type Snapshot struct {
	Time  time.Time `json:"time"`
	Nodes []Node    `json:"nodes"`
	Edges []Edge    `json:"edges"`
}

Snapshot is one run's graph as stored next to its tags. Private attributes never reach it, so emails and raw values stay out of history.

func ReadSnapshot

func ReadSnapshot(path string) (Snapshot, error)

ReadSnapshot loads one snapshot file.

func TakeSnapshot

func TakeSnapshot(g Reader, at time.Time) Snapshot

TakeSnapshot captures a graph.

type Writer

type Writer interface {
	Node(n Node)
	Edge(e Edge)
}

Writer is the only way data enters the graph.

Directories

Path Synopsis
Package pg keeps the estate in Postgres for fast queries.
Package pg keeps the estate in Postgres for fast queries.

Jump to

Keyboard shortcuts

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