diff --git a/.golangci.yml b/.golangci.yml index ec7c6065c..11a419de0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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] diff --git a/services/audit/pkg/command/root.go b/services/audit/pkg/command/root.go index 025dc925d..cfe85a709 100644 --- a/services/audit/pkg/command/root.go +++ b/services/audit/pkg/command/root.go @@ -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 { diff --git a/services/audit/pkg/config/config.go b/services/audit/pkg/config/config.go index d0ccca9e9..48cadb0db 100644 --- a/services/audit/pkg/config/config.go +++ b/services/audit/pkg/config/config.go @@ -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."` } diff --git a/services/audit/pkg/config/defaults/defaultconfig.go b/services/audit/pkg/config/defaults/defaultconfig.go index 34af1c788..5a4286cbc 100644 --- a/services/audit/pkg/config/defaults/defaultconfig.go +++ b/services/audit/pkg/config/defaults/defaultconfig.go @@ -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 } diff --git a/services/audit/pkg/config/parser/parse.go b/services/audit/pkg/config/parser/parse.go index 43adabd42..f4e5f3d68 100644 --- a/services/audit/pkg/config/parser/parse.go +++ b/services/audit/pkg/config/parser/parse.go @@ -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 } diff --git a/services/audit/pkg/logging/logging.go b/services/audit/pkg/logging/logging.go index 4acd0282b..01f0569fa 100644 --- a/services/audit/pkg/logging/logging.go +++ b/services/audit/pkg/logging/logging.go @@ -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), diff --git a/services/audit/pkg/service/service.go b/services/audit/pkg/service/service.go index 961c41963..621eaf8ec 100644 --- a/services/audit/pkg/service/service.go +++ b/services/audit/pkg/service/service.go @@ -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 { diff --git a/services/audit/pkg/types/conversion.go b/services/audit/pkg/types/conversion.go index 14cea5a01..c98b2caf4 100644 --- a/services/audit/pkg/types/conversion.go +++ b/services/audit/pkg/types/conversion.go @@ -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 {