Skip to content

Commit 3fd4da0

Browse files
committed
CLEANUP/MEDIUM: lint: upgrade linter and fix linting errors
1 parent 054014a commit 3fd4da0

17 files changed

Lines changed: 72 additions & 84 deletions

File tree

cmd/gitlab-mr-pipelines/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ func getOldMergeRequestPipelines(apiURL, projectID, mrIID, token string) ([]pipe
9696
}
9797

9898
url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/pipelines", apiURL, projectID, mrIID)
99-
req, err := http.NewRequest("GET", url, nil) //nolint:noctx,usestdlibvars
99+
req, err := http.NewRequest("GET", url, nil) //nolint:noctx,usestdlibvars,gosec // URL constructed from trusted CI environment variables
100100
if err != nil {
101101
return nil, err
102102
}
103103
req.Header.Set("PRIVATE-TOKEN", token) //nolint:canonicalheader
104104

105105
client := &http.Client{}
106-
resp, err := client.Do(req)
106+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
107107
if err != nil {
108108
return nil, err
109109
}
@@ -132,14 +132,14 @@ func getOldMergeRequestPipelines(apiURL, projectID, mrIID, token string) ([]pipe
132132

133133
func cancelPipeline(apiURL, projectID string, pipelineID int, token string) error {
134134
url := fmt.Sprintf("%s/projects/%s/pipelines/%d/cancel", apiURL, projectID, pipelineID)
135-
req, err := http.NewRequest("POST", url, nil) //nolint:noctx,usestdlibvars
135+
req, err := http.NewRequest("POST", url, nil) //nolint:noctx,usestdlibvars,gosec // URL constructed from trusted CI environment variables
136136
if err != nil {
137137
return err
138138
}
139139
req.Header.Set("PRIVATE-TOKEN", token) //nolint:canonicalheader
140140

141141
client := &http.Client{}
142-
resp, err := client.Do(req)
142+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
143143
if err != nil {
144144
return err
145145
}

cmd/govulncheck-report/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
}
7171
currentBranch = string(out)
7272
}
73-
slog.Info("Current branch: " + currentBranch)
73+
slog.Info("Current branch: " + currentBranch) //nolint:gosec // log message from trusted CI environment variables
7474

7575
cmd := exec.Command("govulncheck", "./...")
7676
out, _ := cmd.Output()
@@ -135,7 +135,7 @@ func main() {
135135
}
136136

137137
func createIssue(baseURL, token, projectID string, title, commentBody string) {
138-
slog.Info("Active issue with title '" + title + "' not found in project " + projectID)
138+
slog.Info("Active issue with title '" + title + "' not found in project " + projectID) //nolint:gosec // log message from trusted CI environment variables
139139
// Create the issue here
140140
issueData := map[string]any{
141141
"title": title,

configuration/dataplane_storage.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ func (c *Configuration) SaveClusterModeData() error {
5151
cfgCertificateFetched := cfgCluster.CertificateFetched.Load()
5252

5353
dapiStorageCluster := storagetype.Cluster{
54-
APINodesPath: misc.StringP(cfgCluster.APINodesPath.Load()),
55-
Token: misc.StringP(cfgCluster.Token.Load()),
54+
APINodesPath: new(cfgCluster.APINodesPath.Load()),
55+
Token: new(cfgCluster.Token.Load()),
5656
ClusterTLSCertDir: &c.HAProxy.ClusterTLSCertDir,
57-
ActiveBootstrapKey: misc.StringP(cfgCluster.ActiveBootstrapKey.Load()),
58-
APIRegisterPath: misc.StringP(cfgCluster.APIRegisterPath.Load()),
59-
URL: misc.StringP(cfgCluster.URL.Load()),
57+
ActiveBootstrapKey: new(cfgCluster.ActiveBootstrapKey.Load()),
58+
APIRegisterPath: new(cfgCluster.APIRegisterPath.Load()),
59+
URL: new(cfgCluster.URL.Load()),
6060
Port: &dPort,
61-
StorageDir: misc.StringP(cfgCluster.StorageDir.Load()),
62-
BootstrapKey: misc.StringP(cfgCluster.BootstrapKey.Load()),
63-
ID: misc.StringP(cfgCluster.ID.Load()),
64-
APIBasePath: misc.StringP(cfgCluster.APIBasePath.Load()),
65-
CertificateDir: misc.StringP(cfgCluster.CertificateDir.Load()),
61+
StorageDir: new(cfgCluster.StorageDir.Load()),
62+
BootstrapKey: new(cfgCluster.BootstrapKey.Load()),
63+
ID: new(cfgCluster.ID.Load()),
64+
APIBasePath: new(cfgCluster.APIBasePath.Load()),
65+
CertificateDir: new(cfgCluster.CertificateDir.Load()),
6666
CertificateFetched: &cfgCertificateFetched,
67-
Name: misc.StringP(cfgCluster.Name.Load()),
68-
Description: misc.StringP(cfgCluster.Description.Load()),
69-
ClusterID: misc.StringP(cfgCluster.ClusterID.Load()),
67+
Name: new(cfgCluster.Name.Load()),
68+
Description: new(cfgCluster.Description.Load()),
69+
ClusterID: new(cfgCluster.ClusterID.Load()),
7070
ClusterLogTargets: cfgCluster.ClusterLogTargets,
7171
}
7272
cfgStatus := c.Status.Load()

discovery/utils.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/go-openapi/strfmt"
2222
"github.com/google/uuid"
2323
"github.com/haproxytech/client-native/v6/models"
24-
"github.com/haproxytech/dataplaneapi/misc"
2524
)
2625

2726
const (
@@ -42,10 +41,10 @@ func ValidateAWSData(data *models.AwsRegion, useValidation bool) error {
4241
return err
4342
}
4443
if data.ServerSlotsBase == nil || *data.ServerSlotsBase < minimumServerSlotsBase {
45-
data.ServerSlotsBase = misc.Int64P(10)
44+
data.ServerSlotsBase = new(int64(10))
4645
}
4746
if data.ServerSlotsGrowthType == nil {
48-
data.ServerSlotsGrowthType = misc.StringP(models.AwsRegionServerSlotsGrowthTypeExponential)
47+
data.ServerSlotsGrowthType = new(models.AwsRegionServerSlotsGrowthTypeExponential)
4948
}
5049
if *data.ServerSlotsGrowthType == models.AwsRegionServerSlotsGrowthTypeLinear && (data.ServerSlotsGrowthIncrement == 0 || data.ServerSlotsGrowthIncrement < minimumServerSlotsBase) {
5150
data.ServerSlotsGrowthIncrement = minimumServerSlotsBase
@@ -67,10 +66,10 @@ func ValidateConsulData(data *models.Consul, useValidation bool) error {
6766
return err
6867
}
6968
if data.ServerSlotsBase == nil || *data.ServerSlotsBase < minimumServerSlotsBase {
70-
data.ServerSlotsBase = misc.Int64P(minimumServerSlotsBase)
69+
data.ServerSlotsBase = new(int64(minimumServerSlotsBase))
7170
}
7271
if data.ServerSlotsGrowthType == nil {
73-
data.ServerSlotsGrowthType = misc.StringP(models.ConsulServerSlotsGrowthTypeLinear)
72+
data.ServerSlotsGrowthType = new(models.ConsulServerSlotsGrowthTypeLinear)
7473
}
7574
if *data.ServerSlotsGrowthType == models.ConsulServerSlotsGrowthTypeLinear && (data.ServerSlotsGrowthIncrement == 0 || data.ServerSlotsGrowthIncrement < minimumServerSlotsBase) {
7675
data.ServerSlotsGrowthIncrement = minimumServerSlotsBase

generate/go-generate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type ParseData struct {
116116

117117
func readServerData(filePath string, pd *ParseData, structName string, attName string, groupName string, isList bool) {
118118
typeStruct := fmt.Sprintf("type %s struct {", structName)
119-
dat, err := os.ReadFile(filePath)
119+
dat, err := os.ReadFile(filePath) //nolint:gosec // paths from trusted build tool arguments
120120
if err != nil {
121121
log.Panic(err)
122122
}
@@ -345,7 +345,7 @@ func main() {
345345
}
346346
tmpl = tmpl.Funcs(funcMap)
347347
filePath = path.Join(dir, "configuration", "configuration_generated.go")
348-
f, err := os.Create(filePath)
348+
f, err := os.Create(filePath) //nolint:gosec // paths from trusted build tool arguments
349349
if err != nil {
350350
log.Panic(err)
351351
}
@@ -363,7 +363,7 @@ func main() {
363363
}
364364
tmpl = tmpl.Funcs(funcMap)
365365
filePath = path.Join(dir, "dataplaneapi_generated.go")
366-
f, err = os.Create(filePath)
366+
f, err = os.Create(filePath) //nolint:gosec // paths from trusted build tool arguments
367367
if err != nil {
368368
log.Panic(err)
369369
}
@@ -381,7 +381,7 @@ func main() {
381381
}
382382
tmpl = tmpl.Funcs(funcMap)
383383
filePath = path.Join(dir, "configuration/examples/example-full.yaml")
384-
f, err = os.Create(filePath)
384+
f, err = os.Create(filePath) //nolint:gosec // paths from trusted build tool arguments
385385
if err != nil {
386386
log.Panic(err)
387387
}
@@ -471,7 +471,7 @@ func processLine(line string) (Attribute, error) {
471471
}
472472

473473
func fmtFile(filename string) {
474-
cmd := exec.Command("gofmt", "-s", "-w", filename)
474+
cmd := exec.Command("gofmt", "-s", "-w", filename) //nolint:gosec // paths from trusted build tool arguments
475475
err := cmd.Run()
476476
if err != nil {
477477
log.Fatalf("cmd.Run() failed with %s\n", err)

handlers/bind.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (h *CreateBindHandlerImpl) Handle(parentType cnconstants.CnParentType, para
9696
return bind.NewCreateBindFrontendDefault(int(*e.Code)).WithPayload(e)
9797
}
9898

99-
pType, pName, err := bindTypeParams(nil, misc.StringP(string(parentType)), &params.ParentName)
99+
pType, pName, err := bindTypeParams(nil, new(string(parentType)), &params.ParentName)
100100
if err != nil {
101101
e := misc.HandleError(err)
102102
return bind.NewCreateBindFrontendDefault(int(*e.Code)).WithPayload(e)
@@ -148,7 +148,7 @@ func (h *DeleteBindHandlerImpl) Handle(parentType cnconstants.CnParentType, para
148148
return bind.NewDeleteBindFrontendDefault(int(*e.Code)).WithPayload(e)
149149
}
150150

151-
pType, pName, err := bindTypeParams(nil, misc.StringP(string(parentType)), &params.ParentName)
151+
pType, pName, err := bindTypeParams(nil, new(string(parentType)), &params.ParentName)
152152
if err != nil {
153153
e := misc.HandleError(err)
154154
return bind.NewDeleteBindFrontendDefault(int(*e.Code)).WithPayload(e)
@@ -186,7 +186,7 @@ func (h *GetBindHandlerImpl) Handle(parentType cnconstants.CnParentType, params
186186
return bind.NewGetBindFrontendDefault(int(*e.Code)).WithPayload(e)
187187
}
188188

189-
pType, pName, err := bindTypeParams(nil, misc.StringP(string(parentType)), &params.ParentName)
189+
pType, pName, err := bindTypeParams(nil, new(string(parentType)), &params.ParentName)
190190
if err != nil {
191191
e := misc.HandleError(err)
192192
return bind.NewGetBindFrontendDefault(int(*e.Code)).WithPayload(e)
@@ -212,7 +212,7 @@ func (h *GetAllBindHandlerImpl) Handle(parentType cnconstants.CnParentType, para
212212
return bind.NewGetAllBindFrontendDefault(int(*e.Code)).WithPayload(e)
213213
}
214214

215-
pType, pName, err := bindTypeParams(nil, misc.StringP(string(parentType)), &params.ParentName)
215+
pType, pName, err := bindTypeParams(nil, new(string(parentType)), &params.ParentName)
216216
if err != nil {
217217
e := misc.HandleError(err)
218218
return bind.NewGetAllBindFrontendDefault(int(*e.Code)).WithPayload(e)
@@ -255,7 +255,7 @@ func (h *ReplaceBindHandlerImpl) Handle(parentType cnconstants.CnParentType, par
255255
return bind.NewReplaceBindFrontendDefault(int(*e.Code)).WithPayload(e)
256256
}
257257

258-
pType, pName, err := bindTypeParams(nil, misc.StringP(string(parentType)), &params.ParentName)
258+
pType, pName, err := bindTypeParams(nil, new(string(parentType)), &params.ParentName)
259259
if err != nil {
260260
e := misc.HandleError(err)
261261
return bind.NewReplaceBindFrontendDefault(int(*e.Code)).WithPayload(e)

handlers/consul.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (c *CreateConsulHandlerImpl) Handle(params service_discovery.CreateConsulPa
6565
}
6666
if params.Data.HealthCheckPolicy != nil && *params.Data.HealthCheckPolicy == models.ConsulHealthCheckPolicyMin && params.Data.HealthCheckPolicyMin <= 0 {
6767
e := &models.Error{
68-
Message: misc.StringP("health_check_policy_min is required for 'min' health_check_policy"),
69-
Code: misc.Int64P(int(misc.ErrHTTPBadRequest)),
68+
Message: new("health_check_policy_min is required for 'min' health_check_policy"),
69+
Code: new(misc.ErrHTTPBadRequest),
7070
}
7171
return service_discovery.NewCreateConsulDefault(int(*e.Code)).WithPayload(e)
7272
}
@@ -141,8 +141,8 @@ func (c *ReplaceConsulHandlerImpl) Handle(params service_discovery.ReplaceConsul
141141
}
142142
if params.Data.HealthCheckPolicy != nil && *params.Data.HealthCheckPolicy == models.ConsulHealthCheckPolicyMin && params.Data.HealthCheckPolicyMin <= 0 {
143143
e := &models.Error{
144-
Message: misc.StringP("health_check_policy_min is required for 'min' health_check_policy"),
145-
Code: misc.Int64P(int(misc.ErrHTTPBadRequest)),
144+
Message: new("health_check_policy_min is required for 'min' health_check_policy"),
145+
Code: new(misc.ErrHTTPBadRequest),
146146
}
147147
return service_discovery.NewCreateConsulDefault(int(*e.Code)).WithPayload(e)
148148
}

handlers/fcgi_app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (c CreateFCGIAppHandlerImpl) Handle(params fcgi_app.CreateFCGIAppParams, _
4444
code := misc.ErrHTTPBadRequest
4545

4646
e := &models.Error{
47-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
47+
Message: new("Both force_reload and transaction specified, specify only one"),
4848
Code: &code,
4949
}
5050

@@ -104,7 +104,7 @@ func (d DeleteFCGIAppHandlerImpl) Handle(params fcgi_app.DeleteFCGIAppParams, _
104104
code := misc.ErrHTTPBadRequest
105105

106106
e := &models.Error{
107-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
107+
Message: new("Both force_reload and transaction specified, specify only one"),
108108
Code: &code,
109109
}
110110

@@ -224,7 +224,7 @@ func (r ReplaceFCGIAppHandlerImpl) Handle(params fcgi_app.ReplaceFCGIAppParams,
224224
code := misc.ErrHTTPBadRequest
225225

226226
e := &models.Error{
227-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
227+
Message: new("Both force_reload and transaction specified, specify only one"),
228228
Code: &code,
229229
}
230230

handlers/general_storage.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"bufio"
2020
"fmt"
2121
"io"
22+
"net/http"
2223
"os"
2324
"path/filepath"
2425
"strings"
@@ -41,8 +42,8 @@ type StorageCreateStorageGeneralFileHandlerImpl struct {
4142
func (h *StorageCreateStorageGeneralFileHandlerImpl) Handle(params storage.CreateStorageGeneralFileParams, principal any) middleware.Responder {
4243
if params.FileUpload == nil {
4344
e := &models.Error{
44-
Code: misc.Int64P(400),
45-
Message: misc.StringP("No file_upload form param specified"),
45+
Code: new(int64(http.StatusBadRequest)),
46+
Message: new("No file_upload form param specified"),
4647
}
4748
return storage.NewReplaceStorageGeneralFileBadRequest().WithPayload(e)
4849
}
@@ -199,8 +200,8 @@ func (h *StorageReplaceStorageGeneralFileHandlerImpl) Handle(params storage.Repl
199200

200201
if params.FileUpload == nil {
201202
e := &models.Error{
202-
Code: misc.Int64P(400),
203-
Message: misc.StringP("No file_upload form param specified"),
203+
Code: new(int64(http.StatusBadRequest)),
204+
Message: new("No file_upload form param specified"),
204205
}
205206
return storage.NewReplaceStorageGeneralFileBadRequest().WithPayload(e)
206207
}

handlers/http_after_response_rule.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package handlers
22

33
import (
4+
"net/http"
5+
46
"github.com/go-openapi/runtime/middleware"
57
client_native "github.com/haproxytech/client-native/v6"
68
"github.com/haproxytech/client-native/v6/models"
@@ -29,8 +31,8 @@ func (c CreateHTTPAfterResponseRuleHandlerImpl) Handle(parentType cnconstants.Cn
2931

3032
if t != "" && *params.ForceReload {
3133
e := &models.Error{
32-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
33-
Code: misc.Int64P(int(misc.ErrHTTPBadRequest)),
34+
Message: new("Both force_reload and transaction specified, specify only one"),
35+
Code: new(int64(http.StatusBadRequest)),
3436
}
3537
return http_after_response_rule.NewCreateHTTPAfterResponseRuleBackendDefault(int(*e.Code)).WithPayload(e)
3638
}
@@ -80,8 +82,8 @@ func (d DeleteHTTPAfterResponseRuleHandlerImpl) Handle(parentType cnconstants.Cn
8082

8183
if t != "" && *params.ForceReload {
8284
e := &models.Error{
83-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
84-
Code: misc.Int64P(int(misc.ErrHTTPBadRequest)),
85+
Message: new("Both force_reload and transaction specified, specify only one"),
86+
Code: new(int64(http.StatusBadRequest)),
8587
}
8688
return http_after_response_rule.NewDeleteHTTPAfterResponseRuleBackendDefault(int(*e.Code)).WithPayload(e)
8789
}
@@ -183,8 +185,8 @@ func (r ReplaceHTTPAfterResponseRuleHandlerImpl) Handle(parentType cnconstants.C
183185

184186
if t != "" && *params.ForceReload {
185187
e := &models.Error{
186-
Message: misc.StringP("Both force_reload and transaction specified, specify only one"),
187-
Code: misc.Int64P(int(misc.ErrHTTPBadRequest)),
188+
Message: new("Both force_reload and transaction specified, specify only one"),
189+
Code: new(int64(http.StatusBadRequest)),
188190
}
189191
return http_after_response_rule.NewReplaceHTTPAfterResponseRuleBackendDefault(int(*e.Code)).WithPayload(e)
190192
}

0 commit comments

Comments
 (0)