update lint rules and fix some warnings

This commit is contained in:
Nicola Murino 2021-11-27 17:04:13 +01:00
parent 18ab757216
commit 3e478f42ea
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
9 changed files with 34 additions and 2 deletions

View file

@ -25,6 +25,14 @@ linters-settings:
#enable: #enable:
# - fieldalignment # - fieldalignment
issues:
include:
- EXC0002
- EXC0012
- EXC0013
- EXC0014
- EXC0015
linters: linters:
enable: enable:
- goconst - goconst

View file

@ -25,6 +25,7 @@ import (
// RetentionCheckNotification defines the supported notification methods for a retention check result // RetentionCheckNotification defines the supported notification methods for a retention check result
type RetentionCheckNotification = string type RetentionCheckNotification = string
// Supported notification methods
const ( const (
// notify results using the defined "data_retention_hook" // notify results using the defined "data_retention_hook"
RetentionCheckNotificationHook = "Hook" RetentionCheckNotificationHook = "Hook"

View file

@ -117,6 +117,7 @@ func (t *BaseTransfer) GetFsPath() string {
return t.fsPath 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 { func (t *BaseTransfer) SetTimes(fsPath string, atime time.Time, mtime time.Time) bool {
if fsPath == t.GetFsPath() { if fsPath == t.GetFsPath() {
t.aTime = atime t.aTime = atime

View file

@ -133,6 +133,7 @@ var (
ErrNoInitRequired = errors.New("the data provider is up to date") ErrNoInitRequired = errors.New("the data provider is up to date")
// ErrInvalidCredentials defines the error to return if the supplied credentials are invalid // 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") ErrLoginNotAllowedFromIP = errors.New("login is not allowed from this IP")
isAdminCreated = int32(0) isAdminCreated = int32(0)
validTLSUsernames = []string{string(sdk.TLSUsernameNone), string(sdk.TLSUsernameCN)} validTLSUsernames = []string{string(sdk.TLSUsernameNone), string(sdk.TLSUsernameCN)}

View file

@ -10,34 +10,42 @@ type BaseSecret struct {
Mode int `json:"mode,omitempty"` Mode int `json:"mode,omitempty"`
} }
// GetStatus returns the secret's status
func (s *BaseSecret) GetStatus() SecretStatus { func (s *BaseSecret) GetStatus() SecretStatus {
return s.Status return s.Status
} }
// GetPayload returns the secret's payload
func (s *BaseSecret) GetPayload() string { func (s *BaseSecret) GetPayload() string {
return s.Payload return s.Payload
} }
// GetKey returns the secret's key
func (s *BaseSecret) GetKey() string { func (s *BaseSecret) GetKey() string {
return s.Key return s.Key
} }
// GetMode returns the encryption mode
func (s *BaseSecret) GetMode() int { func (s *BaseSecret) GetMode() int {
return s.Mode return s.Mode
} }
// GetAdditionalData returns the secret's additional data
func (s *BaseSecret) GetAdditionalData() string { func (s *BaseSecret) GetAdditionalData() string {
return s.AdditionalData return s.AdditionalData
} }
// SetKey sets the secret's key
func (s *BaseSecret) SetKey(value string) { func (s *BaseSecret) SetKey(value string) {
s.Key = value s.Key = value
} }
// SetAdditionalData sets the secret's additional data
func (s *BaseSecret) SetAdditionalData(value string) { func (s *BaseSecret) SetAdditionalData(value string) {
s.AdditionalData = value s.AdditionalData = value
} }
// SetStatus sets the secret's status
func (s *BaseSecret) SetStatus(value SecretStatus) { func (s *BaseSecret) SetStatus(value SecretStatus) {
s.Status = value s.Status = value
} }

View file

@ -8,10 +8,12 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
// HCLogAdapter is an adapter for hclog.Logger
type HCLogAdapter struct { type HCLogAdapter struct {
hclog.Logger 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{}) { func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...interface{}) {
var ev *zerolog.Event var ev *zerolog.Event
switch level { switch level {
@ -29,38 +31,47 @@ func (l *HCLogAdapter) Log(level hclog.Level, msg string, args ...interface{}) {
ev.Msg(msg) ev.Msg(msg)
} }
// Trace emits a message and key/value pairs at the TRACE level
func (l *HCLogAdapter) Trace(msg string, args ...interface{}) { func (l *HCLogAdapter) Trace(msg string, args ...interface{}) {
l.Log(hclog.Debug, msg, args...) 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{}) { func (l *HCLogAdapter) Debug(msg string, args ...interface{}) {
l.Log(hclog.Debug, msg, args...) 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{}) { func (l *HCLogAdapter) Info(msg string, args ...interface{}) {
l.Log(hclog.Info, msg, args...) 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{}) { func (l *HCLogAdapter) Warn(msg string, args ...interface{}) {
l.Log(hclog.Warn, msg, args...) 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{}) { func (l *HCLogAdapter) Error(msg string, args ...interface{}) {
l.Log(hclog.Error, msg, args...) l.Log(hclog.Error, msg, args...)
} }
// With creates a sub-logger
func (l *HCLogAdapter) With(args ...interface{}) hclog.Logger { func (l *HCLogAdapter) With(args ...interface{}) hclog.Logger {
return &HCLogAdapter{Logger: l.Logger.With(args...)} 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 { func (l *HCLogAdapter) Named(name string) hclog.Logger {
return &HCLogAdapter{Logger: l.Logger.Named(name)} 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 { func (l *HCLogAdapter) StandardLogger(opts *hclog.StandardLoggerOptions) *log.Logger {
return log.New(&StdLoggerWrapper{Sender: l.Name()}, "", 0) 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 { func (l *HCLogAdapter) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer {
return &StdLoggerWrapper{Sender: l.Name()} return &StdLoggerWrapper{Sender: l.Name()}
} }

View file

@ -1,7 +1,7 @@
//go:build !nometrics //go:build !nometrics
// +build !nometrics // +build !nometrics
// Package metrics provides Prometheus metrics support // Package metric provides Prometheus metrics support
package metric package metric
import ( import (

View file

@ -175,6 +175,7 @@ type UserFilters struct {
UserType string `json:"user_type,omitempty"` UserType string `json:"user_type,omitempty"`
} }
// BaseUser defines the shared user fields
type BaseUser struct { type BaseUser struct {
// Data provider unique identifier // Data provider unique identifier
ID int64 `json:"id"` ID int64 `json:"id"`

View file

@ -163,6 +163,7 @@ func RenderRetentionReportTemplate(buf *bytes.Buffer, data interface{}) error {
return emailTemplates[templateRetentionCheckResult].Execute(buf, data) return emailTemplates[templateRetentionCheckResult].Execute(buf, data)
} }
// RenderPasswordResetTemplate executes the password reset template
func RenderPasswordResetTemplate(buf *bytes.Buffer, data interface{}) error { func RenderPasswordResetTemplate(buf *bytes.Buffer, data interface{}) error {
if smtpServer == nil { if smtpServer == nil {
return errors.New("smtp: not configured") return errors.New("smtp: not configured")