mirror of
https://github.com/project-zot/zot.git
synced 2026-06-19 22:27:58 +08:00
feat: allow disabling CVE independently from search
Agent-Logs-Url: https://github.com/project-zot/zot/sessions/9b89c154-fd36-4315-9910-9c19f96e2417 Co-authored-by: rchincha <45800463+rchincha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d8a53b7096
commit
b5ed56f07d
@@ -53,6 +53,7 @@ type SearchConfig struct {
|
||||
}
|
||||
|
||||
type CVEConfig struct {
|
||||
Enable *bool `mapstructure:",omitempty" json:",omitempty"`
|
||||
UpdateInterval time.Duration // should be 2 hours or more, if not specified default be kept as 2 hours
|
||||
Trivy *TrivyConfig
|
||||
}
|
||||
@@ -109,8 +110,15 @@ func (e *ExtensionConfig) IsCveScanningEnabled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return e.Search != nil && e.Search.Enable != nil && *e.Search.Enable &&
|
||||
e.Search.CVE != nil && e.Search.CVE.Trivy != nil
|
||||
if e.Search == nil || e.Search.Enable == nil || !*e.Search.Enable || e.Search.CVE == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if e.Search.CVE.Enable != nil && !*e.Search.CVE.Enable {
|
||||
return false
|
||||
}
|
||||
|
||||
return e.Search.CVE.Trivy != nil
|
||||
}
|
||||
|
||||
// IsEventRecorderEnabled checks if event recording is enabled in this extensions config.
|
||||
|
||||
@@ -44,6 +44,22 @@ func buildSearchConfigWithCVE(enabled bool) *config.ExtensionConfig {
|
||||
return ext
|
||||
}
|
||||
|
||||
func buildSearchConfigWithCVEDisabled(enabled bool) *config.ExtensionConfig {
|
||||
disabled := false
|
||||
ext := &config.ExtensionConfig{}
|
||||
ext.Search = &config.SearchConfig{
|
||||
BaseConfig: config.BaseConfig{
|
||||
Enable: &enabled,
|
||||
},
|
||||
CVE: &config.CVEConfig{
|
||||
Enable: &disabled,
|
||||
Trivy: &config.TrivyConfig{},
|
||||
},
|
||||
}
|
||||
|
||||
return ext
|
||||
}
|
||||
|
||||
func buildEventsConfig(enabled bool) *config.ExtensionConfig {
|
||||
ext := &config.ExtensionConfig{}
|
||||
ext.Events = &events.Config{
|
||||
@@ -302,6 +318,12 @@ func TestExtensionConfig(t *testing.T) {
|
||||
testMethodWithNilEnable("Search", (*config.ExtensionConfig).IsCveScanningEnabled)
|
||||
testMethodWithDisabledEnable("Search", (*config.ExtensionConfig).IsCveScanningEnabled, buildSearchConfig)
|
||||
testMethodWithEnabledEnable("Search", (*config.ExtensionConfig).IsCveScanningEnabled, buildSearchConfigWithCVE)
|
||||
|
||||
Convey("Test with search enabled but cve explicitly disabled", func() {
|
||||
enabled := true
|
||||
extensionConfig := buildSearchConfigWithCVEDisabled(enabled)
|
||||
So(extensionConfig.IsCveScanningEnabled(), ShouldBeFalse)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Test IsEventRecorderEnabled()", func() {
|
||||
|
||||
Reference in New Issue
Block a user