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:
@@ -16,6 +16,7 @@ go_library(
|
||||
deps = [
|
||||
"//docs:go_default_library",
|
||||
"//errors:go_default_library",
|
||||
"//pkg/extensions/search/cve:go_default_library",
|
||||
"//pkg/log:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
"@com_github_chartmuseum_auth//:go_default_library",
|
||||
|
||||
+5
-8
@@ -12,8 +12,6 @@ import (
|
||||
// Commit ...
|
||||
var Commit string //nolint: gochecknoglobals
|
||||
|
||||
const updateInterval = 24
|
||||
|
||||
type StorageConfig struct {
|
||||
RootDirectory string
|
||||
GC bool
|
||||
@@ -96,12 +94,11 @@ type Config struct {
|
||||
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
Version: dspec.Version,
|
||||
Commit: Commit,
|
||||
Storage: StorageConfig{GC: true, Dedupe: true},
|
||||
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
||||
Log: &LogConfig{Level: "debug"},
|
||||
Extensions: &ExtensionConfig{&SearchConfig{CVE: &CVEConfig{UpdateInterval: updateInterval}}},
|
||||
Version: dspec.Version,
|
||||
Commit: Commit,
|
||||
Storage: StorageConfig{GC: true, Dedupe: true},
|
||||
HTTP: HTTPConfig{Address: "127.0.0.1", Port: "8080"},
|
||||
Log: &LogConfig{Level: "debug"},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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