From 3e478f42ea93010bf4b0fef1e57f4594fcb36e50 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 27 Nov 2021 17:04:13 +0100 Subject: [PATCH] update lint rules and fix some warnings --- .golangci.yml | 8 ++++++++ common/dataretention.go | 1 + common/transfer.go | 1 + dataprovider/dataprovider.go | 3 ++- kms/basesecret.go | 8 ++++++++ logger/hclog_adapter.go | 11 +++++++++++ metric/metric.go | 2 +- sdk/user.go | 1 + smtp/smtp.go | 1 + 9 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fd448089..820a03e0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,6 +25,14 @@ linters-settings: #enable: # - fieldalignment +issues: + include: + - EXC0002 + - EXC0012 + - EXC0013 + - EXC0014 + - EXC0015 + linters: enable: - goconst diff --git a/common/dataretention.go b/common/dataretention.go index 3341c2d6..f96d0108 100644 --- a/common/dataretention.go +++ b/common/dataretention.go @@ -25,6 +25,7 @@ import ( // RetentionCheckNotification defines the supported notification methods for a retention check result type RetentionCheckNotification = string +// Supported notification methods const ( // notify results using the defined "data_retention_hook" RetentionCheckNotificationHook = "Hook" diff --git a/common/transfer.go b/common/transfer.go index 6dd3703e..7b2736d3 100644 --- a/common/transfer.go +++ b/common/transfer.go @@ -117,6 +117,7 @@ func (t *BaseTransfer) GetFsPath() string { return t.fsPath } +// SetTimes stores access and modification times if fsPath matches the current file func (t *BaseTransfer) SetTimes(fsPath string, atime time.Time, mtime time.Time) bool { if fsPath == t.GetFsPath() { t.aTime = atime diff --git a/dataprovider/dataprovider.go b/dataprovider/dataprovider.go index 272fdabe..35723e15 100644 --- a/dataprovider/dataprovider.go +++ b/dataprovider/dataprovider.go @@ -132,7 +132,8 @@ var ( // ErrNoInitRequired defines the error returned by InitProvider if no inizialization/update is required ErrNoInitRequired = errors.New("the data provider is up to date") // ErrInvalidCredentials defines the error to return if the supplied credentials are invalid - ErrInvalidCredentials = errors.New("invalid credentials") + ErrInvalidCredentials = errors.New("invalid credentials") + // ErrLoginNotAllowedFromIP defines the error to return if login is denied from the current IP ErrLoginNotAllowedFromIP = errors.New("login is not allowed from this IP") isAdminCreated = int32(0) validTLSUsernames = []string{string(sdk.TLSUsernameNone), string(sdk.TLSUsernameCN)} diff --git a/kms/basesecret.go b/kms/basesecret.go index 52ce99c5..9e8a5c49 100644 --- a/kms/basesecret.go +++ b/kms/basesecret.go @@ -10,34 +10,42 @@ type BaseSecret struct { Mode int `json:"mode,omitempty"` } +// GetStatus returns the secret's status func (s *BaseSecret) GetStatus() SecretStatus { return s.Status } +// GetPayload returns the secret's payload func (s *BaseSecret) GetPayload() string { return s.Payload } +// GetKey returns the secret's key func (s *BaseSecret) GetKey() string { return s.Key } +// GetMode returns the encryption mode func (s *BaseSecret) GetMode() int { return s.Mode } +// GetAdditionalData returns the secret's additional data func (s *BaseSecret) GetAdditionalData() string { return s.AdditionalData } +// SetKey sets the secret's key func (s *BaseSecret) SetKey(value string) { s.Key = value } +// SetAdditionalData sets the secret's additional data func (s *BaseSecret) SetAdditionalData(value string) { s.AdditionalData = value } +// SetStatus sets the secret's status func (s *BaseSecret) SetStatus(value SecretStatus) { s.Status = value } diff --git a/logger/hclog_adapter.go b/logger/hclog_adapter.go index 6a1fc6bc..4dc15208 100644 --- a/logger/hclog_adapter.go +++ b/logger/hclog_adapter.go @@ -8,10 +8,12 @@ import ( "github.com/rs/zerolog" ) +// HCLogAdapter is an adapter for hclog.Logger type HCLogAdapter struct { hclog.Logger } +// Log emits a message and key/value pairs at a provided log level func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...interface{}) { var ev *zerolog.Event switch level { @@ -29,38 +31,47 @@ func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...interface{}) { ev.Msg(msg) } +// Trace emits a message and key/value pairs at the TRACE level func (l *HCLogAdapter) Trace(msg string, args ...interface{}) { l.Log(hclog.Debug, msg, args...) } +// Debug emits a message and key/value pairs at the DEBUG level func (l *HCLogAdapter) Debug(msg string, args ...interface{}) { l.Log(hclog.Debug, msg, args...) } +// Info emits a message and key/value pairs at the INFO level func (l *HCLogAdapter) Info(msg string, args ...interface{}) { l.Log(hclog.Info, msg, args...) } +// Warn emits a message and key/value pairs at the WARN level func (l *HCLogAdapter) Warn(msg string, args ...interface{}) { l.Log(hclog.Warn, msg, args...) } +// Error emits a message and key/value pairs at the ERROR level func (l *HCLogAdapter) Error(msg string, args ...interface{}) { l.Log(hclog.Error, msg, args...) } +// With creates a sub-logger func (l *HCLogAdapter) With(args ...interface{}) hclog.Logger { return &HCLogAdapter{Logger: l.Logger.With(args...)} } +// Named creates a logger that will prepend the name string on the front of all messages func (l *HCLogAdapter) Named(name string) hclog.Logger { return &HCLogAdapter{Logger: l.Logger.Named(name)} } +// StandardLogger returns a value that conforms to the stdlib log.Logger interface func (l *HCLogAdapter) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger { return log.New(&StdLoggerWrapper{Sender: l.Name()}, "", 0) } +// StandardWriter returns a value that conforms to io.Writer, which can be passed into log.SetOutput() func (l *HCLogAdapter) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer { return &StdLoggerWrapper{Sender: l.Name()} } diff --git a/metric/metric.go b/metric/metric.go index 2b639051..16cd3fc2 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -1,7 +1,7 @@ //go:build !nometrics // +build !nometrics -// Package metrics provides Prometheus metrics support +// Package metric provides Prometheus metrics support package metric import ( diff --git a/sdk/user.go b/sdk/user.go index 4b40e3ce..58c687f2 100644 --- a/sdk/user.go +++ b/sdk/user.go @@ -175,6 +175,7 @@ type UserFilters struct { UserType string `json:"user_type,omitempty"` } +// BaseUser defines the shared user fields type BaseUser struct { // Data provider unique identifier ID int64 `json:"id"` diff --git a/smtp/smtp.go b/smtp/smtp.go index 2a6d8c45..b176a883 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -163,6 +163,7 @@ func RenderRetentionReportTemplate(buf *bytes.Buffer, data interface{}) error { return emailTemplates[templateRetentionCheckResult].Execute(buf, data) } +// RenderPasswordResetTemplate executes the password reset template func RenderPasswordResetTemplate(buf *bytes.Buffer, data interface{}) error { if smtpServer == nil { return errors.New("smtp: not configured")