Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor types and add kdr package #155

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module config-service

go 1.22.4

toolchain go1.22.5

require (
github.com/armosec/armoapi-go v0.0.450
github.com/armosec/armosec-infra v0.0.67
github.com/armosec/armoapi-go v0.0.452
github.com/armosec/armosec-infra v0.0.69-0.20240929101252-3977ec0a0ba5

github.com/aws/smithy-go v1.20.2
github.com/chidiwilliams/flatbson v0.3.0
github.com/dchest/uniuri v1.2.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVb
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/armosec/armoapi-go v0.0.450 h1:qgO/hyt3qkIOAAqkVPQZCTBLCt8WCq57lJEIgcjifFg=
github.com/armosec/armoapi-go v0.0.450/go.mod h1:mpok+lZaolcN5XRz/JxpwhfF8nln1OEKnGuvwAN+7Lo=
github.com/armosec/armosec-infra v0.0.67 h1:38DlCRtsn4N5COf2qWZg+Gjqs+ePnJk0DMBXw8TY3zc=
github.com/armosec/armosec-infra v0.0.67/go.mod h1:i1oP5dhpZpELRzs+jtc8Q+HyfBohwd95LAycQ0OpSmQ=
github.com/armosec/armoapi-go v0.0.452 h1:THsTfBtrUfLKUEVfwq+ztqfyBjnnHO/yzTuYg3MdwAQ=
github.com/armosec/armoapi-go v0.0.452/go.mod h1:mpok+lZaolcN5XRz/JxpwhfF8nln1OEKnGuvwAN+7Lo=
github.com/armosec/armosec-infra v0.0.69-0.20240929101252-3977ec0a0ba5 h1:O902d1uJ/iA+p0GXdfR6TrOX5y1v72hhxLvgkdC7QFQ=
github.com/armosec/armosec-infra v0.0.69-0.20240929101252-3977ec0a0ba5/go.mod h1:mJKzU4liDVCAcnGuLU9AY1Iocur45Srnn+ath7ClbJk=
github.com/armosec/gojay v1.2.17 h1:VSkLBQzD1c2V+FMtlGFKqWXNsdNvIKygTKJI9ysY8eM=
github.com/armosec/gojay v1.2.17/go.mod h1:vuvX3DlY0nbVrJ0qCklSS733AWMoQboq3cFyuQW9ybc=
github.com/armosec/utils-go v0.0.57 h1:0RaqexK+t7HeKWfldBv2C1JiLLGuUx9FP0DGWDNRJpg=
Expand Down
50 changes: 23 additions & 27 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/armosec/armoapi-go/identifiers"
"github.com/armosec/armoapi-go/notifications"
"github.com/armosec/armosec-infra/kdr"

"github.com/armosec/armosec-infra/workflows"

rndStr "github.com/dchest/uniuri"
Expand Down Expand Up @@ -1692,7 +1693,7 @@ func getIncidentsMocks() []*types.RuntimeIncident {
Name: "incident1",
GUID: "1c0e9d28-7e71-4370-999e-9b3e8f69a648",
},
RuntimeAlert: armotypes.RuntimeAlert{
RuntimeAlert: kdr.RuntimeAlert{
RuntimeAlertK8sDetails: armotypes.RuntimeAlertK8sDetails{
ClusterName: "cluster1",
Namespace: "namespace1",
Expand Down Expand Up @@ -1728,41 +1729,35 @@ func getIncidentsMocks() []*types.RuntimeIncident {
Name: "incident3",
GUID: "1c0e9d28-7e71-4370-999e-9b3e8f69a646",
},
RuntimeAlert: armotypes.RuntimeAlert{
RuntimeAlert: kdr.RuntimeAlert{
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Timestamp: ts,
},
},
Severity: "medium",
RelatedAlerts: []kdr.RuntimeAlert{
{
RuntimeAlert: armotypes.RuntimeAlert{
Message: "msg1",
HostName: "host1",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Timestamp: ts,
Nanoseconds: uint64(tsNanos) + 200,
},
Message: "msg1",
HostName: "host1",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Timestamp: ts,
Nanoseconds: uint64(tsNanos) + 200,
},
},
{
RuntimeAlert: armotypes.RuntimeAlert{
Message: "msg2",
HostName: "host2",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Timestamp: ts,
Nanoseconds: uint64(tsNanos) + 100,
},
Message: "msg2",
HostName: "host2",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Timestamp: ts,
Nanoseconds: uint64(tsNanos) + 100,
},
},
{
RuntimeAlert: armotypes.RuntimeAlert{
Message: "msg3",
HostName: "host3",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Nanoseconds: uint64(tsNanos),
Timestamp: ts,
},
Message: "msg3",
HostName: "host3",
BaseRuntimeAlert: armotypes.BaseRuntimeAlert{
Nanoseconds: uint64(tsNanos),
Timestamp: ts,
},
},
},
Expand All @@ -1775,6 +1770,7 @@ func getIncidentsMocks() []*types.RuntimeIncident {
},
},
}

return runtimeIncidents
}

Expand All @@ -1783,9 +1779,8 @@ func (suite *MainTestSuite) TestRuntimeIncidents() {
modifyDocFunc := func(doc *types.RuntimeIncident) *types.RuntimeIncident {
docCloned := Clone(doc)
docCloned.RelatedAlerts = append(docCloned.RelatedAlerts, kdr.RuntimeAlert{
RuntimeAlert: armotypes.RuntimeAlert{
Message: "msg" + rndStr.New(),
},

Message: "msg" + rndStr.New(),
})
return docCloned
}
Expand Down Expand Up @@ -2024,7 +2019,7 @@ func (suite *MainTestSuite) TestRuntimeAlerts() {
// assuer the calling PUT for this incident (with empty alerts) will not change the alerts
w = suite.doRequest(http.MethodPut, consts.RuntimeIncidentPath+"/"+resp.Response[0].GUID, resp.Response[0])
suite.Equal(http.StatusOK, w.Code)
w = suite.doRequest(http.MethodPut, consts.RuntimeIncidentPath, resp.Response[0])
w = suite.doRequest(http.MethodPut, consts.RuntimeIncidentPath, resp.Response[0].RuntimeAlert)
suite.Equal(http.StatusOK, w.Code)
// get alerts of this incident guid paginated
alertRequest := armotypes.V2ListRequest{
Expand Down Expand Up @@ -2069,6 +2064,7 @@ func (suite *MainTestSuite) TestRuntimeAlerts() {
}
suite.Len(alerts.Response, 1)
suite.Equal(1, alerts.Total.Value)

suite.Equal(runtimeIncidents[2].RelatedAlerts[2], alerts.Response[0].RuntimeAlert)
// test alerts sort by timestamp (with nanoseconds)
alertRequest = armotypes.V2ListRequest{
Expand Down
5 changes: 3 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/armosec/armoapi-go/armotypes"
"github.com/armosec/armoapi-go/configservice"
"github.com/armosec/armoapi-go/notifications"

cloudposture "github.com/armosec/armosec-infra/cloudPosture"
"github.com/armosec/armosec-infra/kdr"
"github.com/armosec/armosec-infra/workflows"
Expand Down Expand Up @@ -451,11 +452,11 @@ func (r *RuntimeAlert) GetReadOnlyFields() []string {
}

func (r *RuntimeAlert) InitNew() {
r.Timestamp = time.Now().UTC()
r.BaseRuntimeAlert.Timestamp = time.Now().UTC()
}

func (r *RuntimeAlert) GetCreationTime() *time.Time {
return &r.Timestamp
return &r.BaseRuntimeAlert.Timestamp
}

func (r *RuntimeAlert) SetGUID(guid string) {
Expand Down
Loading