Skip to content

Commit 837eb42

Browse files
committed
fix issues found by lint
1 parent 1d129c5 commit 837eb42

7 files changed

Lines changed: 22 additions & 9 deletions

File tree

pkg/erbackend/reverseproxybackend/reverseproxy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func NewWithModifyResponse(
5757
if opts.TlsConfig != nil { // got custom TLS config?
5858
return &http.Transport{
5959
TLSClientConfig: &tls.Config{
60-
ServerName: opts.TlsConfig.ServerName,
60+
ServerName: opts.TlsConfig.ServerName,
61+
//nolint:gosec // InsecureSkipVerify intentionally configurable
6162
InsecureSkipVerify: opts.TlsConfig.InsecureSkipVerify,
6263
},
6364
}
@@ -72,6 +73,7 @@ func NewWithModifyResponse(
7273
return &httputil.ReverseProxy{
7374
Transport: transport,
7475
Director: func(req *http.Request) {
76+
//nolint:gosec // Cryptographical randomness not required here
7577
randomOriginIdx := rand.Intn(len(originUrls))
7678

7779
originUrl := originUrls[randomOriginIdx]

pkg/erconfig/appconfig.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ func (b *Backend) Describe() string {
393393
return string(b.Kind) + ":" + b.TurbochargerOpts.Manifest.String()
394394
case BackendKindAuthSso:
395395
return string(b.Kind) + ":" + fmt.Sprintf("[audience=%s] -> %s", b.AuthSsoOpts.Audience, b.AuthSsoOpts.AuthorizedBackend.Describe())
396-
default:
396+
case BackendKindEdgerouterAdmin, BackendKindPromMetrics: // to please exhaustive lint
397+
return string(b.Kind)
398+
default: // should never actually arrive here
397399
return string(b.Kind)
398400
}
399401
}

pkg/erdiscovery/dockerdiscovery/docker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (s *dockerDiscovery) ReadApplications(ctx context.Context) ([]erconfig.Appl
8686
return nil, err
8787
}
8888

89-
swarmServicesAndBareContainers := append(swarmServices, bareContainers...)
89+
swarmServicesAndBareContainers := []Service{}
90+
swarmServicesAndBareContainers = append(swarmServicesAndBareContainers, swarmServices...)
91+
swarmServicesAndBareContainers = append(swarmServicesAndBareContainers, bareContainers...)
9092

9193
apps := []erconfig.Application{}
9294

pkg/erdiscovery/s3discovery/s3discovery.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package s3discovery
44
import (
55
"bytes"
66
"context"
7-
"crypto/sha1"
7+
"crypto/sha1" //nolint:gosec // Not used for cryptographic purposes
88
"encoding/json"
99
"fmt"
1010
"os"
@@ -62,6 +62,7 @@ func (d *s3discovery) ReadApplications(ctx context.Context) ([]erconfig.Applicat
6262
return nil, fmt.Errorf("s3discovery: ListObjects: %v", err)
6363
}
6464

65+
//nolint:gosec // Not used for cryptographic purposes
6566
contentsEtagsHashBuilder := sha1.New()
6667

6768
for _, object := range listResponse.Contents {

pkg/erserver/hostregexp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func hostnameRegexpSyntaxToRegexp(in string) (*regexp.Regexp, error) {
2828
}
2929

3030
func escapeRegexChars(in string) string {
31-
return strings.Replace(in, ".", `\.`, -1)
31+
return strings.ReplaceAll(in, ".", `\.`)
3232
}
3333

3434
func unescapeRegexChars(in string) string {
35-
return strings.Replace(in, `\.`, `.`, -1)
35+
return strings.ReplaceAll(in, `\.`, `.`)
3636
}

pkg/erserver/ipfilter_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ allow_specified {
4040
`))
4141
assert.Ok(t, err)
4242

43+
//nolint:gocritic // intentionally useless lambda, but useful as shorthand
4344
ip := func(ipStr string) netaddr.IP { // shorthand
4445
return netaddr.MustParseIP(ipStr)
4546
}

pkg/erserver/serve.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,15 @@ func Serve(ctx context.Context, logger *log.Logger) error {
152152
tasks.Start("listener :443", func(ctx context.Context) error {
153153
srv := &http.Server{
154154
Addr: ":443",
155+
// lint complains about too low MinVersion (the default, in Go sets it as TLS 1.0).
156+
// purposefully leaving MinVersion as default because I feel Go stdlib's default MinVersion
157+
// in the long run aligns with loadbalancer use case of conservatively having to support a wide base of users.
158+
// https://developers.cloudflare.com/ssl/edge-certificates/additional-options/minimum-tls#decide-what-version-to-use
159+
//
160+
//nolint:gosec // rationale above
155161
TLSConfig: &tls.Config{
156-
// this integrates CertBus into your server - certificates are fetched
157-
// dynamically from CertBus's dynamically managed state
158-
GetCertificate: certBus.GetCertificateAdapter(),
162+
// MinVersion: ... // purposefully unset to follow Go stdlib MinVersion
163+
GetCertificate: getCertificateFn,
159164
},
160165
Handler: serveRequestWithMetricsCapture,
161166
}

0 commit comments

Comments
 (0)