mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-23 02:36:42 +00:00
Add peer operation
This commit is contained in:
@@ -9,9 +9,22 @@ const (
|
||||
ManagementEvent Type = "management"
|
||||
)
|
||||
|
||||
const (
|
||||
AddPeerByUserOperation Operation = iota
|
||||
AddPeerWithKeyOperation
|
||||
)
|
||||
|
||||
const (
|
||||
AddPeerByUserOperationMessage string = "Add new peer"
|
||||
AddPeerWithKeyOperationMessage string = AddPeerByUserOperationMessage
|
||||
)
|
||||
|
||||
// Type of the Event
|
||||
type Type string
|
||||
|
||||
// Operation is an action that triggered an Event
|
||||
type Operation int
|
||||
|
||||
// Store provides an interface to store or stream events.
|
||||
type Store interface {
|
||||
// Save an event in the store
|
||||
@@ -28,6 +41,8 @@ type Event struct {
|
||||
Timestamp time.Time
|
||||
// Operation that was performed during the event
|
||||
Operation string
|
||||
// OperationCode that was performed during the event
|
||||
OperationCode Operation
|
||||
// ID of the event (can be empty, meaning that it wasn't yet generated)
|
||||
ID uint64
|
||||
// Type of the event
|
||||
|
||||
@@ -12,7 +12,7 @@ const (
|
||||
SQLiteEventSinkDB = "events.db"
|
||||
createTableQuery = "CREATE TABLE IF NOT EXISTS events " +
|
||||
"(id INTEGER PRIMARY KEY AUTOINCREMENT, account TEXT NOT NULL, " +
|
||||
"operation TEXT, " +
|
||||
"operation INTEGER, " +
|
||||
"type TEXT, " +
|
||||
"timestamp DATETIME, " +
|
||||
"modifier TEXT," +
|
||||
@@ -98,7 +98,7 @@ func (store *SQLiteStore) Save(event Event) (*Event, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err := stmt.Exec(event.Operation, event.Timestamp, event.ModifierID, event.TargetID, event.AccountID, event.Type)
|
||||
result, err := stmt.Exec(event.OperationCode, event.Timestamp, event.ModifierID, event.TargetID, event.AccountID, event.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ func TestNewSQLiteStore(t *testing.T) {
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err = store.Save(Event{
|
||||
Timestamp: time.Now(),
|
||||
Operation: "cool_operation_" + fmt.Sprint(i),
|
||||
Type: ManagementEvent,
|
||||
ModifierID: "user_" + fmt.Sprint(i),
|
||||
TargetID: "peer_" + fmt.Sprint(i),
|
||||
AccountID: accountID,
|
||||
Timestamp: time.Now(),
|
||||
OperationCode: AddPeerByUserOperation,
|
||||
Type: ManagementEvent,
|
||||
ModifierID: "user_" + fmt.Sprint(i),
|
||||
TargetID: "peer_" + fmt.Sprint(i),
|
||||
AccountID: accountID,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user