Skip to content

Commit 2b5958b

Browse files
Bugfix/337 ci lint is bumped to version 202 this breaks ci linting (#338)
1 parent f1fe72d commit 2b5958b

File tree

23 files changed

+142
-98
lines changed

23 files changed

+142
-98
lines changed

internal/database/memory/memory_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func TestCreate(t *testing.T) {
2222
fmt.Println(err)
2323
t.Fail()
2424
}
25-
defer jsonFile.Close()
26-
byteValue, _ := io.ReadAll(jsonFile)
2725

26+
byteValue, _ := io.ReadAll(jsonFile)
27+
err = jsonFile.Close()
2828
if err != nil {
2929
fmt.Println("Not valid JSON")
3030
t.Fail()
@@ -45,9 +45,9 @@ func TestRead(t *testing.T) {
4545
fmt.Println(err)
4646
t.Fail()
4747
}
48-
defer jsonFile.Close()
49-
byteValue, _ := io.ReadAll(jsonFile)
5048

49+
byteValue, _ := io.ReadAll(jsonFile)
50+
err = jsonFile.Close()
5151
if err != nil {
5252
fmt.Println("Not valid JSON")
5353
t.Fail()
@@ -75,8 +75,9 @@ func TestUpdate(t *testing.T) {
7575
fmt.Println(err)
7676
t.Fail()
7777
}
78-
defer jsonFile.Close()
78+
7979
byteValue, _ := io.ReadAll(jsonFile)
80+
err = jsonFile.Close()
8081

8182
if err != nil {
8283
fmt.Println("Not valid JSON")
@@ -117,9 +118,9 @@ func TestDelete(t *testing.T) {
117118
fmt.Println(err)
118119
t.Fail()
119120
}
120-
defer jsonFile.Close()
121-
byteValue, _ := io.ReadAll(jsonFile)
122121

122+
byteValue, _ := io.ReadAll(jsonFile)
123+
err = jsonFile.Close()
123124
if err != nil {
124125
fmt.Println("Not valid JSON")
125126
t.Fail()
@@ -154,9 +155,9 @@ func TestGetAllPlaybooks(t *testing.T) {
154155
fmt.Println(err)
155156
t.Fail()
156157
}
157-
defer jsonFile.Close()
158-
byteValue, _ := io.ReadAll(jsonFile)
159158

159+
byteValue, _ := io.ReadAll(jsonFile)
160+
err = jsonFile.Close()
160161
if err != nil {
161162
fmt.Println("Not valid JSON")
162163
t.Fail()
@@ -202,9 +203,9 @@ func TestGetAllPlaybookMetas(t *testing.T) {
202203
fmt.Println(err)
203204
t.Fail()
204205
}
205-
defer jsonFile.Close()
206-
byteValue, _ := io.ReadAll(jsonFile)
207206

207+
byteValue, _ := io.ReadAll(jsonFile)
208+
err = jsonFile.Close()
208209
if err != nil {
209210
fmt.Println("Not valid JSON")
210211
t.Fail()

internal/database/mongodb/mongo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ func SetupMongodb(uri string, username string, password string) error {
6666
log.Trace("Calling SetupMongodb() to start setting up the mongodb database implementation")
6767
err := InitMongoClient(uri, username, password)
6868
if err != nil {
69-
log.Error("Failed to setup MongoClient, error msg: ", err.Error())
69+
log.Error("failed to setup MongoClient, error msg: ", err.Error())
7070
return err
7171
}
7272

7373
if mongoclient == nil {
74-
const error_msg = "Mongoclient is not set properly"
74+
const error_msg = "mongoclient is not set properly"
7575
log.Error(error_msg)
7676
return errors.New(error_msg)
7777
}
@@ -152,7 +152,7 @@ func (mongocollection *mongoCollection[T]) Create(data interface{}) error {
152152

153153
if input_type != comparison_type { // checks if the input type provided is accordance with collection type
154154
log.Error("Failed as input object does not match required collection type")
155-
return errors.New("Input type for Create function is not in accordance with required type")
155+
return errors.New("input type for Create function is not in accordance with required type")
156156
}
157157
// ctx := context.Background()
158158
context, cancel := context.WithTimeout(context.Background(), 2*time.Second)
@@ -229,7 +229,7 @@ func InitMongoClient(mongo_uri string, username string, password string) error {
229229

230230
if username == "" || password == "" {
231231
log.Error("you must set your 'username' or 'password'")
232-
return errors.New("Username or password not correctly set")
232+
return errors.New("username or password not correctly set")
233233
}
234234

235235
clientOpts := options.Client().ApplyURI(mongo_uri).SetAuth(options.Credential{

internal/logger/logger.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ func (format Format) fromString(name string) Format {
7373
}
7474

7575
func setFormat(instance *logrus.Logger, format Format) {
76-
if format == Text {
76+
switch format {
77+
case Text:
7778
instance.SetFormatter(&logrus.TextFormatter{})
78-
} else if format == Json {
79+
case Json:
7980
instance.SetFormatter(&logrus.JSONFormatter{})
81+
8082
}
8183
}
8284

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ swagger:
1515

1616
lint: swagger
1717

18-
golangci-lint run --timeout 5m -v
18+
golangci-lint run --max-same-issues 0 --timeout 5m -v
1919

2020
build: swagger
2121
CGO_ENABLED=0 go build -o ./build/soarca $(GOFLAGS) ./cmd/soarca/main.go

pkg/api/manual/manual_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (manualHandler *ManualHandler) PostContinue(g *gin.Context) {
152152
outArgsUpdate, err := manualHandler.parseManualOutArgsUpdate(byteData)
153153
if err != nil {
154154
apiError.SendErrorResponse(g, http.StatusBadRequest,
155-
fmt.Sprint(fmt.Errorf("Failed to parse manual out args payload: %w", err)),
155+
fmt.Sprint(fmt.Errorf("failed to parse manual out args payload: %w", err)),
156156
"POST /manual/continue", err.Error())
157157
return
158158
}

pkg/core/capability/fin/protocol/finprotocol_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"soarca/pkg/models/cacao"
88
"soarca/pkg/models/fin"
9-
model "soarca/pkg/models/fin"
109
"soarca/pkg/utils/guid"
1110
"soarca/test/unittest/mocks/mock_mqtt"
1211
"testing"
@@ -40,7 +39,7 @@ func TestTimeoutAndCallbackTimerElaspsed(t *testing.T) {
4039
mock_client.On("Subscribe", "testing", uint8(1), mock.Anything).Return(&mock_token)
4140
prot.Subscribe(&mock_client)
4241

43-
expectedCommand := model.NewCommand()
42+
expectedCommand := fin.NewCommand()
4443
expectedCommand.CommandSubstructure.Context.Timeout = 1
4544

4645
result, err := prot.AwaitResultOrTimeout(expectedCommand, &mock_client)
@@ -63,7 +62,7 @@ func TestTimeoutAndCallbackHandlerCalled(t *testing.T) {
6362

6463
prot.Subscribe(&mock_client)
6564

66-
expectedCommand := model.NewCommand()
65+
expectedCommand := fin.NewCommand()
6766
expectedCommand.CommandSubstructure.Context.Timeout = 1
6867

6968
mock_token_ack.On("Wait").Return(true)

pkg/core/capability/fin/protocol/protocol.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ func (protocol *FinProtocol) AwaitResultOrTimeout(command fin.Command, client mq
116116
break
117117
}
118118
log.Info(finMessage)
119+
119120
// This now accepts any ack, should be changed
120-
if finMessage.Type == fin.MessageTypeAck {
121+
switch finMessage.Type {
122+
case fin.MessageTypeAck:
121123
ackReceived = true
122-
} else if finMessage.Type == fin.MessageTypeResult {
124+
case fin.MessageTypeResult:
123125
finResult := fin.Result{}
124126
err := fin.Decode(result, &finResult)
125127
if err != nil {

pkg/core/capability/manual/interaction/interaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (manualController *InteractionController) registerPendingInteraction(comman
172172
if _, ok := execution[commandInfo.Metadata.StepId]; ok {
173173
// Error: there is already a pending manual command for the action step
174174
err := fmt.Errorf(
175-
"a manual step is already pending for execution %s, step %s. There can only be one pending manual command per action step.",
175+
"a manual step is already pending for execution %s, step %s. There can only be one pending manual command per action step",
176176
commandInfo.Metadata.ExecutionId.String(), commandInfo.Metadata.StepId)
177177
log.Error(err)
178178
return err

pkg/core/capability/manual/interaction/interaction_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"soarca/pkg/core/capability"
1010
"soarca/pkg/models/cacao"
1111
"soarca/pkg/models/execution"
12-
"soarca/pkg/models/manual"
1312
manualModel "soarca/pkg/models/manual"
1413
"sort"
1514
"strings"
@@ -286,7 +285,7 @@ func TestValidateMatchingOutArgs(t *testing.T) {
286285
}
287286
storedOutArgs := cacao.Variables{"__var2__": storedOutArg}
288287

289-
interactionStorageEntry := manual.InteractionStorageEntry{
288+
interactionStorageEntry := manualModel.InteractionStorageEntry{
290289
CommandInfo: manualModel.CommandInfo{
291290
Metadata: testMetadata,
292291
Context: capability.Context{},
@@ -422,7 +421,7 @@ func TestFailOnRegisterSamePendingInteraction(t *testing.T) {
422421
expectedErr := errors.New(
423422
"a manual step is already pending for execution " +
424423
"61a6c41e-6efc-4516-a242-dfbc5c89d562, step test_step_id. " +
425-
"There can only be one pending manual command per action step.",
424+
"There can only be one pending manual command per action step",
426425
)
427426
assert.Equal(t, err, expectedErr)
428427
}

pkg/core/capability/ssh/ssh.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func execute(command cacao.Command,
5858
if err != nil {
5959
return cacao.NewVariables(), err
6060
}
61-
defer client.Close()
61+
defer close(client)
6262

6363
return executeCommand(session, command)
6464
}
@@ -72,11 +72,15 @@ func executeCommand(session *ssh.Session,
7272
log.Error(err)
7373
return cacao.NewVariables(), err
7474
}
75-
defer session.Close()
7675
results := cacao.NewVariables(cacao.Variable{Type: cacao.VariableTypeString,
7776
Name: sshResultVariableName,
7877
Value: string(response)})
7978
log.Trace("Finished ssh execution will return the variables: ", results)
79+
sessionErr := session.Close()
80+
if sessionErr != nil {
81+
log.Error(sessionErr)
82+
}
83+
8084
return results, err
8185
}
8286

@@ -118,7 +122,7 @@ func getSession(config ssh.ClientConfig, target cacao.AgentTarget) (*ssh.Session
118122
session, err := client.NewSession()
119123
if err != nil {
120124
log.Error(err)
121-
client.Close()
125+
close(client)
122126
return nil, nil, err
123127
}
124128
return session, client, err
@@ -149,16 +153,27 @@ func CheckSshAuthenticationInfo(authentication cacao.AuthenticationInformation)
149153
if strings.TrimSpace(authentication.Username) == "" {
150154
return errors.New("username is empty")
151155
}
152-
if authentication.Type == "user-auth" {
156+
157+
switch authentication.Type {
158+
case "user-auth":
153159
if strings.TrimSpace(authentication.Password) == "" {
154160
return errors.New("password is empty")
155161
}
156-
} else if authentication.Type == "private-key" {
162+
case "private-key":
157163
if strings.TrimSpace(authentication.PrivateKey) == "" {
158164
return errors.New("private key is not set")
159165
}
160-
} else {
166+
default:
161167
return errors.New("non supported authentication type")
162168
}
163169
return nil
164170
}
171+
172+
func close(client *ssh.Client) {
173+
if client != nil {
174+
err := client.Close()
175+
if err != nil {
176+
log.Error(err)
177+
}
178+
}
179+
}

0 commit comments

Comments
 (0)