Skip to content

Commit b357f52

Browse files
committed
CLEANUP/MEDIUM: lint: upgrade linter and fix linting errors
1 parent 07c70ce commit b357f52

23 files changed

+118
-131
lines changed

cmd/gitlab-mr-checker/main.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,18 @@ func startThreadOnMergeRequest(baseURL, token, projectID string, mergeRequestIID
221221
os.Exit(1)
222222
}
223223

224-
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost,
224+
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, //nolint:gosec // URL constructed from trusted CI environment variables
225225
fmt.Sprintf("%s/projects/%s/merge_requests/%d/discussions", baseURL, url.PathEscape(projectID), mergeRequestIID), bytes.NewBuffer(threadDataBytes))
226226
if err != nil {
227-
slog.Error(err.Error())
227+
slog.Error(err.Error()) //nolint:gosec // log message from trusted CI environment variables
228228
os.Exit(1)
229229
}
230230
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
231231
req.Header.Add("Content-Type", "application/json")
232232

233-
resp, err := client.Do(req)
233+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
234234
if err != nil {
235-
slog.Error(err.Error())
235+
slog.Error(err.Error()) //nolint:gosec // log message from trusted CI environment variables
236236
os.Exit(1)
237237
}
238238
defer resp.Body.Close()
@@ -241,14 +241,14 @@ func startThreadOnMergeRequest(baseURL, token, projectID string, mergeRequestIID
241241
func getMergeRequest(baseURL, token, projectID string, mergeRequestIID int) (*MergeRequest, error) {
242242
client := &http.Client{}
243243

244-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet,
244+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, //nolint:gosec // URL constructed from trusted CI environment variables
245245
fmt.Sprintf("%s/projects/%s/merge_requests/%d", baseURL, url.PathEscape(projectID), mergeRequestIID), nil)
246246
if err != nil {
247247
return nil, err
248248
}
249249
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
250250

251-
resp, err := client.Do(req)
251+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
252252
if err != nil {
253253
return nil, err
254254
}
@@ -276,14 +276,14 @@ func getMergeRequest(baseURL, token, projectID string, mergeRequestIID int) (*Me
276276
func getMergeRequestComments(baseURL, token, projectID string, mergeRequestIID int) ([]Note, error) {
277277
client := &http.Client{}
278278

279-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet,
279+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, //nolint:gosec // URL constructed from trusted CI environment variables
280280
fmt.Sprintf("%s/projects/%s/merge_requests/%d/notes", baseURL, url.PathEscape(projectID), mergeRequestIID), nil)
281281
if err != nil {
282282
return nil, err
283283
}
284284
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
285285

286-
resp, err := client.Do(req)
286+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
287287
if err != nil {
288288
return nil, err
289289
}
@@ -309,13 +309,13 @@ func getProjectlabels(backportLabels map[string]struct{}, projectID string) erro
309309
if token == "" {
310310
return errors.New("GITLAB_TOKEN not set")
311311
}
312-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet,
312+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, //nolint:gosec // URL constructed from trusted CI environment variables
313313
fmt.Sprintf("%s/projects/%s/labels", baseURL, url.PathEscape(projectID)), nil)
314314
if err != nil {
315315
return fmt.Errorf("failed to create request: %w", err)
316316
}
317317
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
318-
resp, err := client.Do(req)
318+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
319319
if err != nil {
320320
return fmt.Errorf("failed to get project labels: %w", err)
321321
}
@@ -353,14 +353,14 @@ func getProjectlabels(backportLabels map[string]struct{}, projectID string) erro
353353
if err != nil {
354354
return fmt.Errorf("failed to marshal label data: %w", err)
355355
}
356-
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost,
356+
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, //nolint:gosec // URL constructed from trusted CI environment variables
357357
fmt.Sprintf("%s/projects/%s/labels", baseURL, url.PathEscape(projectID)), bytes.NewBuffer(labelDataBytes))
358358
if err != nil {
359359
return fmt.Errorf("failed to create request to create label: %w", err)
360360
}
361361
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
362362
req.Header.Add("Content-Type", "application/json")
363-
resp, err := client.Do(req)
363+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
364364
if err != nil {
365365
return fmt.Errorf("failed to create label %s: %w", label, err)
366366
}
@@ -387,13 +387,13 @@ func GetBranches() ([]string, error) {
387387
nextPageURL := fmt.Sprintf("%s/projects/%s/repository/branches", baseURL, url.PathEscape(projectID))
388388

389389
for nextPageURL != "" {
390-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, nextPageURL, nil)
390+
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, nextPageURL, nil) //nolint:gosec // URL constructed from trusted CI environment variables
391391
if err != nil {
392392
return nil, fmt.Errorf("failed to create request: %w", err)
393393
}
394394
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
395395

396-
resp, err := client.Do(req)
396+
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
397397
if err != nil {
398398
return nil, fmt.Errorf("failed to get branches: %w", err)
399399
}

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/aws_service_discovery_instance.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131

3232
"github.com/haproxytech/dataplaneapi/haproxy"
3333
"github.com/haproxytech/dataplaneapi/log"
34-
"github.com/haproxytech/dataplaneapi/misc"
3534
)
3635

3736
const (
@@ -94,7 +93,7 @@ func (a awsService) GetServers() (servers []configuration.ServiceServer) {
9493
var port *int64
9594

9695
if parsedPort > 0 {
97-
port = misc.Int64P(parsedPort)
96+
port = new(int64(parsedPort))
9897
}
9998

10099
servers = append(servers, configuration.ServiceServer{

discovery/consul_service_discovery_instance.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/haproxytech/client-native/v6/models"
3030

3131
"github.com/haproxytech/dataplaneapi/log"
32-
"github.com/haproxytech/dataplaneapi/misc"
3332
jsoniter "github.com/json-iterator/go"
3433
)
3534

@@ -184,15 +183,15 @@ func (c *consulInstance) convertToServers(nodes []*serviceEntry) []configuration
184183
Address: node.Service.Address,
185184
}
186185
if node.Service.Port > 0 {
187-
ss.Port = misc.Int64P(node.Service.Port)
186+
ss.Port = new(int64(node.Service.Port))
188187
}
189188
servers = append(servers, ss)
190189
} else {
191190
ss := configuration.ServiceServer{
192191
Address: node.Node.Address,
193192
}
194193
if node.Service.Port > 0 {
195-
ss.Port = misc.Int64P(node.Service.Port)
194+
ss.Port = new(int64(node.Service.Port))
196195
}
197196
servers = append(servers, ss)
198197
}

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
}

0 commit comments

Comments
 (0)