From f64ccd0d35911e77bed9a97b48f6f148f3af9b4d Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Thu, 10 Oct 2024 11:12:41 +0200 Subject: [PATCH] refactor checks for activitylog and antivirus Signed-off-by: Christian Richter --- .../activitylog/pkg/server/debug/server.go | 12 ++------ services/antivirus/pkg/server/debug/server.go | 28 ++++--------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/services/activitylog/pkg/server/debug/server.go b/services/activitylog/pkg/server/debug/server.go index 8c9aec90c7c..c674f3ad8b9 100644 --- a/services/activitylog/pkg/server/debug/server.go +++ b/services/activitylog/pkg/server/debug/server.go @@ -1,11 +1,8 @@ package debug import ( - "context" - "fmt" "net/http" - "github.com/cs3org/reva/v2/pkg/events/stream" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -17,13 +14,8 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). - WithLogger(options.Logger).WithCheck("nats reachability", func(ctx context.Context) error { - _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) - if err != nil { - return fmt.Errorf("could not connect to nats server: %v", err) - } - return nil - }), + WithLogger(options.Logger). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)), ) return debug.NewService( diff --git a/services/antivirus/pkg/server/debug/server.go b/services/antivirus/pkg/server/debug/server.go index 460bc390a4a..b0488e321cf 100644 --- a/services/antivirus/pkg/server/debug/server.go +++ b/services/antivirus/pkg/server/debug/server.go @@ -2,15 +2,12 @@ package debug import ( "context" - "fmt" - "net" "net/http" - "github.com/cs3org/reva/v2/pkg/events/stream" + "github.com/dutchcoders/go-clamd" "github.com/owncloud/ocis/v2/ocis-pkg/handlers" "github.com/owncloud/ocis/v2/ocis-pkg/service/debug" "github.com/owncloud/ocis/v2/ocis-pkg/version" - "github.com/owncloud/ocis/v2/services/antivirus/pkg/scanners" ) // Server initializes the debug service and server. @@ -20,31 +17,18 @@ func Server(opts ...Option) (*http.Server, error) { checkHandler := handlers.NewCheckHandler( handlers.NewCheckHandlerConfiguration(). WithLogger(options.Logger). - WithCheck("nats reachability", func(ctx context.Context) error { - _, err := stream.NatsFromConfig("healthcheckfornats", false, stream.NatsConfig(options.Config.Events)) - if err != nil { - return fmt.Errorf("could not connect to nats server: %v", err) - } - return nil - }). + WithCheck("nats reachability", handlers.NewNatsCheck(options.Config.Events.Cluster)). WithCheck("antivirus reachability", func(ctx context.Context) error { cfg := options.Config switch cfg.Scanner.Type { default: - // there is not av configured, return no error here - return nil + // there is not av configured, so we panic + panic("no antivirus configured") case "clamav": - _, err := net.Dial("tcp", cfg.Scanner.ClamAV.Socket) - if err != nil { - return fmt.Errorf("could not connect to clamav server: %v", err) - } + return clamd.NewClamd(cfg.Scanner.ClamAV.Socket).Ping() case "icap": - _, err := scanners.NewICAP(cfg.Scanner.ICAP.URL, cfg.Scanner.ICAP.Service, cfg.Scanner.ICAP.Timeout) - if err != nil { - return fmt.Errorf("could not connect to icap server: %v", err) - } + return handlers.NewTCPCheck(cfg.Scanner.ICAP.URL)(ctx) } - return nil }), )