Skip to content

Commit 18a9f06

Browse files
committed
fix(lint) configure linter after update, fix linting issues
1 parent 45e455d commit 18a9f06

File tree

16 files changed

+70
-54
lines changed

16 files changed

+70
-54
lines changed

golang-ci.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ linters:
4747
gosec:
4848
excludes:
4949
# Suppressions: (see https://github.com/securego/gosec#available-rules for details)
50+
- G101 # "Look for hardcoded credentials" -> a lot of false positives in descriptions for resources like mariadb/credential
5051
- G104 # "Audit errors not checked" -> which we don't need and is a badly implemented version of errcheck
5152
- G102 # "Bind to all interfaces" -> since this is normal in k8s
5253
- G304 # "File path provided as taint input" -> too many false positives
@@ -73,13 +74,27 @@ linters:
7374
- name: atomic
7475
- name: empty-lines
7576
- name: early-return
77+
staticcheck:
78+
checks:
79+
# default from https://golangci-lint.run/docs/linters/configuration/#staticcheck
80+
- all
81+
- "-ST1000"
82+
- "-ST1003"
83+
- "-ST1016"
84+
- "-ST1020"
85+
- "-ST1021"
86+
- "-ST1022"
87+
# customizations
88+
- "-SA1019" # disable deprecation errors while we switch over to the SDK structure with multi API version support
89+
- "-QF1001" # disable 'could apply De Morgan's law': readability of boolean expressions is subjective and should be decided on a case-by-case basis
90+
- "-QF1012" # disable 'use fmt.Fprintf instead' Fprintf returns bytes written and an error, which we'd have to handle/ignore to appease some other linter
7691
exclusions:
7792
generated: lax
7893
rules:
79-
# disable deprecation errors while we switch over to the SDK structure with multi API version support
8094
- linters:
81-
- staticcheck
82-
text: 'SA1019:'
95+
- gocritic
96+
text: 'dupOption'
97+
path: _acc_test\.go
8398
paths:
8499
- third_party$
85100
- builtin$

stackit/internal/services/authorization/roleassignments/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type roleAssignmentResource struct {
7070

7171
// Metadata returns the resource type name.
7272
func (r *roleAssignmentResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
73-
resp.TypeName = fmt.Sprintf("%s_authorization_%s_role_assignment", req.ProviderTypeName, strings.Replace(r.apiName, "-", "_", -1))
73+
resp.TypeName = fmt.Sprintf("%s_authorization_%s_role_assignment", req.ProviderTypeName, strings.ReplaceAll(r.apiName, "-", "_"))
7474
}
7575

7676
// Configure adds the provider configured client to the resource.

stackit/internal/services/authorization/utils/util_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func TestLockAssignment(t *testing.T) {
172172
// Wait a tiny bit to ensure G1 has started and acquired the lock
173173
time.Sleep(10 * time.Millisecond)
174174
wg.Go(func() {
175-
176175
// This should block until G1 releases the lock
177176
unlock := LockAssignment(key)
178177
defer unlock()

stackit/internal/services/cdn/distribution/resource.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
570570

571571
configPatchBackend := &cdn.ConfigPatchBackend{}
572572

573-
if configModel.Backend.Type == "http" {
573+
switch configModel.Backend.Type {
574+
case "http":
574575
geofencingPatch := map[string][]string{}
575576
if configModel.Backend.Geofencing != nil {
576577
gf := make(map[string][]string)
@@ -594,7 +595,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
594595
Type: new("http"),
595596
Geofencing: &geofencingPatch,
596597
}
597-
} else if configModel.Backend.Type == "bucket" {
598+
case "bucket":
598599
configPatchBackend.BucketBackendPatch = &cdn.BucketBackendPatch{
599600
Type: new("bucket"),
600601
BucketUrl: configModel.Backend.BucketURL,
@@ -713,23 +714,23 @@ func mapFields(ctx context.Context, distribution *cdn.Distribution, model *Model
713714
}
714715

715716
if distribution.ProjectId == nil {
716-
return fmt.Errorf("Project ID not present")
717+
return fmt.Errorf("'Project ID' not present")
717718
}
718719

719720
if distribution.Id == nil {
720721
return fmt.Errorf("CDN distribution ID not present")
721722
}
722723

723724
if distribution.CreatedAt == nil {
724-
return fmt.Errorf("CreatedAt missing in response")
725+
return fmt.Errorf("'CreatedAt' missing in response")
725726
}
726727

727728
if distribution.UpdatedAt == nil {
728-
return fmt.Errorf("UpdatedAt missing in response")
729+
return fmt.Errorf("'UpdatedAt' missing in response")
729730
}
730731

731732
if distribution.Status == nil {
732-
return fmt.Errorf("Status missing in response")
733+
return fmt.Errorf("'Status' missing in response")
733734
}
734735

735736
model.ID = utils.BuildInternalTerraformId(*distribution.ProjectId, *distribution.Id)
@@ -1083,7 +1084,8 @@ func convertConfig(ctx context.Context, model *Model) (*cdn.Config, error) {
10831084
BlockedCountries: &blockedCountries,
10841085
}
10851086

1086-
if configModel.Backend.Type == "http" {
1087+
switch configModel.Backend.Type {
1088+
case "http":
10871089
originRequestHeaders := map[string]string{}
10881090
if configModel.Backend.OriginRequestHeaders != nil {
10891091
maps.Copy(originRequestHeaders, *configModel.Backend.OriginRequestHeaders)
@@ -1094,7 +1096,7 @@ func convertConfig(ctx context.Context, model *Model) (*cdn.Config, error) {
10941096
Type: new("http"),
10951097
Geofencing: &geofencing,
10961098
}
1097-
} else if configModel.Backend.Type == "bucket" {
1099+
case "bucket":
10981100
cdnConfig.Backend.BucketBackend = &cdn.BucketBackend{
10991101
Type: new("bucket"),
11001102
BucketUrl: configModel.Backend.BucketURL,

stackit/internal/services/iaas/networkarea/resource_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,10 @@ func TestUpdateNetworkRanges(t *testing.T) {
10861086
// Setup server and client
10871087
router := mux.NewRouter()
10881088
router.HandleFunc("/v2/organizations/{organizationId}/network-areas/{areaId}/regions/{region}/network-ranges", func(w http.ResponseWriter, r *http.Request) {
1089-
if r.Method == "GET" {
1089+
switch r.Method {
1090+
case http.MethodGet:
10901091
getAllNetworkRangesHandler(w, r)
1091-
} else if r.Method == "POST" {
1092+
case http.MethodPost:
10921093
createNetworkRangeHandler(w, r)
10931094
}
10941095
})

stackit/internal/services/iaas/networkarearegion/resource_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,10 @@ func Test_updateIpv4NetworkRanges(t *testing.T) {
905905
// Setup server and client
906906
router := mux.NewRouter()
907907
router.HandleFunc("/v2/organizations/{organizationId}/network-areas/{areaId}/regions/{region}/network-ranges", func(w http.ResponseWriter, r *http.Request) {
908-
if r.Method == "GET" {
908+
switch r.Method {
909+
case http.MethodGet:
909910
getAllNetworkRangesHandler(w, r)
910-
} else if r.Method == "POST" {
911+
case http.MethodPost:
911912
createNetworkRangeHandler(w, r)
912913
}
913914
})

stackit/internal/services/iaas/server/resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ func (r *serverResource) updateServerAttributes(ctx context.Context, model, stat
711711
// Generate API request body from model
712712
payload, err := toUpdatePayload(ctx, model, stateModel.Labels)
713713
if err != nil {
714-
return nil, fmt.Errorf("Creating API payload: %w", err)
714+
return nil, fmt.Errorf("creating API payload: %w", err)
715715
}
716716
projectId := model.ProjectId.ValueString()
717717
serverId := model.ServerId.ValueString()
@@ -720,7 +720,7 @@ func (r *serverResource) updateServerAttributes(ctx context.Context, model, stat
720720
// Update existing server
721721
updatedServer, err = r.client.UpdateServer(ctx, projectId, region, serverId).UpdateServerPayload(*payload).Execute()
722722
if err != nil {
723-
return nil, fmt.Errorf("Calling API: %w", err)
723+
return nil, fmt.Errorf("calling API: %w", err)
724724
}
725725

726726
// Update machine type
@@ -731,7 +731,7 @@ func (r *serverResource) updateServerAttributes(ctx context.Context, model, stat
731731
}
732732
err := r.client.ResizeServer(ctx, projectId, region, serverId).ResizeServerPayload(payload).Execute()
733733
if err != nil {
734-
return nil, fmt.Errorf("Resizing the server, calling API: %w", err)
734+
return nil, fmt.Errorf("resizing the server, calling API: %w", err)
735735
}
736736

737737
_, err = wait.ResizeServerWaitHandler(ctx, r.client, projectId, region, serverId).WaitWithContext(ctx)

stackit/internal/services/iaas/volume/datasource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func mapDatasourceFields(ctx context.Context, volumeResp *iaas.Volume, model *Da
226226
} else if volumeResp.Id != nil {
227227
volumeId = *volumeResp.Id
228228
} else {
229-
return fmt.Errorf("Volume id not present")
229+
return fmt.Errorf("volume id not present")
230230
}
231231

232232
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, volumeId)

stackit/internal/services/iaas/volume/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ func mapFields(ctx context.Context, volumeResp *iaas.Volume, model *Model, regio
694694
} else if volumeResp.Id != nil {
695695
volumeId = *volumeResp.Id
696696
} else {
697-
return fmt.Errorf("Volume id not present")
697+
return fmt.Errorf("volume id not present")
698698
}
699699

700700
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, volumeId)

stackit/internal/services/observability/instance/resource.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,30 +2540,30 @@ func (r *instanceResource) getAlertConfigs(ctx context.Context, alertConfig *ale
25402540
if utils.IsUndefined(model.AlertConfig) {
25412541
*alertConfig, err = getMockAlertConfig(ctx)
25422542
if err != nil {
2543-
return fmt.Errorf("Getting mock alert config: %w", err)
2543+
return fmt.Errorf("getting mock alert config: %w", err)
25442544
}
25452545
}
25462546

25472547
alertConfigPayload, err := toUpdateAlertConfigPayload(ctx, alertConfig)
25482548
if err != nil {
2549-
return fmt.Errorf("Building alert config payload: %w", err)
2549+
return fmt.Errorf("building alert config payload: %w", err)
25502550
}
25512551

25522552
if alertConfigPayload != nil {
25532553
_, err = r.client.UpdateAlertConfigs(ctx, instanceId, projectId).UpdateAlertConfigsPayload(*alertConfigPayload).Execute()
25542554
if err != nil {
2555-
return fmt.Errorf("Setting alert config: %w", err)
2555+
return fmt.Errorf("setting alert config: %w", err)
25562556
}
25572557
}
25582558

25592559
alertConfigResp, err := r.client.GetAlertConfigs(ctx, instanceId, projectId).Execute()
25602560
if err != nil {
2561-
return fmt.Errorf("Calling API to get alert config: %w", err)
2561+
return fmt.Errorf("calling API to get alert config: %w", err)
25622562
}
25632563
// Map response body to schema
25642564
err = mapAlertConfigField(ctx, alertConfigResp, model)
25652565
if err != nil {
2566-
return fmt.Errorf("Processing API response for the alert config: %w", err)
2566+
return fmt.Errorf("processing API response for the alert config: %w", err)
25672567
}
25682568
return nil
25692569
}
@@ -2576,7 +2576,7 @@ func (r *instanceResource) getTracesRetention(ctx context.Context, model *Model)
25762576
if tracesRetentionDays != nil {
25772577
tracesResp, err := r.client.GetTracesConfigs(ctx, instanceId, projectId).Execute()
25782578
if err != nil {
2579-
return fmt.Errorf("Getting traces retention policy: %w", err)
2579+
return fmt.Errorf("getting traces retention policy: %w", err)
25802580
}
25812581
if tracesResp == nil {
25822582
return fmt.Errorf("nil response")
@@ -2585,18 +2585,18 @@ func (r *instanceResource) getTracesRetention(ctx context.Context, model *Model)
25852585
retentionDays := fmt.Sprintf("%dh", *tracesRetentionDays*24)
25862586
_, err = r.client.UpdateTracesConfigs(ctx, instanceId, projectId).UpdateTracesConfigsPayload(observability.UpdateTracesConfigsPayload{Retention: &retentionDays}).Execute()
25872587
if err != nil {
2588-
return fmt.Errorf("Setting traces retention policy: %w", err)
2588+
return fmt.Errorf("setting traces retention policy: %w", err)
25892589
}
25902590
}
25912591

25922592
tracesResp, err := r.client.GetTracesConfigsExecute(ctx, instanceId, projectId)
25932593
if err != nil {
2594-
return fmt.Errorf("Getting traces retention policy: %w", err)
2594+
return fmt.Errorf("getting traces retention policy: %w", err)
25952595
}
25962596

25972597
err = mapTracesRetentionField(tracesResp, model)
25982598
if err != nil {
2599-
return fmt.Errorf("Processing API response for the traces retention %w", err)
2599+
return fmt.Errorf("processing API response for the traces retention %w", err)
26002600
}
26012601

26022602
return nil
@@ -2610,7 +2610,7 @@ func (r *instanceResource) getLogsRetention(ctx context.Context, model *Model) e
26102610
if logsRetentionDays != nil {
26112611
logsResp, err := r.client.GetLogsConfigs(ctx, instanceId, projectId).Execute()
26122612
if err != nil {
2613-
return fmt.Errorf("Getting logs retention policy: %w", err)
2613+
return fmt.Errorf("getting logs retention policy: %w", err)
26142614
}
26152615
if logsResp == nil {
26162616
return fmt.Errorf("nil response")
@@ -2619,18 +2619,18 @@ func (r *instanceResource) getLogsRetention(ctx context.Context, model *Model) e
26192619
retentionDays := fmt.Sprintf("%dh", *logsRetentionDays*24)
26202620
_, err = r.client.UpdateLogsConfigs(ctx, instanceId, projectId).UpdateLogsConfigsPayload(observability.UpdateLogsConfigsPayload{Retention: &retentionDays}).Execute()
26212621
if err != nil {
2622-
return fmt.Errorf("Setting logs retention policy: %w", err)
2622+
return fmt.Errorf("setting logs retention policy: %w", err)
26232623
}
26242624
}
26252625

26262626
logsResp, err := r.client.GetLogsConfigsExecute(ctx, instanceId, projectId)
26272627
if err != nil {
2628-
return fmt.Errorf("Getting logs retention policy: %w", err)
2628+
return fmt.Errorf("getting logs retention policy: %w", err)
26292629
}
26302630

26312631
err = mapLogsRetentionField(logsResp, model)
26322632
if err != nil {
2633-
return fmt.Errorf("Processing API response for the logs retention %w", err)
2633+
return fmt.Errorf("processing API response for the logs retention %w", err)
26342634
}
26352635

26362636
return nil
@@ -2648,29 +2648,29 @@ func (r *instanceResource) getMetricsRetention(ctx context.Context, model *Model
26482648
// Need to get the metrics retention policy because update endpoint is a PUT and we need to send all fields
26492649
metricsResp, err := r.client.GetMetricsStorageRetentionExecute(ctx, instanceId, projectId)
26502650
if err != nil {
2651-
return fmt.Errorf("Getting metrics retention policy: %w", err)
2651+
return fmt.Errorf("getting metrics retention policy: %w", err)
26522652
}
26532653

26542654
metricsRetentionPayload, err := toUpdateMetricsStorageRetentionPayload(metricsRetentionDays, metricsRetentionDays5mDownsampling, metricsRetentionDays1hDownsampling, metricsResp)
26552655
if err != nil {
2656-
return fmt.Errorf("Building metrics retention policy payload: %w", err)
2656+
return fmt.Errorf("building metrics retention policy payload: %w", err)
26572657
}
26582658
_, err = r.client.UpdateMetricsStorageRetention(ctx, instanceId, projectId).UpdateMetricsStorageRetentionPayload(*metricsRetentionPayload).Execute()
26592659
if err != nil {
2660-
return fmt.Errorf("Setting metrics retention policy: %w", err)
2660+
return fmt.Errorf("setting metrics retention policy: %w", err)
26612661
}
26622662
}
26632663

26642664
// Get metrics retention policy after update
26652665
metricsResp, err := r.client.GetMetricsStorageRetentionExecute(ctx, instanceId, projectId)
26662666
if err != nil {
2667-
return fmt.Errorf("Getting metrics retention policy: %w", err)
2667+
return fmt.Errorf("getting metrics retention policy: %w", err)
26682668
}
26692669

26702670
// Map response body to schema
26712671
err = mapMetricsRetentionField(metricsResp, model)
26722672
if err != nil {
2673-
return fmt.Errorf("Processing API response for the metrics retention %w", err)
2673+
return fmt.Errorf("processing API response for the metrics retention %w", err)
26742674
}
26752675
return nil
26762676
}

0 commit comments

Comments
 (0)