Skip to content

Commit 438904e

Browse files
authored
Update golangci-lint to 1.64.2 (#3012)
Remove deprecated `tenv`, some more improvements
1 parent da397ba commit 438904e

25 files changed

+97
-95
lines changed

.golangci.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ linters-settings:
148148
exported-fields-are-used: false
149149
# Mark all local variables as used.
150150
local-variables-are-used: false
151-
tenv:
152-
all: true
153-
151+
usetesting:
152+
os-setenv: true
153+
os-temp-dir: true
154154
prealloc:
155155
simple: true
156156
range-loops: true
File renamed without changes.

bin/golangci-lint

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.golangci-lint-1.63.4.pkg
1+
.golangci-lint-1.64.2.pkg

cmd/root.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package cmd
1919

2020
import (
21+
"errors"
2122
"fmt"
2223

2324
"github.com/elastic/beats/v7/libbeat/cmd"
@@ -57,12 +58,12 @@ func cloudbeatCfg(rawIn *proto.UnitExpectedConfig, agentInfo *client.AgentInfo)
5758
config := rawIn.Source.AsMap()
5859
packagePolicyID, ok := config["package_policy_id"]
5960
if !ok {
60-
return nil, fmt.Errorf("'package_policy_id' element does not exist")
61+
return nil, errors.New("'package_policy_id' element does not exist")
6162
}
6263

6364
packagePolicyRevision, ok := config["revision"]
6465
if !ok {
65-
return nil, fmt.Errorf("'revision' element does not exist")
66+
return nil, errors.New("'revision' element does not exist")
6667
}
6768

6869
for i := range modules {

deploy/asset-inventory-cloudformation/config.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package main
2222

2323
import (
24+
"errors"
2425
"fmt"
2526
"reflect"
2627
"strings"
@@ -95,19 +96,19 @@ func bindEnvs(iface any, parts ...string) error {
9596

9697
func validateConfig(cfg *config) error {
9798
if cfg.StackName == "" {
98-
return fmt.Errorf("missing required flag: STACK_NAME")
99+
return errors.New("missing required flag: STACK_NAME")
99100
}
100101

101102
if cfg.FleetURL == "" {
102-
return fmt.Errorf("missing required flag: FLEET_URL")
103+
return errors.New("missing required flag: FLEET_URL")
103104
}
104105

105106
if cfg.EnrollmentToken == "" {
106-
return fmt.Errorf("missing required flag: ENROLLMENT_TOKEN")
107+
return errors.New("missing required flag: ENROLLMENT_TOKEN")
107108
}
108109

109110
if cfg.ElasticAgentVersion == "" {
110-
return fmt.Errorf("missing required flag: ELASTIC_AGENT_VERSION")
111+
return errors.New("missing required flag: ELASTIC_AGENT_VERSION")
111112
}
112113

113114
if cfg.Dev != nil {
@@ -119,7 +120,7 @@ func validateConfig(cfg *config) error {
119120

120121
func validateDevConfig(cfg *devConfig) error {
121122
if cfg.AllowSSH && cfg.KeyName == "" {
122-
return fmt.Errorf("missing required flag for SSH enablement mode: DEV.KEY_NAME")
123+
return errors.New("missing required flag for SSH enablement mode: DEV.KEY_NAME")
123124
}
124125

125126
return nil

deploy/cloudformation/config.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package main
2222

2323
import (
24+
"errors"
2425
"fmt"
2526
"reflect"
2627
"slices"
@@ -104,19 +105,19 @@ func bindEnvs(iface any, parts ...string) error {
104105

105106
func validateConfig(cfg *config) error {
106107
if cfg.StackName == "" {
107-
return fmt.Errorf("missing required flag: STACK_NAME")
108+
return errors.New("missing required flag: STACK_NAME")
108109
}
109110

110111
if cfg.FleetURL == "" {
111-
return fmt.Errorf("missing required flag: FLEET_URL")
112+
return errors.New("missing required flag: FLEET_URL")
112113
}
113114

114115
if cfg.EnrollmentToken == "" {
115-
return fmt.Errorf("missing required flag: ENROLLMENT_TOKEN")
116+
return errors.New("missing required flag: ENROLLMENT_TOKEN")
116117
}
117118

118119
if cfg.ElasticAgentVersion == "" {
119-
return fmt.Errorf("missing required flag: ELASTIC_AGENT_VERSION")
120+
return errors.New("missing required flag: ELASTIC_AGENT_VERSION")
120121
}
121122

122123
if cfg.Dev != nil {
@@ -133,7 +134,7 @@ func validateConfig(cfg *config) error {
133134

134135
func validateDevConfig(cfg *devConfig) error {
135136
if cfg.AllowSSH && cfg.KeyName == "" {
136-
return fmt.Errorf("missing required flag for SSH enablement mode: DEV.KEY_NAME")
137+
return errors.New("missing required flag for SSH enablement mode: DEV.KEY_NAME")
137138
}
138139

139140
return nil

internal/flavors/assetinventory/strategy.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package assetinventory
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324
"strings"
2425
"time"
@@ -63,7 +64,7 @@ func (s *strategy) NewAssetInventory(ctx context.Context, client beat.Client) (i
6364
case config.ProviderGCP:
6465
fetchers, err = s.initGcpFetchers(ctx)
6566
case "":
66-
err = fmt.Errorf("missing config.v1.asset_inventory_provider setting")
67+
err = errors.New("missing config.v1.asset_inventory_provider setting")
6768
default:
6869
err = fmt.Errorf("unsupported Asset Inventory provider %q", s.cfg.AssetInventoryProvider)
6970
}

internal/flavors/benchmark/eks.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package benchmark
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324

2425
awssdk "github.com/aws/aws-sdk-go-v2/aws"
@@ -127,16 +128,16 @@ func (k *EKS) getEksAwsConfig(ctx context.Context, cfg *config.Config) (awssdk.C
127128

128129
func (k *EKS) checkDependencies() error {
129130
if k.AWSIdentityProvider == nil {
130-
return fmt.Errorf("aws identity provider is uninitialized")
131+
return errors.New("aws identity provider is uninitialized")
131132
}
132133
if k.ClientProvider == nil {
133-
return fmt.Errorf("kubernetes client provider is uninitialized")
134+
return errors.New("kubernetes client provider is uninitialized")
134135
}
135136
if k.EKSClusterNameProvider == nil {
136-
return fmt.Errorf("eks cluster name provider is uninitialized")
137+
return errors.New("eks cluster name provider is uninitialized")
137138
}
138139
if k.AWSMetadataProvider == nil {
139-
return fmt.Errorf("aws metadata provider is uninitialized")
140+
return errors.New("aws metadata provider is uninitialized")
140141
}
141142
return nil
142143
}

internal/inventory/azurefetcher/fetcher_activedirectory_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package azurefetcher
2020
import (
2121
"bytes"
2222
"context"
23-
"fmt"
23+
"errors"
2424
"testing"
2525
"time"
2626

@@ -175,7 +175,7 @@ func TestActiveDirectoryFetcher_FetchError(t *testing.T) {
175175

176176
provider := newMockActivedirectoryProvider(t)
177177
provider.EXPECT().ListServicePrincipals(mock.Anything).Return(
178-
[]*models.ServicePrincipal{}, fmt.Errorf("! error listing service principals"),
178+
[]*models.ServicePrincipal{}, errors.New("! error listing service principals"),
179179
)
180180
provider.EXPECT().ListDirectoryRoles(mock.Anything).Maybe().Return(
181181
[]*models.DirectoryRole{}, nil,

internal/launcher/launcher.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (l *launcher) waitForUpdates() (*config.C, error) {
248248

249249
case update, ok := <-l.reloader.Channel():
250250
if !ok {
251-
return nil, fmt.Errorf("reloader channel unexpectedly closed")
251+
return nil, errors.New("reloader channel unexpectedly closed")
252252
}
253253

254254
l.log.Infof("Launcher will restart %s to apply the configuration update", l.name)
@@ -285,14 +285,14 @@ func (l *launcher) reconfigureWait(timeout time.Duration) (*config.C, error) {
285285
for {
286286
select {
287287
case <-l.beaterErr:
288-
return nil, fmt.Errorf("error channel closed")
288+
return nil, errors.New("error channel closed")
289289

290290
case <-timer:
291291
return nil, fmt.Errorf("timed out waiting for reconfiguration after %s", time.Since(start))
292292

293293
case update, ok := <-l.reloader.Channel():
294294
if !ok {
295-
return nil, fmt.Errorf("reconfiguration channel is closed")
295+
return nil, errors.New("reconfiguration channel is closed")
296296
}
297297

298298
if l.validator != nil {

internal/launcher/launcher_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package launcher
2222

2323
import (
2424
"errors"
25-
"fmt"
2625
"reflect"
2726
"testing"
2827
"time"
@@ -120,7 +119,7 @@ type validatorMock struct {
120119
func (v *validatorMock) Validate(cfg *config.C) error {
121120
var err error
122121
if !reflect.DeepEqual(cfg, v.expected) {
123-
err = fmt.Errorf("mock validation failed")
122+
err = errors.New("mock validation failed")
124123
}
125124

126125
return err

internal/resources/fetching/fetchers/aws/ecr_fetcher_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fetchers
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324
"regexp"
2425
"sort"
@@ -292,7 +293,7 @@ func (s *EcrFetcherTestSuite) TestCreateFetcherErrorCases() {
292293
Name: "cloudbeat",
293294
},
294295
},
295-
fmt.Errorf("ecr error"),
296+
errors.New("ecr error"),
296297
},
297298
}
298299
for _, test := range tests {

internal/resources/fetching/fetchers/aws/elb_fetcher_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fetchers
1919

2020
import (
2121
"context"
22+
"errors"
2223
"fmt"
2324
"regexp"
2425
"testing"
@@ -169,7 +170,7 @@ func (s *ElbFetcherTestSuite) TestCreateFetcherErrorCases() {
169170
Hostname: "adda9cdc89b13452e92d48be46858d37-1423035038.us-east-2.elb.amazonaws.com",
170171
},
171172
},
172-
fmt.Errorf("elb error")},
173+
errors.New("elb error")},
173174
}
174175
for _, test := range tests {
175176
kubeclient := k8sfake.NewSimpleClientset()

internal/resources/fetching/fetchers/aws/monitoring_fetcher_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package fetchers
1919

2020
import (
2121
"context"
22-
"fmt"
22+
"errors"
2323
"testing"
2424
"time"
2525

@@ -77,13 +77,13 @@ func TestMonitoringFetcher_Fetch(t *testing.T) {
7777
monitoring: clientMocks{
7878
"AggregateResources": [2]mocks{
7979
{mock.Anything},
80-
{nil, fmt.Errorf("failed to run provider")},
80+
{nil, errors.New("failed to run provider")},
8181
},
8282
},
8383
securityhub: clientMocks{
8484
"Describe": [2]mocks{
8585
{mock.Anything},
86-
{[]securityhub.SecurityHub{{}}, fmt.Errorf("failed to run provider")},
86+
{[]securityhub.SecurityHub{{}}, errors.New("failed to run provider")},
8787
},
8888
},
8989
},
@@ -92,7 +92,7 @@ func TestMonitoringFetcher_Fetch(t *testing.T) {
9292
monitoring: clientMocks{
9393
"AggregateResources": [2]mocks{
9494
{mock.Anything},
95-
{nil, fmt.Errorf("failed to run provider")},
95+
{nil, errors.New("failed to run provider")},
9696
},
9797
},
9898
securityhub: clientMocks{

internal/resources/fetching/fetchers/azure/assets_fetcher.go

+15-23
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,23 @@ type typePair struct {
5151
Type string
5252
}
5353

54-
func newPair(subType string, tpe string) typePair {
55-
return typePair{
56-
SubType: subType,
57-
Type: tpe,
58-
}
59-
}
60-
6154
var AzureAssetTypeToTypePair = map[string]typePair{
62-
inventory.ClassicStorageAccountAssetType: newPair(fetching.AzureClassicStorageAccountType, fetching.CloudStorage),
63-
inventory.DiskAssetType: newPair(fetching.AzureDiskType, fetching.CloudCompute),
64-
inventory.DocumentDBDatabaseAccountAssetType: newPair(fetching.AzureDocumentDBDatabaseAccountType, fetching.CloudDatabase),
65-
inventory.MySQLDBAssetType: newPair(fetching.AzureMySQLDBType, fetching.CloudDatabase),
66-
inventory.FlexibleMySQLDBAssetType: newPair(fetching.AzureFlexibleMySQLDBType, fetching.CloudDatabase),
67-
inventory.NetworkWatchersFlowLogAssetType: newPair(fetching.AzureNetworkWatchersFlowLogType, fetching.MonitoringIdentity),
68-
inventory.FlexiblePostgreSQLDBAssetType: newPair(fetching.AzureFlexiblePostgreSQLDBType, fetching.CloudDatabase),
69-
inventory.PostgreSQLDBAssetType: newPair(fetching.AzurePostgreSQLDBType, fetching.CloudDatabase),
70-
inventory.SQLServersAssetType: newPair(fetching.AzureSQLServerType, fetching.CloudDatabase),
71-
inventory.StorageAccountAssetType: newPair(fetching.AzureStorageAccountType, fetching.CloudStorage),
72-
inventory.VirtualMachineAssetType: newPair(fetching.AzureVMType, fetching.CloudCompute),
73-
inventory.WebsitesAssetType: newPair(fetching.AzureWebSiteType, fetching.CloudCompute),
74-
inventory.VaultAssetType: newPair(fetching.AzureVaultType, fetching.KeyManagement),
75-
inventory.RoleDefinitionsType: newPair(fetching.AzureRoleDefinitionType, fetching.CloudIdentity),
76-
55+
inventory.ClassicStorageAccountAssetType: {fetching.AzureClassicStorageAccountType, fetching.CloudStorage},
56+
inventory.DiskAssetType: {fetching.AzureDiskType, fetching.CloudCompute},
57+
inventory.DocumentDBDatabaseAccountAssetType: {fetching.AzureDocumentDBDatabaseAccountType, fetching.CloudDatabase},
58+
inventory.MySQLDBAssetType: {fetching.AzureMySQLDBType, fetching.CloudDatabase},
59+
inventory.FlexibleMySQLDBAssetType: {fetching.AzureFlexibleMySQLDBType, fetching.CloudDatabase},
60+
inventory.NetworkWatchersFlowLogAssetType: {fetching.AzureNetworkWatchersFlowLogType, fetching.MonitoringIdentity},
61+
inventory.FlexiblePostgreSQLDBAssetType: {fetching.AzureFlexiblePostgreSQLDBType, fetching.CloudDatabase},
62+
inventory.PostgreSQLDBAssetType: {fetching.AzurePostgreSQLDBType, fetching.CloudDatabase},
63+
inventory.SQLServersAssetType: {fetching.AzureSQLServerType, fetching.CloudDatabase},
64+
inventory.StorageAccountAssetType: {fetching.AzureStorageAccountType, fetching.CloudStorage},
65+
inventory.VirtualMachineAssetType: {fetching.AzureVMType, fetching.CloudCompute},
66+
inventory.WebsitesAssetType: {fetching.AzureWebSiteType, fetching.CloudCompute},
67+
inventory.VaultAssetType: {fetching.AzureVaultType, fetching.KeyManagement},
68+
inventory.RoleDefinitionsType: {fetching.AzureRoleDefinitionType, fetching.CloudIdentity},
7769
// This asset type is used only for enrichment purposes, but is sent to OPA layer, producing no findings.
78-
inventory.NetworkSecurityGroupAssetType: newPair(fetching.AzureNetworkSecurityGroupType, fetching.MonitoringIdentity),
70+
inventory.NetworkSecurityGroupAssetType: {fetching.AzureNetworkSecurityGroupType, fetching.MonitoringIdentity},
7971
}
8072

8173
// In order to simplify the mappings, we are trying to query all AzureAssetTypeToTypePair on every asset group

internal/resources/fetching/fetchers/azure/batch_fetcher.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ type AzureBatchAssetFetcher struct {
4141
}
4242

4343
var AzureBatchAssets = map[string]typePair{
44-
inventory.ActivityLogAlertAssetType: newPair(fetching.AzureActivityLogAlertType, fetching.MonitoringIdentity),
45-
inventory.ApplicationInsights: newPair(fetching.AzureInsightsComponentType, fetching.MonitoringIdentity),
46-
inventory.BastionAssetType: newPair(fetching.AzureBastionType, fetching.CloudDns),
44+
inventory.ActivityLogAlertAssetType: {fetching.AzureActivityLogAlertType, fetching.MonitoringIdentity},
45+
inventory.ApplicationInsights: {fetching.AzureInsightsComponentType, fetching.MonitoringIdentity},
46+
inventory.BastionAssetType: {fetching.AzureBastionType, fetching.CloudDns},
4747
}
4848

4949
// In order to simplify the mappings, we are trying to query all AzureBatchAssets on every asset group

internal/resources/fetching/fetchers/azure/locations_network_watcher_batch_fetcher.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ func (f *AzureLocationsNetworkWatcherAssetBatchFetcher) fetchNetworkWatchersPerL
9292
case f.resourceCh <- fetching.ResourceInfo{
9393
CycleMetadata: metadata,
9494
Resource: &NetworkWatchersBatchedByLocationResource{
95-
typePair: newPair(fetching.AzureNetworkWatchersType, fetching.MonitoringIdentity),
95+
typePair: typePair{
96+
SubType: fetching.AzureNetworkWatchersType,
97+
Type: fetching.MonitoringIdentity,
98+
},
9699
Subscription: subscription,
97100
Location: location,
98101
NetworkWatchers: groupedWatchers[location.Name],

internal/resources/fetching/fetchers/azure/locations_network_watcher_batch_fetcher_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ func batchedNetworkWatcherByLocationResourceInfo(cycle cycle.Metadata, subscript
330330
return fetching.ResourceInfo{
331331
CycleMetadata: cycle,
332332
Resource: &NetworkWatchersBatchedByLocationResource{
333-
typePair: newPair(fetching.AzureNetworkWatchersType, fetching.MonitoringIdentity),
333+
typePair: typePair{
334+
SubType: fetching.AzureNetworkWatchersType,
335+
Type: fetching.MonitoringIdentity,
336+
},
334337
Subscription: subscription,
335338
Location: azAssetLocation(subscription.ShortID, location),
336339
NetworkWatchers: networkWatchers,

internal/resources/fetching/fetchers/azure/security_fetcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func NewAzureSecurityAssetFetcher(log *clog.Logger, ch chan fetching.ResourceInf
4444
}
4545

4646
var AzureSecurityAssetTypeToTypePair = map[string]typePair{
47-
inventory.SecurityContactsAssetType: newPair(fetching.AzureSecurityContactsType, fetching.MonitoringIdentity),
48-
inventory.SecurityAutoProvisioningSettingsType: newPair(fetching.AzureAutoProvisioningSettingsType, fetching.MonitoringIdentity),
47+
inventory.SecurityContactsAssetType: {fetching.AzureSecurityContactsType, fetching.MonitoringIdentity},
48+
inventory.SecurityAutoProvisioningSettingsType: {fetching.AzureAutoProvisioningSettingsType, fetching.MonitoringIdentity},
4949
}
5050

5151
func (f *AzureSecurityAssetFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) error {

0 commit comments

Comments
 (0)