feat(go): enrich snapshots with package ownership
This commit is contained in:
parent
6355fb403d
commit
88d7a6e3b8
8 changed files with 149 additions and 54 deletions
|
|
@ -47,17 +47,23 @@ type SlowResult struct {
|
|||
Files map[string]map[string]any
|
||||
}
|
||||
|
||||
func CollectSlow(processes []Process, paths []string) SlowResult {
|
||||
func CollectSlow(processes []Process, paths []string, owner ...func(string) string) SlowResult {
|
||||
result := SlowResult{Processes: map[int]map[string]any{}, Files: map[string]map[string]any{}}
|
||||
packageOwner := func(string) string { return "" }
|
||||
if len(owner) > 0 && owner[0] != nil {
|
||||
packageOwner = owner[0]
|
||||
}
|
||||
for _, process := range processes {
|
||||
exe := cleanPath(process.Exe)
|
||||
if exe == "" {
|
||||
continue
|
||||
}
|
||||
result.Processes[process.PID] = map[string]any{"exe_sha256": boundedHash(exe)}
|
||||
result.Processes[process.PID] = map[string]any{"exe_sha256": boundedHash(exe), "package_owner": packageOwner(exe)}
|
||||
}
|
||||
for _, path := range paths {
|
||||
result.Files[path] = fileMetadata(path)
|
||||
metadata := fileMetadata(path)
|
||||
metadata["package_owner"] = packageOwner(path)
|
||||
result.Files[path] = metadata
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue