mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
Enable trivy db download and update
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/anuvu/zot/errors"
|
||||
cveinfo "github.com/anuvu/zot/pkg/extensions/search/cve"
|
||||
"github.com/anuvu/zot/pkg/log"
|
||||
"github.com/anuvu/zot/pkg/storage"
|
||||
"github.com/gorilla/handlers"
|
||||
@@ -49,6 +51,34 @@ func (c *Controller) Run() error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Updating the CVE Database
|
||||
if c.Config != nil && c.Config.Extensions != nil && c.Config.Extensions.Search != nil &&
|
||||
c.Config.Extensions.Search.CVE != nil {
|
||||
defaultUpdateInterval, _ := time.ParseDuration("2h")
|
||||
|
||||
if c.Config.Extensions.Search.CVE.UpdateInterval < defaultUpdateInterval {
|
||||
c.Config.Extensions.Search.CVE.UpdateInterval = defaultUpdateInterval
|
||||
c.Log.Warn().Msg("CVE update interval set to too-short interval <= 1, changing update duration to 2 hours and continuing.") // nolint: lll
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
c.Log.Info().Msg("Updating the CVE database")
|
||||
|
||||
err := cveinfo.UpdateCVEDb(c.Config.Storage.RootDirectory, c.Log)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.Log.Info().Str("Db update completed, next update scheduled after", c.Config.Extensions.Search.CVE.UpdateInterval.String()).Msg("") //nolint: lll
|
||||
|
||||
time.Sleep(c.Config.Extensions.Search.CVE.UpdateInterval)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
c.Log.Info().Msg("Cve config not provided, skipping cve update")
|
||||
}
|
||||
|
||||
c.Router = engine
|
||||
c.Router.UseEncodedPath()
|
||||
_ = NewRouteHandler(c)
|
||||
|
||||
Reference in New Issue
Block a user