Files
ocis/services/audit/pkg/command/server.go
T

60 lines
1.5 KiB
Go
Raw Normal View History

2022-03-08 11:25:26 +01:00
package command
import (
2022-03-09 10:11:27 +01:00
"context"
2022-03-08 11:25:26 +01:00
"fmt"
"os"
2022-03-08 11:25:26 +01:00
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/events/server"
2022-04-19 09:44:47 +02:00
"github.com/go-micro/plugins/v4/events/natsjs"
2022-06-20 16:49:06 +02:00
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
"github.com/owncloud/ocis/v2/services/audit/pkg/config/parser"
"github.com/owncloud/ocis/v2/services/audit/pkg/logging"
svc "github.com/owncloud/ocis/v2/services/audit/pkg/service"
"github.com/owncloud/ocis/v2/services/audit/pkg/types"
2022-03-08 11:25:26 +01:00
"github.com/urfave/cli/v2"
)
// Server is the entrypoint for the server command.
func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name),
Category: "server",
Before: func(c *cli.Context) error {
2022-04-28 15:52:26 +02:00
err := parser.ParseConfig(cfg)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
2022-04-28 15:52:26 +02:00
}
return err
2022-03-08 11:25:26 +01:00
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)
2022-03-09 10:11:27 +01:00
ctx := cfg.Context
if ctx == nil {
ctx = context.Background()
2022-03-08 11:25:26 +01:00
}
2022-03-09 10:11:27 +01:00
ctx, cancel := context.WithCancel(ctx)
defer cancel()
2022-03-08 11:25:26 +01:00
2022-03-08 14:44:39 +01:00
evtsCfg := cfg.Events
client, err := server.NewNatsStream(
natsjs.Address(evtsCfg.Endpoint),
natsjs.ClusterID(evtsCfg.Cluster),
)
2022-03-08 11:25:26 +01:00
if err != nil {
return err
}
2022-03-23 10:15:27 +01:00
evts, err := events.Consume(client, evtsCfg.ConsumerGroup, types.RegisteredEvents()...)
2022-03-08 11:25:26 +01:00
if err != nil {
return err
}
2022-03-08 14:44:39 +01:00
2022-03-09 10:11:27 +01:00
svc.AuditLoggerFromConfig(ctx, cfg.Auditlog, evts, logger)
2022-03-08 14:44:39 +01:00
return nil
2022-03-08 11:25:26 +01:00
},
}
}