mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: Add malysis cache implementation with proxy flow integration (#346)
* feat: Add malysis cache implementation with proxy flow integration * fix: Code review fixes
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/safedep/dry/localdb"
|
||||
"github.com/safedep/dry/log"
|
||||
"github.com/safedep/pmg/analyzer"
|
||||
"github.com/safedep/pmg/analyzer/malysiscache"
|
||||
"github.com/safedep/pmg/config"
|
||||
"github.com/safedep/pmg/guard"
|
||||
"github.com/safedep/pmg/internal/audit"
|
||||
@@ -135,8 +137,31 @@ func (f *proxyFlow) Run(ctx context.Context, args []string, parsedCmd *packagema
|
||||
return fmt.Errorf("failed to create certificate manager: %w", err)
|
||||
}
|
||||
|
||||
// Optional persistent analysis cache. Disposable: any failure degrades to
|
||||
// running uncached, never blocks the install.
|
||||
var malysisCache analyzer.MalysisCache
|
||||
cacheCfg := cfg.Config.AnalysisCache.Malysis
|
||||
if cacheCfg.Enabled && cacheCfg.TTL > 0 {
|
||||
mgr := localdb.New(localdb.Config{
|
||||
Dir: cfg.LocalDBDir(),
|
||||
FileName: cfg.LocalDBFileName(),
|
||||
})
|
||||
defer func() {
|
||||
if cerr := mgr.Close(); cerr != nil {
|
||||
log.Warnf("failed to close localdb: %v", cerr)
|
||||
}
|
||||
}()
|
||||
|
||||
store, serr := mgr.Store(ctx, malysiscache.Descriptor())
|
||||
if serr != nil {
|
||||
log.Warnf("analysis cache unavailable, continuing without it: %v", serr)
|
||||
} else {
|
||||
malysisCache = malysiscache.New(store, cacheCfg)
|
||||
}
|
||||
}
|
||||
|
||||
// Create analyzer
|
||||
malysisAnalyzer, err := f.createAnalyzer()
|
||||
malysisAnalyzer, err := f.createAnalyzer(malysisCache)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create analyzer: %w", err)
|
||||
}
|
||||
@@ -381,9 +406,9 @@ func (f *proxyFlow) createCertificateManager(caCert *certmanager.Certificate) (c
|
||||
}
|
||||
|
||||
// createAnalyzer creates the malysis query analyzer
|
||||
func (f *proxyFlow) createAnalyzer() (analyzer.PackageVersionAnalyzer, error) {
|
||||
func (f *proxyFlow) createAnalyzer(cache analyzer.MalysisCache) (analyzer.PackageVersionAnalyzer, error) {
|
||||
log.Debugf("Creating malysis query analyzer")
|
||||
return analyzer.NewMalysisAnalyzer(analyzer.MalysisQueryAnalyzerConfig{})
|
||||
return analyzer.NewMalysisAnalyzer(analyzer.MalysisQueryAnalyzerConfig{Cache: cache})
|
||||
}
|
||||
|
||||
// createAndStartProxyServer creates and starts the proxy server with the given interceptor
|
||||
|
||||
Reference in New Issue
Block a user