Skip to content

Commit

Permalink
refactor checks for activitylog and antivirus
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Oct 10, 2024
1 parent e08baa7 commit f64ccd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
12 changes: 2 additions & 10 deletions services/activitylog/pkg/server/debug/server.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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(
Expand Down
28 changes: 6 additions & 22 deletions services/antivirus/pkg/server/debug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}),
)

Expand Down

0 comments on commit f64ccd0

Please sign in to comment.