mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 07:39:19 -05:00
Repositories upload an SBOM of their default branch, for example from
syft in CI, to PUT /api/projects/{project}/sbom. The proxy records the
package versions it lists, keyed by the same unversioned PURL the
handlers record packages under, so the inventory joins with what the
proxy has cached and the vulnerabilities it holds.
That answers which repository uses which version of a package: the new
/ui/projects pages list each project's package versions with outdated
and vulnerability markers, package pages show the projects per version,
the dashboard lists vulnerable versions in use, and
GET /api/projects?purl= does the same for scripts.
The feature is off by default. Uploads and deletes need projects.token;
an upload replaces the project's components in one transaction.
projects.max_age removes projects that stopped uploading.
43 lines
1,012 B
Go
43 lines
1,012 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// projectPruneInterval is how often projects older than projects.max_age
|
|
// are removed.
|
|
const projectPruneInterval = time.Hour
|
|
|
|
// startProjectPruning removes projects that have not uploaded an SBOM for
|
|
// projects.max_age, once at startup and then every projectPruneInterval.
|
|
func (s *Server) startProjectPruning(ctx context.Context) {
|
|
maxAge := s.cfg.Projects.MaxAgeDuration()
|
|
if !s.cfg.Projects.Enabled || maxAge <= 0 {
|
|
return
|
|
}
|
|
prune := func() {
|
|
s.runExclusive(ctx, "project-pruning", func() {
|
|
pruned, err := s.db.PruneProjects(time.Now().Add(-maxAge))
|
|
if err != nil {
|
|
s.logger.Warn("pruning projects failed", "error", err)
|
|
}
|
|
if pruned > 0 {
|
|
s.logger.Info("pruned projects", "count", pruned, "max_age", maxAge)
|
|
}
|
|
})
|
|
}
|
|
s.background.Go(func() {
|
|
prune()
|
|
ticker := time.NewTicker(projectPruneInterval)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
prune()
|
|
}
|
|
}
|
|
})
|
|
}
|