fix audit service

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2022-08-17 14:20:05 +02:00
committed by kobergj
parent 66ff20442f
commit 152ce60d87
8 changed files with 29 additions and 7 deletions
+15 -1
View File
@@ -40,11 +40,25 @@ linters:
- gocognit - gocognit
- nestif # each 10-50 issues in codebase - nestif # each 10-50 issues in codebase
linters-settings:
gocyclo:
min-complexity: 35 # there are some func unforuntately who need this - should we refactor them?
severity: severity:
default-severity: error default-severity: error
issues: issues:
exclude-use-default: false exclude-use-default: true
exclude-rules:
- path: _test.go
source: "." # exclude _test.go files from linting
include: # include comment errors. We want comments!
- EXC0002
- EXC0011
- EXC0012
- EXC0013
- EXC0014
- EXC0015
# Enabled by default linters: # Enabled by default linters:
# deadcode: Finds unused code [fast: false, auto-fix: false] # deadcode: Finds unused code [fast: false, auto-fix: false]
+1
View File
@@ -49,6 +49,7 @@ func NewSutureService(cfg *ociscfg.Config) suture.Service {
} }
} }
// Serve implements Server interface
func (s SutureService) Serve(ctx context.Context) error { func (s SutureService) Serve(ctx context.Context) error {
s.cfg.Context = ctx s.cfg.Context = ctx
if err := Execute(s.cfg); err != nil { if err := Execute(s.cfg); err != nil {
+1 -1
View File
@@ -23,7 +23,7 @@ type Config struct {
// Events combines the configuration options for the event bus. // Events combines the configuration options for the event bus.
type Events struct { type Events struct {
Endpoint string `yaml:"endpoint" env:"AUDIT_EVENTS_ENDPOINT" desc:"The address of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture.` Endpoint string `yaml:"endpoint" env:"AUDIT_EVENTS_ENDPOINT" desc:"The address of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture."`
Cluster string `yaml:"cluster" env:"AUDIT_EVENTS_CLUSTER" desc:"The clusterID of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture. Mandatory when using NATS as event system."` Cluster string `yaml:"cluster" env:"AUDIT_EVENTS_CLUSTER" desc:"The clusterID of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture. Mandatory when using NATS as event system."`
ConsumerGroup string `yaml:"group" env:"AUDIT_EVENTS_GROUP" desc:"The consumergroup of the service. One group will only get one copy of an event."` ConsumerGroup string `yaml:"group" env:"AUDIT_EVENTS_GROUP" desc:"The consumergroup of the service. One group will only get one copy of an event."`
} }
@@ -4,6 +4,7 @@ import (
"github.com/owncloud/ocis/v2/services/audit/pkg/config" "github.com/owncloud/ocis/v2/services/audit/pkg/config"
) )
// FullDefaultConfig returns a fully initialized default configuration
func FullDefaultConfig() *config.Config { func FullDefaultConfig() *config.Config {
cfg := DefaultConfig() cfg := DefaultConfig()
EnsureDefaults(cfg) EnsureDefaults(cfg)
@@ -11,6 +12,7 @@ func FullDefaultConfig() *config.Config {
return cfg return cfg
} }
// DefaultConfig returns a basic default configuration
func DefaultConfig() *config.Config { func DefaultConfig() *config.Config {
return &config.Config{ return &config.Config{
Debug: config.Debug{ Debug: config.Debug{
@@ -31,6 +33,7 @@ func DefaultConfig() *config.Config {
} }
} }
// EnsureDefaults adds default values to the configuration if they are not set yet
func EnsureDefaults(cfg *config.Config) { func EnsureDefaults(cfg *config.Config) {
// provide with defaults for shared logging, since we need a valid destination address for "envdecode". // provide with defaults for shared logging, since we need a valid destination address for "envdecode".
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
@@ -45,6 +48,7 @@ func EnsureDefaults(cfg *config.Config) {
} }
} }
// Sanitize sanitized the configuration
func Sanitize(cfg *config.Config) { func Sanitize(cfg *config.Config) {
// sanitize config // sanitize config
} }
@@ -32,6 +32,7 @@ func ParseConfig(cfg *config.Config) error {
return Validate(cfg) return Validate(cfg)
} }
// Validate validates the configuration
func Validate(cfg *config.Config) error { func Validate(cfg *config.Config) error {
return nil return nil
} }
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"github.com/owncloud/ocis/v2/services/audit/pkg/config" "github.com/owncloud/ocis/v2/services/audit/pkg/config"
) )
// LoggerFromConfig initializes a service-specific logger instance. // Configure initializes a service-specific logger instance.
func Configure(name string, cfg *config.Log) log.Logger { func Configure(name string, cfg *config.Log) log.Logger {
return log.NewLogger( return log.NewLogger(
log.Name(name), log.Name(name),
+1 -1
View File
@@ -34,7 +34,7 @@ func AuditLoggerFromConfig(ctx context.Context, cfg config.Auditlog, ch <-chan i
} }
// StartAuditLogger will block. run in seperate go routine // StartAuditLogger will block. run in separate go routine
func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger, marshaller Marshaller, logto ...Log) { func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger, marshaller Marshaller, logto ...Log) {
for { for {
select { select {
+5 -3
View File
@@ -13,6 +13,8 @@ import (
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
) )
const _linktype = "link"
// BasicAuditEvent creates an AuditEvent from given values // BasicAuditEvent creates an AuditEvent from given values
func BasicAuditEvent(uid string, ctime string, msg string, action string) AuditEvent { func BasicAuditEvent(uid string, ctime string, msg string, action string) AuditEvent {
return AuditEvent{ return AuditEvent{
@@ -68,7 +70,7 @@ func ShareCreated(ev events.ShareCreated) AuditEventShareCreated {
// LinkCreated converts a ShareCreated Event to an AuditEventShareCreated // LinkCreated converts a ShareCreated Event to an AuditEventShareCreated
func LinkCreated(ev events.LinkCreated) AuditEventShareCreated { func LinkCreated(ev events.LinkCreated) AuditEventShareCreated {
uid := ev.Sharer.OpaqueId uid := ev.Sharer.OpaqueId
with, typ := "", "link" with, typ := "", _linktype
base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkCreated(uid, ev.ItemID.OpaqueId, ev.ShareID.OpaqueId), ActionShareCreated) base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkCreated(uid, ev.ItemID.OpaqueId, ev.ShareID.OpaqueId), ActionShareCreated)
return AuditEventShareCreated{ return AuditEventShareCreated{
AuditEventSharing: SharingAuditEvent("", ev.ItemID.OpaqueId, uid, base), AuditEventSharing: SharingAuditEvent("", ev.ItemID.OpaqueId, uid, base),
@@ -108,7 +110,7 @@ func ShareUpdated(ev events.ShareUpdated) AuditEventShareUpdated {
// LinkUpdated converts a LinkUpdated event to an AuditEventShareUpdated // LinkUpdated converts a LinkUpdated event to an AuditEventShareUpdated
func LinkUpdated(ev events.LinkUpdated) AuditEventShareUpdated { func LinkUpdated(ev events.LinkUpdated) AuditEventShareUpdated {
uid := ev.Sharer.OpaqueId uid := ev.Sharer.OpaqueId
with, typ := "", "link" with, typ := "", _linktype
base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkUpdated(uid, ev.ShareID.OpaqueId, ev.FieldUpdated), updateType(ev.FieldUpdated)) base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkUpdated(uid, ev.ShareID.OpaqueId, ev.FieldUpdated), updateType(ev.FieldUpdated))
return AuditEventShareUpdated{ return AuditEventShareUpdated{
AuditEventSharing: SharingAuditEvent(ev.ShareID.GetOpaqueId(), ev.ItemID.OpaqueId, uid, base), AuditEventSharing: SharingAuditEvent(ev.ShareID.GetOpaqueId(), ev.ItemID.OpaqueId, uid, base),
@@ -150,7 +152,7 @@ func ShareRemoved(ev events.ShareRemoved) AuditEventShareRemoved {
// LinkRemoved converts a LinkRemoved event to an AuditEventShareRemoved // LinkRemoved converts a LinkRemoved event to an AuditEventShareRemoved
func LinkRemoved(ev events.LinkRemoved) AuditEventShareRemoved { func LinkRemoved(ev events.LinkRemoved) AuditEventShareRemoved {
uid, sid, typ := ev.Executant.GetOpaqueId(), "", "link" uid, sid, typ := ev.Executant.GetOpaqueId(), "", _linktype
if ev.ShareID != nil { if ev.ShareID != nil {
sid = ev.ShareID.GetOpaqueId() sid = ev.ShareID.GetOpaqueId()
} else { } else {