From 3c861922a677a180059b1ee684e482983ef0dbb6 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Fri, 4 Sep 2020 13:20:17 +1000 Subject: [PATCH] [MISC] Address errors from linter updates (#1308) --- cmd/authelia/main.go | 2 +- internal/authentication/ldap_user_provider.go | 2 +- internal/commands/certificates.go | 2 +- internal/configuration/validator/authentication.go | 4 ++-- internal/configuration/validator/configuration.go | 2 +- internal/configuration/validator/keys_test.go | 2 +- internal/handlers/handler_firstfactor.go | 2 +- internal/storage/errors.go | 2 +- internal/utils/strings.go | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/authelia/main.go b/cmd/authelia/main.go index 64cdd02d0..fa5e69760 100644 --- a/cmd/authelia/main.go +++ b/cmd/authelia/main.go @@ -24,7 +24,7 @@ import ( var configPathFlag string -//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting +//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting. func startServer() { config, errs := configuration.Read(configPathFlag) diff --git a/internal/authentication/ldap_user_provider.go b/internal/authentication/ldap_user_provider.go index c96dde66e..3b6c08881 100644 --- a/internal/authentication/ldap_user_provider.go +++ b/internal/authentication/ldap_user_provider.go @@ -49,7 +49,7 @@ func (p *LDAPUserProvider) connect(userDN string, password string) (LDAPConnecti logging.Logger().Trace("LDAP client starts a TLS session") conn, err := p.connectionFactory.DialTLS("tcp", url.Host, &tls.Config{ - InsecureSkipVerify: p.configuration.SkipVerify, //nolint:gosec // This is a configurable option, is desirable in some situations and is off by default + InsecureSkipVerify: p.configuration.SkipVerify, //nolint:gosec // This is a configurable option, is desirable in some situations and is off by default. }) if err != nil { return nil, err diff --git a/internal/commands/certificates.go b/internal/commands/certificates.go index fa50684af..d1d382b1b 100644 --- a/internal/commands/certificates.go +++ b/internal/commands/certificates.go @@ -63,7 +63,7 @@ func publicKey(priv interface{}) interface{} { } } -//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting +//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting. func generateSelfSignedCertificate(cmd *cobra.Command, args []string) { // implementation retrieved from https://golang.org/src/crypto/tls/generate_cert.go var priv interface{} diff --git a/internal/configuration/validator/authentication.go b/internal/configuration/validator/authentication.go index 3c5584c80..6ac166ea5 100644 --- a/internal/configuration/validator/authentication.go +++ b/internal/configuration/validator/authentication.go @@ -10,7 +10,7 @@ import ( "github.com/authelia/authelia/internal/utils" ) -//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting +//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting. func validateFileAuthenticationBackend(configuration *schema.FileAuthenticationBackendConfiguration, validator *schema.StructValidator) { if configuration.Path == "" { validator.Push(errors.New("Please provide a `path` for the users database in `authentication_backend`")) @@ -98,7 +98,7 @@ func validateLdapURL(ldapURL string, validator *schema.StructValidator) string { return u.String() } -//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting +//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting. func validateLdapAuthenticationBackend(configuration *schema.LDAPAuthenticationBackendConfiguration, validator *schema.StructValidator) { if configuration.URL == "" { validator.Push(errors.New("Please provide a URL to the LDAP server")) diff --git a/internal/configuration/validator/configuration.go b/internal/configuration/validator/configuration.go index f410ff2e2..e3adab6ce 100644 --- a/internal/configuration/validator/configuration.go +++ b/internal/configuration/validator/configuration.go @@ -11,7 +11,7 @@ var defaultPort = 8080 var defaultLogLevel = "info" // ValidateConfiguration and adapt the configuration read from file. -//nolint:gocyclo // This function is likely to always have lots of if/else statements, as long as we keep the flow clean it should be understandable +//nolint:gocyclo // This function is likely to always have lots of if/else statements, as long as we keep the flow clean it should be understandable. func ValidateConfiguration(configuration *schema.Configuration, validator *schema.StructValidator) { if configuration.Host == "" { configuration.Host = "0.0.0.0" diff --git a/internal/configuration/validator/keys_test.go b/internal/configuration/validator/keys_test.go index 4ec5a2c3b..119eb3661 100644 --- a/internal/configuration/validator/keys_test.go +++ b/internal/configuration/validator/keys_test.go @@ -33,7 +33,7 @@ func TestShouldNotValidateBadKeys(t *testing.T) { } func TestAllSpecificErrorKeys(t *testing.T) { - var configKeys []string //nolint:prealloc // This is because the test is dynamic based on the keys that exist in the map + var configKeys []string //nolint:prealloc // This is because the test is dynamic based on the keys that exist in the map. var uniqueValues []string diff --git a/internal/handlers/handler_firstfactor.go b/internal/handlers/handler_firstfactor.go index fb1c3932e..e3e14ab10 100644 --- a/internal/handlers/handler_firstfactor.go +++ b/internal/handlers/handler_firstfactor.go @@ -31,7 +31,7 @@ func movingAverageIteration(value time.Duration, successful bool, movingAverageC } func calculateActualDelay(ctx *middlewares.AutheliaCtx, execDuration time.Duration, avgExecDurationMs float64, successful *bool) float64 { - randomDelayMs := float64(rand.Int63n(msMaximumRandomDelay)) + randomDelayMs := float64(rand.Int63n(msMaximumRandomDelay)) //nolint:gosec // TODO: Consider use of crypto/rand, this should be benchmarked and measured first. totalDelayMs := math.Max(avgExecDurationMs, msMinimumDelay1FA) + randomDelayMs actualDelayMs := math.Max(totalDelayMs-float64(execDuration.Milliseconds()), 1.0) ctx.Logger.Tracef("attempt successful: %t, exec duration: %d, avg execution duration: %d, random delay ms: %d, total delay ms: %d, actual delay ms: %d", *successful, execDuration.Milliseconds(), int64(avgExecDurationMs), int64(randomDelayMs), int64(totalDelayMs), int64(actualDelayMs)) diff --git a/internal/storage/errors.go b/internal/storage/errors.go index 1f8d4f9a7..30384e21a 100644 --- a/internal/storage/errors.go +++ b/internal/storage/errors.go @@ -6,6 +6,6 @@ var ( // ErrNoU2FDeviceHandle error thrown when no U2F device handle has been found in DB. ErrNoU2FDeviceHandle = errors.New("No U2F device handle found") - // ErrNoTOTPSecret error thrown when no TOTP secret has been found in DB + // ErrNoTOTPSecret error thrown when no TOTP secret has been found in DB. ErrNoTOTPSecret = errors.New("No TOTP secret registered") ) diff --git a/internal/utils/strings.go b/internal/utils/strings.go index bfe957d48..9b8789e46 100644 --- a/internal/utils/strings.go +++ b/internal/utils/strings.go @@ -86,7 +86,7 @@ func RandomString(n int, characters []rune) (randomString string) { b := make([]rune, n) for i := range b { - b[i] = characters[rand.Intn(len(characters))] + b[i] = characters[rand.Intn(len(characters))] //nolint:gosec // Likely isn't necessary to use the more expensive crypto/rand for this utility func. } return string(b)