Skip to content

Commit e4b5bcd

Browse files
Fix linting
1 parent 33fd813 commit e4b5bcd

17 files changed

Lines changed: 79 additions & 51 deletions

File tree

pkg/auth/auth_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ const tokenRefreshMargin = 10 * time.Second
3131
type KeycloakConfig struct {
3232
ClientID string
3333
Username string
34-
Password string
34+
Password string //nolint:gosec
3535
AuthURL string
3636
KeycloakRealm string
3737
}
3838

3939
type tokenInfo struct {
40-
AccessToken string
40+
AccessToken string //nolint:gosec
4141
ExpiresAt time.Time
4242
}
4343

4444
type authResponse struct {
45-
AccessToken string `json:"access_token"`
46-
ExpiresIn int `json:"expires_in"` // in seconds
45+
AccessToken string `json:"access_token"` //nolint:gosec
46+
ExpiresIn int `json:"expires_in"` // in seconds
4747
}
4848

4949
// KeycloakClient can be used to authenticate against a Keycloak server.
@@ -121,7 +121,7 @@ func (c *KeycloakClient) requestToken(ctx context.Context) (*authResponse, error
121121
}
122122
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
123123

124-
resp, err := c.httpClient.Do(req)
124+
resp, err := c.httpClient.Do(req) //nolint:gosec
125125
if err != nil {
126126
return nil, fmt.Errorf("failed to execute authentication request: %w", err)
127127
}

pkg/auth/auth_client_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ func TestKeycloakClient_GetToken(t *testing.T) {
3939
for name, tt := range tests {
4040
t.Run(name, func(t *testing.T) {
4141
var serverCallCount atomic.Int32
42-
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42+
mockServer := httptest.NewServer(http.HandlerFunc(func(
43+
w http.ResponseWriter, r *http.Request,
44+
) {
4345
serverCallCount.Add(1)
4446
w.WriteHeader(tt.responseCode)
4547
_, err := w.Write([]byte(tt.responseBody))
@@ -108,7 +110,9 @@ func TestKeycloakClient_GetToken_Refresh(t *testing.T) {
108110
fakeClock := NewFakeClock(time.Now())
109111

110112
var serverCallCount atomic.Int32
111-
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
113+
mockServer := httptest.NewServer(http.HandlerFunc(func(
114+
w http.ResponseWriter, r *http.Request,
115+
) {
112116
serverCallCount.Add(1)
113117
w.WriteHeader(200)
114118
_, err := w.Write(kcMockResponse)

pkg/dbcrypt/dbcipher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Config struct {
2525
Version string
2626

2727
// Contains the password used to derive encryption key
28-
Password string
28+
Password string //nolint:gosec
2929

3030
// Contains the salt for increasing password entropy
3131
PasswordSalt string

pkg/notifications/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *Client) RegisterOrigins(ctx context.Context, serviceID string, origins
121121
req.Header.Set("Authorization", "Bearer "+token)
122122
req.Header.Set("Content-Type", "application/json")
123123

124-
response, err := c.httpClient.Do(req)
124+
response, err := c.httpClient.Do(req) //nolint:gosec
125125
if err != nil {
126126
return fmt.Errorf("failed to execute request: %w", err)
127127
}

pkg/notifications/notification_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func TestClient_CreateNotification(t *testing.T) {
113113
mockAuthServer := setupMockAuthServer(t, tt.serverErrors.authenticationFail)
114114
defer mockAuthServer.Close()
115115

116-
mockNotificationServer := setupMockNotificationServer(t, &serverCallCount, tt.wantNotificationSent, tt.serverErrors)
116+
mockNotificationServer := setupMockNotificationServer(t, &serverCallCount,
117+
tt.wantNotificationSent, tt.serverErrors)
117118
defer mockNotificationServer.Close()
118119

119120
config := Config{
@@ -158,7 +159,9 @@ func setupMockAuthServer(t *testing.T, failAuth bool) *httptest.Server {
158159
}))
159160
}
160161

161-
func setupMockNotificationServer(t *testing.T, serverCallCount *atomic.Int32, wantNotification notificationModel, errors serverErrors) *httptest.Server {
162+
func setupMockNotificationServer(t *testing.T, serverCallCount *atomic.Int32,
163+
wantNotification notificationModel, errors serverErrors,
164+
) *httptest.Server {
162165
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
163166
serverCallCount.Add(1)
164167

pkg/openSearch/openSearchQuery/sort_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func TestSorting(t *testing.T) {
7070
}
7171
termsAggregation := esquery.TermsAgg("vulnerabilityWithAssetCountAgg", "vulnerabilityTest.oid.keyword").
7272
Aggs(subAggs...)
73-
termsAggregation, err = AddOrder(termsAggregation, testCases[name].SortingRequest, sortFieldMapping)
73+
termsAggregation, err = AddOrder(termsAggregation,
74+
testCases[name].SortingRequest, sortFieldMapping)
7475
resultingJson, queryErr := esquery.Search().Query(q.Build()).Aggs(termsAggregation).Size(0).MarshalJSON()
7576
assert.Nil(t, queryErr)
7677
assert.JSONEq(t, testCases[name].ExpectedQueryJson, string(resultingJson))

pkg/openSearch/osquery/boolQueryBuilder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ func (q *BoolQueryBuilder) AddFilterRequest(request *filter.Request) error {
151151
if handler, ok := operatorMapping[field.Operator]; ok {
152152
value := field.Value
153153

154-
if field.Operator == filter.CompareOperatorExists || field.Operator == filter.CompareOperatorDoesNotExist {
154+
if field.Operator == filter.CompareOperatorExists ||
155+
field.Operator == filter.CompareOperatorDoesNotExist {
155156
value = "" // exists operator does not need a value, but for more consistent handling just pass a dummy value
156157
}
157158
if value == nil {

pkg/openSearch/osquery/boolQueryBuilder_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ func TestBoolQueryBuilder_AddFilterRequest(t *testing.T) {
703703
t.Logf("sending search request to OpenSearch: %s", string(requestBody))
704704
gotDocuments, totalResults, err := client.ListDocuments(alias, requestBody)
705705
require.NoError(t, err, "listing documents failed")
706-
require.Len(t, gotDocuments, int(totalResults), "test requires results to be returned on a single page") // catch paging misconfiguration
706+
require.Len(t, gotDocuments, int(totalResults),
707+
"test requires results to be returned on a single page") // catch paging misconfiguration
707708

708709
assert.ElementsMatch(t, tt.wantDocuments, gotDocuments)
709710
}
@@ -751,7 +752,9 @@ func TestBoolQueryBuilder_AddTermFilter(t *testing.T) {
751752

752753
// index setup needed only once, as test cases are only reading data
753754
_, alias := tester.NewTestTypeIndexAlias(t, "arbitrary")
754-
tester.CreateDocuments(t, alias, ostesting.ToAnySlice(allDocs), []string{"id0", "id1", "id2", "id3", "id4"})
755+
tester.CreateDocuments(t, alias, ostesting.ToAnySlice(allDocs), []string{
756+
"id0", "id1", "id2", "id3", "id4",
757+
})
755758
client, err := newTestOSClient(tester.OSClient())
756759
require.NoError(t, err)
757760

@@ -939,7 +942,8 @@ func TestBoolQueryBuilder_AddTermFilter(t *testing.T) {
939942
t.Logf("sending search request to OpenSearch: %s", string(requestBody))
940943
gotDocuments, totalResults, err := client.ListDocuments(alias, requestBody)
941944
require.NoError(t, err, "listing documents failed")
942-
require.Len(t, gotDocuments, int(totalResults), "test requires results to be returned on a single page") // catch paging misconfiguration
945+
require.Len(t, gotDocuments, int(totalResults),
946+
"test requires results to be returned on a single page") // catch paging misconfiguration
943947

944948
assert.ElementsMatch(t, tt.wantDocuments, gotDocuments)
945949
})

pkg/openSearch/ostesting/test_type.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ type TestType struct {
2020
KeywordOmitEmpty string `json:"keywordOmitEmpty,omitempty"`
2121
}
2222

23-
var (
24-
// testTypeMapping is an index mapping for testType
25-
testTypeMapping string = `{
23+
// testTypeMapping is an index mapping for testType
24+
var testTypeMapping string = `{
2625
"mappings": {
2726
"properties": {
2827
"id": {
@@ -64,4 +63,3 @@ var (
6463
}
6564
}
6665
}`
67-
)

pkg/openSearch/ostesting/tester.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const KeepFailedEnv = "TEST_KEEP_FAILED"
3333
type ClientConfig struct {
3434
Address string
3535
User string
36-
Password string
36+
Password string //nolint:gosec
3737
}
3838

3939
const (
@@ -43,15 +43,13 @@ const (
4343
defaultTestUser = "admin"
4444
)
4545

46-
var (
47-
// defaultOSConf is the default configuration used for testing OpenSearch to connect
48-
// to the test OpenSearch instance running in docker
49-
defaultOSConf = ClientConfig{
50-
Address: defaultTestAddress,
51-
User: defaultTestUser,
52-
Password: defaultTestPassword,
53-
}
54-
)
46+
// defaultOSConf is the default configuration used for testing OpenSearch to connect
47+
// to the test OpenSearch instance running in docker
48+
var defaultOSConf = ClientConfig{
49+
Address: defaultTestAddress,
50+
User: defaultTestUser,
51+
Password: defaultTestPassword,
52+
}
5553

5654
// Tester manages connecting with testing OpenSearch instance and implements
5755
// helper methods
@@ -109,7 +107,8 @@ func NewTester(t *testing.T, opts ...TesterOption) *Tester {
109107
Addresses: []string{tst.conf.Address},
110108
Username: tst.conf.User,
111109
Password: tst.conf.Password,
112-
}})
110+
},
111+
})
113112
if err != nil {
114113
t.Fatalf("error while initializing opensearchapi.Client for testing: %v", err)
115114
}
@@ -177,7 +176,7 @@ func (tst Tester) NewIndex(t *testing.T, prefix string, mapping *string) string
177176
if createResponse != nil {
178177
resp = createResponse.Inspect().Response
179178
}
180-
defer func() { //close response body
179+
defer func() { // close response body
181180
if resp != nil {
182181
if err := resp.Body.Close(); err != nil {
183182
t.Errorf("failed to close response body: %v", err)

0 commit comments

Comments
 (0)