aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application_context.go8
-rw-r--r--connection_handler.go4
-rw-r--r--connections_controller.go34
-rw-r--r--stream_handler_test.go9
4 files changed, 28 insertions, 27 deletions
diff --git a/application_context.go b/application_context.go
index fc3005a..5db8843 100644
--- a/application_context.go
+++ b/application_context.go
@@ -48,7 +48,7 @@ func CreateApplicationContext(storage Storage, version string) (*ApplicationCont
var configWrapper struct {
Config Config
}
- if err := storage.Find(Settings).Filter(OrderedDocument{{"_id", "config"}}).
+ if err := storage.Find(Settings).Filter(OrderedDocument{{Key: "_id", Value: "config"}}).
First(&configWrapper); err != nil {
return nil, err
}
@@ -56,7 +56,7 @@ func CreateApplicationContext(storage Storage, version string) (*ApplicationCont
Accounts gin.Accounts
}
- if err := storage.Find(Settings).Filter(OrderedDocument{{"_id", "accounts"}}).
+ if err := storage.Find(Settings).Filter(OrderedDocument{{Key: "_id", Value: "accounts"}}).
First(&accountsWrapper); err != nil {
return nil, err
}
@@ -79,7 +79,7 @@ func (sm *ApplicationContext) SetConfig(config Config) {
sm.Configure()
var upsertResults interface{}
if _, err := sm.Storage.Update(Settings).Upsert(&upsertResults).
- Filter(OrderedDocument{{"_id", "config"}}).One(UnorderedDocument{"config": config}); err != nil {
+ Filter(OrderedDocument{{Key: "_id", Value: "config"}}).One(UnorderedDocument{"config": config}); err != nil {
log.WithError(err).WithField("config", config).Error("failed to update config")
}
}
@@ -88,7 +88,7 @@ func (sm *ApplicationContext) SetAccounts(accounts gin.Accounts) {
sm.Accounts = accounts
var upsertResults interface{}
if _, err := sm.Storage.Update(Settings).Upsert(&upsertResults).
- Filter(OrderedDocument{{"_id", "accounts"}}).One(UnorderedDocument{"accounts": accounts}); err != nil {
+ Filter(OrderedDocument{{Key: "_id", Value: "accounts"}}).One(UnorderedDocument{"accounts": accounts}); err != nil {
log.WithError(err).Error("failed to update accounts")
}
}
diff --git a/connection_handler.go b/connection_handler.go
index 4e92ccf..cd3d7d0 100644
--- a/connection_handler.go
+++ b/connection_handler.go
@@ -235,7 +235,7 @@ func (ch *connectionHandlerImpl) Complete(handler *StreamHandler) {
streamsIDs := append(client.documentsIDs, server.documentsIDs...)
if len(streamsIDs) > 0 {
n, err := ch.Storage().Update(ConnectionStreams).
- Filter(OrderedDocument{{"_id", UnorderedDocument{"$in": streamsIDs}}}).
+ Filter(OrderedDocument{{Key: "_id", Value: UnorderedDocument{"$in": streamsIDs}}}).
Many(UnorderedDocument{"connection_id": connectionID})
if err != nil {
log.WithError(err).WithField("connection", connection).Error("failed to update connection streams")
@@ -270,7 +270,7 @@ func (ch *connectionHandlerImpl) UpdateStatistics(connection Connection) {
var results interface{}
if _, err := ch.Storage().Update(Statistics).Upsert(&results).
- Filter(OrderedDocument{{"_id", time.Unix(rangeStart*60, 0)}}).
+ Filter(OrderedDocument{{Key: "_id", Value: time.Unix(rangeStart*60, 0)}}).
OneComplex(UnorderedDocument{"$inc": updateDocument}); err != nil {
log.WithError(err).WithField("connection", connection).Error("failed to update connection statistics")
}
diff --git a/connections_controller.go b/connections_controller.go
index 924cb53..71fd87c 100644
--- a/connections_controller.go
+++ b/connections_controller.go
@@ -89,52 +89,52 @@ func (cc ConnectionsController) GetConnections(c context.Context, filter Connect
from, _ := RowIDFromHex(filter.From)
if !from.IsZero() {
- query = query.Filter(OrderedDocument{{"_id", UnorderedDocument{"$lte": from}}})
+ query = query.Filter(OrderedDocument{{Key: "_id", Value: UnorderedDocument{"$lte": from}}})
}
to, _ := RowIDFromHex(filter.To)
if !to.IsZero() {
- query = query.Filter(OrderedDocument{{"_id", UnorderedDocument{"$gte": to}}})
+ query = query.Filter(OrderedDocument{{Key: "_id", Value: UnorderedDocument{"$gte": to}}})
} else {
query = query.Sort("_id", false)
}
if filter.ServicePort > 0 {
- query = query.Filter(OrderedDocument{{"port_dst", filter.ServicePort}})
+ query = query.Filter(OrderedDocument{{Key: "port_dst", Value: filter.ServicePort}})
}
if len(filter.ClientAddress) > 0 {
- query = query.Filter(OrderedDocument{{"ip_src", filter.ClientAddress}})
+ query = query.Filter(OrderedDocument{{Key: "ip_src", Value: filter.ClientAddress}})
}
if filter.ClientPort > 0 {
- query = query.Filter(OrderedDocument{{"port_src", filter.ClientPort}})
+ query = query.Filter(OrderedDocument{{Key: "port_src", Value: filter.ClientPort}})
}
if filter.MinDuration > 0 {
- query = query.Filter(OrderedDocument{{"$where", fmt.Sprintf("this.closed_at - this.started_at >= %v", filter.MinDuration)}})
+ query = query.Filter(OrderedDocument{{Key: "$where", Value: fmt.Sprintf("this.closed_at - this.started_at >= %v", filter.MinDuration)}})
}
if filter.MaxDuration > 0 {
- query = query.Filter(OrderedDocument{{"$where", fmt.Sprintf("this.closed_at - this.started_at <= %v", filter.MaxDuration)}})
+ query = query.Filter(OrderedDocument{{Key: "$where", Value: fmt.Sprintf("this.closed_at - this.started_at <= %v", filter.MaxDuration)}})
}
if filter.MinBytes > 0 {
- query = query.Filter(OrderedDocument{{"$where", fmt.Sprintf("this.client_bytes + this.server_bytes >= %v", filter.MinBytes)}})
+ query = query.Filter(OrderedDocument{{Key: "$where", Value: fmt.Sprintf("this.client_bytes + this.server_bytes >= %v", filter.MinBytes)}})
}
if filter.MaxBytes > 0 {
- query = query.Filter(OrderedDocument{{"$where", fmt.Sprintf("this.client_bytes + this.server_bytes <= %v", filter.MaxBytes)}})
+ query = query.Filter(OrderedDocument{{Key: "$where", Value: fmt.Sprintf("this.client_bytes + this.server_bytes <= %v", filter.MaxBytes)}})
}
if filter.StartedAfter > 0 {
- query = query.Filter(OrderedDocument{{"started_at", UnorderedDocument{"$gt": time.Unix(filter.StartedAfter, 0)}}})
+ query = query.Filter(OrderedDocument{{Key: "started_at", Value: UnorderedDocument{"$gt": time.Unix(filter.StartedAfter, 0)}}})
}
if filter.StartedBefore > 0 {
- query = query.Filter(OrderedDocument{{"started_at", UnorderedDocument{"$lt": time.Unix(filter.StartedBefore, 0)}}})
+ query = query.Filter(OrderedDocument{{Key: "started_at", Value: UnorderedDocument{"$lt": time.Unix(filter.StartedBefore, 0)}}})
}
if filter.ClosedAfter > 0 {
- query = query.Filter(OrderedDocument{{"closed_at", UnorderedDocument{"$gt": time.Unix(filter.ClosedAfter, 0)}}})
+ query = query.Filter(OrderedDocument{{Key: "closed_at", Value: UnorderedDocument{"$gt": time.Unix(filter.ClosedAfter, 0)}}})
}
if filter.ClosedBefore > 0 {
- query = query.Filter(OrderedDocument{{"closed_at", UnorderedDocument{"$lt": time.Unix(filter.ClosedBefore, 0)}}})
+ query = query.Filter(OrderedDocument{{Key: "closed_at", Value: UnorderedDocument{"$lt": time.Unix(filter.ClosedBefore, 0)}}})
}
if filter.Hidden {
- query = query.Filter(OrderedDocument{{"hidden", true}})
+ query = query.Filter(OrderedDocument{{Key: "hidden", Value: true}})
}
if filter.Marked {
- query = query.Filter(OrderedDocument{{"marked", true}})
+ query = query.Filter(OrderedDocument{{Key: "marked", Value: true}})
}
if filter.MatchedRules != nil && len(filter.MatchedRules) > 0 {
matchedRules := make([]RowID, len(filter.MatchedRules))
@@ -146,13 +146,13 @@ func (cc ConnectionsController) GetConnections(c context.Context, filter Connect
}
}
- query = query.Filter(OrderedDocument{{"matched_rules", UnorderedDocument{"$all": matchedRules}}})
+ query = query.Filter(OrderedDocument{{Key: "matched_rules", Value: UnorderedDocument{"$all": matchedRules}}})
}
performedSearchID, _ := RowIDFromHex(filter.PerformedSearch)
if !performedSearchID.IsZero() {
performedSearch := cc.searchController.GetPerformedSearch(performedSearchID)
if !performedSearch.ID.IsZero() && len(performedSearch.AffectedConnections) > 0 {
- query = query.Filter(OrderedDocument{{"_id", UnorderedDocument{"$in": performedSearch.AffectedConnections}}})
+ query = query.Filter(OrderedDocument{{Key: "_id", Value: UnorderedDocument{"$in": performedSearch.AffectedConnections}}})
}
}
if filter.Limit > 0 && filter.Limit <= MaxQueryLimit {
diff --git a/stream_handler_test.go b/stream_handler_test.go
index 127aa82..b185483 100644
--- a/stream_handler_test.go
+++ b/stream_handler_test.go
@@ -19,15 +19,16 @@ package main
import (
"context"
+ "crypto/rand"
+ "net"
+ "testing"
+ "time"
+
"github.com/flier/gohs/hyperscan"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/tcpassembly"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "math/rand"
- "net"
- "testing"
- "time"
)
const testSrcIP = "10.10.10.100"