fix audit service

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2022-08-11 15:19:49 +02:00
committed by kobergj
parent 66ff20442f
commit 152ce60d87
8 changed files with 29 additions and 7 deletions

View File

@@ -40,11 +40,25 @@ linters:
- gocognit
- 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:
default-severity: error
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:
# deadcode: Finds unused code [fast: false, auto-fix: false]

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 {
s.cfg.Context = ctx
if err := Execute(s.cfg); err != nil {

View File

@@ -23,7 +23,7 @@ type Config struct {
// Events combines the configuration options for the event bus.
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."`
ConsumerGroup string `yaml:"group" env:"AUDIT_EVENTS_GROUP" desc:"The consumergroup of the service. One group will only get one copy of an event."`
}

View File

@@ -4,6 +4,7 @@ import (
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
)
// FullDefaultConfig returns a fully initialized default configuration
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
@@ -11,6 +12,7 @@ func FullDefaultConfig() *config.Config {
return cfg
}
// DefaultConfig returns a basic default configuration
func DefaultConfig() *config.Config {
return &config.Config{
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) {
// 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 {
@@ -45,6 +48,7 @@ func EnsureDefaults(cfg *config.Config) {
}
}
// Sanitize sanitized the configuration
func Sanitize(cfg *config.Config) {
// sanitize config
}

View File

@@ -32,6 +32,7 @@ func ParseConfig(cfg *config.Config) error {
return Validate(cfg)
}
// Validate validates the configuration
func Validate(cfg *config.Config) error {
return nil
}

View File

@@ -5,7 +5,7 @@ import (
"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 {
return log.NewLogger(
log.Name(name),

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) {
for {
select {

View File

@@ -13,6 +13,8 @@ import (
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
)
const _linktype = "link"
// BasicAuditEvent creates an AuditEvent from given values
func BasicAuditEvent(uid string, ctime string, msg string, action string) AuditEvent {
return AuditEvent{
@@ -68,7 +70,7 @@ func ShareCreated(ev events.ShareCreated) AuditEventShareCreated {
// LinkCreated converts a ShareCreated Event to an AuditEventShareCreated
func LinkCreated(ev events.LinkCreated) AuditEventShareCreated {
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)
return AuditEventShareCreated{
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
func LinkUpdated(ev events.LinkUpdated) AuditEventShareUpdated {
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))
return AuditEventShareUpdated{
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
func LinkRemoved(ev events.LinkRemoved) AuditEventShareRemoved {
uid, sid, typ := ev.Executant.GetOpaqueId(), "", "link"
uid, sid, typ := ev.Executant.GetOpaqueId(), "", _linktype
if ev.ShareID != nil {
sid = ev.ShareID.GetOpaqueId()
} else {