mirror of
https://github.com/project-zot/zot.git
synced 2026-06-18 05:28:07 +08:00
feat(events): add events extension (#3045)
* feat: add events config Signed-off-by: Piaras Hoban <phoban01@gmail.com> * feat: implement event support with log sink Signed-off-by: Piaras Hoban <phoban01@gmail.com> * feat: integrate events and update tests Signed-off-by: Piaras Hoban <phoban01@gmail.com> * refactor: update event config Signed-off-by: Piaras Hoban <phoban01@gmail.com> * feat: implement http and nats sinks. remove log sink Signed-off-by: Piaras Hoban <phoban01@gmail.com> * refactor: events extension setup Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: cleanup tests to use nil event recorder Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: update events config example and add more logging Signed-off-by: Piaras Hoban <phoban01@gmail.com> * refactor: better use of build tags for minimal binary Signed-off-by: Piaras Hoban <phoban01@gmail.com> * fix: missing store param in evelated privileges tests Signed-off-by: Piaras Hoban <phoban01@gmail.com> * fix: regression in config decoding Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: update check logs script to enable cross-platform usage via GREP_BIN_PATH envvar Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: fix log lint issue for events Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: fix failing events disabled test Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: add blackbox tests for events Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: specify architecture when downloading binaries in Makefile Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: improve failure handling when no valid sinks are provided Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: fix data race in events test Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: cleanup event decoding Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: fix logging tests Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: make nats server test more reliable Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: go mod cleanup Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: add sleep when setting up nats client Signed-off-by: Piaras Hoban <phoban01@gmail.com> * fix: ensure event sink errors do not propogate Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: increase coverage for events Signed-off-by: Piaras Hoban <phoban01@gmail.com> * feat(events): Refactor events to be non-blocking from caller. Signed-off-by: Asgeir Nilsen <asgeir.nilsen@bouvet.no> Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: remove harded-coded linux Co-authored-by: Andrei Aaron <andreifdaaron@gmail.com> Signed-off-by: Piaras Hoban <phoban01@gmail.com> * feat(events): fail to start if incorrect event sink is configured Signed-off-by: Piaras Hoban <phoban01@gmail.com> * test: allow cli tests to return errors instead of panic Signed-off-by: Piaras Hoban <phoban01@gmail.com> * chore: bump nats server to v2.11.3 Signed-off-by: Piaras Hoban <phoban01@gmail.com> --------- Signed-off-by: Piaras Hoban <phoban01@gmail.com> Signed-off-by: Asgeir Nilsen <asgeir.nilsen@bouvet.no> Co-authored-by: Asgeir Nilsen <asgeir.nilsen@bouvet.no> Co-authored-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -341,6 +341,20 @@ func (c *Config) Sanitize() *Config {
|
||||
sanitizedConfig.HTTP.Auth.LDAP.bindPassword = "******"
|
||||
}
|
||||
|
||||
if c.IsEventRecorderEnabled() {
|
||||
for i, sink := range c.Extensions.Events.Sinks {
|
||||
if sink.Credentials == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := DeepCopy(&c.Extensions.Events.Sinks[i], &sanitizedConfig.Extensions.Events.Sinks[i]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
sanitizedConfig.Extensions.Events.Sinks[i].Credentials.Password = "******"
|
||||
}
|
||||
}
|
||||
|
||||
return sanitizedConfig
|
||||
}
|
||||
|
||||
@@ -516,6 +530,10 @@ func (c *Config) IsCompatEnabled() bool {
|
||||
return len(c.HTTP.Compat) > 0
|
||||
}
|
||||
|
||||
func (c *Config) IsEventRecorderEnabled() bool {
|
||||
return c.Extensions != nil && c.Extensions.Events != nil && *c.Extensions.Events.Enable
|
||||
}
|
||||
|
||||
func IsOpenIDSupported(provider string) bool {
|
||||
for _, supportedProvider := range openIDSupportedProviders {
|
||||
if supportedProvider == provider {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"zotregistry.dev/zot/pkg/api/config"
|
||||
extconf "zotregistry.dev/zot/pkg/extensions/config"
|
||||
"zotregistry.dev/zot/pkg/extensions/config/events"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
@@ -129,4 +131,30 @@ func TestConfig(t *testing.T) {
|
||||
|
||||
So(conf.IsRetentionEnabled(), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("Test IsEventRecorderEnabled()", t, func() {
|
||||
conf := config.New()
|
||||
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
||||
|
||||
// Enable the event recorder
|
||||
enable := true
|
||||
conf.Extensions = &extconf.ExtensionConfig{}
|
||||
conf.Extensions.Events = &events.Config{
|
||||
Enable: &enable,
|
||||
}
|
||||
|
||||
So(conf.IsEventRecorderEnabled(), ShouldBeTrue)
|
||||
|
||||
// Disabled scenario
|
||||
disable := false
|
||||
conf.Extensions.Events.Enable = &disable
|
||||
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
||||
|
||||
// nil pointers
|
||||
conf.Extensions.Events = nil
|
||||
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
||||
|
||||
conf.Extensions = nil
|
||||
So(conf.IsEventRecorderEnabled(), ShouldBeFalse)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user