Documentation
¶
Overview ¶
Package graph is the node and edge model every connector writes into and every fact reads from.
Index ¶
- Constants
- func Compact(dir string, now time.Time) (int, error)
- func SnapshotFiles(dir string) ([]string, error)
- func WriteScan(w Writer, source, scanner, scope string, inspected int, partial string, ...)
- func WriteSnapshot(dir string, s Snapshot) (string, error)
- type Edge
- type Estate
- type EstateItem
- type Graph
- type Hasher
- type ID
- type Node
- type Reader
- type Snapshot
- type Writer
Constants ¶
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.
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.
const CompactedName = "0000-compacted.json.gz"
CompactedName holds snapshots older than a year. It sorts first, so it merges before anything newer.
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 ¶
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 ¶
SnapshotFiles lists snapshot files under dir, oldest first.
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 RebuildEstate ¶
RebuildEstate merges the compacted snapshot, then every snapshot newer than a year ago, oldest first.
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.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher turns secrets and emails into stable HMACs using the org's salt.
func (Hasher) Fingerprint ¶
Fingerprint is a short value that identifies the salt without revealing it.
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.
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 ¶
ReadSnapshot loads one snapshot file.