From 5f1f797281420300cb339fc79eeebe87152659c6 Mon Sep 17 00:00:00 2001 From: Matt Hook Date: Mon, 18 Dec 2023 11:48:41 +1300 Subject: [PATCH] remove deprecated random seed and other minor staticcheck errors (#10851) --- api/cmd/portainer/main.go | 4 ---- api/http/handler/auth/authenticate.go | 2 +- api/http/middlewares/endpoint.go | 10 +++++++++- api/stacks/deployments/deployer_remote.go | 1 - 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index 1b865581d..2f73b6e38 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -3,11 +3,9 @@ package main import ( "context" "crypto/sha256" - "math/rand" "os" "path" "strings" - "time" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/apikey" @@ -631,8 +629,6 @@ func buildServer(flags *portainer.CLIFlags) portainer.Server { } func main() { - rand.Seed(time.Now().UnixNano()) - configureLogger() setLoggingMode("PRETTY") diff --git a/api/http/handler/auth/authenticate.go b/api/http/handler/auth/authenticate.go index 0098e00b1..e25358955 100644 --- a/api/http/handler/auth/authenticate.go +++ b/api/http/handler/auth/authenticate.go @@ -200,7 +200,7 @@ func (handler *Handler) syncUserTeamsWithLDAPGroups(user *portainer.User, settin func teamExists(teamName string, ldapGroups []string) bool { for _, group := range ldapGroups { - if strings.ToLower(group) == strings.ToLower(teamName) { + if strings.EqualFold(group, teamName) { return true } } diff --git a/api/http/middlewares/endpoint.go b/api/http/middlewares/endpoint.go index ca9d3fbf8..fa593fd41 100644 --- a/api/http/middlewares/endpoint.go +++ b/api/http/middlewares/endpoint.go @@ -13,7 +13,15 @@ import ( "github.com/gorilla/mux" ) -const contextEndpoint = "endpoint" +// Note: context keys must be distinct types to prevent collisions. They are NOT key/value map's internally +// See: https://go.dev/blog/context#TOC_3.2. + +// This avoids staticcheck error: +// SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck) +// https://stackoverflow.com/questions/40891345/fix-should-not-use-basic-type-string-as-key-in-context-withvalue-golint +type key int + +const contextEndpoint key = 0 func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam string) mux.MiddlewareFunc { return func(next http.Handler) http.Handler { diff --git a/api/stacks/deployments/deployer_remote.go b/api/stacks/deployments/deployer_remote.go index 33bec796e..69a54e7ba 100644 --- a/api/stacks/deployments/deployer_remote.go +++ b/api/stacks/deployments/deployer_remote.go @@ -198,7 +198,6 @@ func (d *stackDeployer) remoteStack(stack *portainer.Stack, endpoint *portainer. Str("cmd", strings.Join(cmd, " ")). Msg("running unpacker") - rand.Seed(time.Now().UnixNano()) unpackerContainer, err := cli.ContainerCreate(ctx, &container.Config{ Image: image, Cmd: cmd,