mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 23:39:07 +01:00
Finalize events API
This commit is contained in:
@@ -511,7 +511,18 @@ func (am *DefaultAccountManager) newAccount(userID, domain string) (*Account, er
|
|||||||
log.Warnf("an account with ID already exists, retrying...")
|
log.Warnf("an account with ID already exists, retrying...")
|
||||||
continue
|
continue
|
||||||
} else if statusErr.Type() == status.NotFound {
|
} else if statusErr.Type() == status.NotFound {
|
||||||
return newAccountWithId(accountId, userID, domain), nil
|
newAccount := newAccountWithId(accountId, userID, domain)
|
||||||
|
_, err = am.eventStore.Save(&activity.Event{
|
||||||
|
Timestamp: time.Now(),
|
||||||
|
Activity: activity.AccountCreated,
|
||||||
|
AccountID: newAccount.Id,
|
||||||
|
TargetID: newAccount.Id,
|
||||||
|
InitiatorID: userID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newAccount, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -798,16 +809,15 @@ func (am *DefaultAccountManager) handleNewUserAccount(domainAcc *Account, claims
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
opEvent := &activity.Event{
|
event := &activity.Event{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
Type: activity.ManagementEvent,
|
Activity: activity.UserJoined,
|
||||||
OperationCode: activity.UserJoinedOperation,
|
AccountID: account.Id,
|
||||||
AccountID: account.Id,
|
TargetID: claims.UserId,
|
||||||
TargetID: claims.UserId,
|
InitiatorID: claims.UserId,
|
||||||
ModifierID: claims.UserId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = am.eventStore.Save(opEvent)
|
_, err = am.eventStore.Save(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,43 +3,69 @@ package activity
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DeviceEvent describes an event that happened of a device (e.g, connected/disconnected)
|
// PeerAddedByUser indicates that a user added a new peer to the system
|
||||||
DeviceEvent Type = "device"
|
PeerAddedByUser Activity = iota
|
||||||
// ManagementEvent describes an event that happened on a Management service (e.g., user added)
|
// PeerAddedWithSetupKey indicates that a new peer joined the system using a setup key
|
||||||
ManagementEvent Type = "management"
|
PeerAddedWithSetupKey
|
||||||
|
// UserJoined indicates that a new user joined the account
|
||||||
|
UserJoined
|
||||||
|
// UserInvited indicates that a new user was invited to join the account
|
||||||
|
UserInvited
|
||||||
|
// AccountCreated indicates that a new account has been created
|
||||||
|
AccountCreated
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AddPeerByUserOperation Operation = iota
|
// PeerAddedByUserMessage is a human-readable text message of the PeerAddedByUser activity
|
||||||
AddPeerWithKeyOperation
|
PeerAddedByUserMessage string = "New peer added by a user"
|
||||||
UserJoinedOperation
|
// PeerAddedWithSetupKeyMessage is a human-readable text message of the PeerAddedWithSetupKey activity
|
||||||
|
PeerAddedWithSetupKeyMessage = "New peer added with a setup key"
|
||||||
|
//UserJoinedMessage is a human-readable text message of the UserJoined activity
|
||||||
|
UserJoinedMessage string = "New user joined"
|
||||||
|
//UserInvitedMessage is a human-readable text message of the UserInvited activity
|
||||||
|
UserInvitedMessage string = "New user invited"
|
||||||
|
//AccountCreatedMessage is a human-readable text message of the AccountCreated activity
|
||||||
|
AccountCreatedMessage string = "Account created"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// Activity that triggered an Event
|
||||||
AddPeerByUserOperationMessage string = "Add new peer"
|
type Activity int
|
||||||
AddPeerWithKeyOperationMessage string = AddPeerByUserOperationMessage
|
|
||||||
UserJoinedOperationMessage string = "New user joined"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MessageForOperation returns a string message for an Operation
|
// Message returns a string representation of an activity
|
||||||
func MessageForOperation(op Operation) string {
|
func (a Activity) Message() string {
|
||||||
switch op {
|
switch a {
|
||||||
case AddPeerByUserOperation:
|
case PeerAddedByUser:
|
||||||
return AddPeerByUserOperationMessage
|
return PeerAddedByUserMessage
|
||||||
case AddPeerWithKeyOperation:
|
case PeerAddedWithSetupKey:
|
||||||
return AddPeerWithKeyOperationMessage
|
return PeerAddedWithSetupKeyMessage
|
||||||
case UserJoinedOperation:
|
case UserJoined:
|
||||||
return UserJoinedOperationMessage
|
return UserJoinedMessage
|
||||||
|
case UserInvited:
|
||||||
|
return UserInvitedMessage
|
||||||
|
case AccountCreated:
|
||||||
|
return AccountCreatedMessage
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN_OPERATION"
|
return "UNKNOWN_ACTIVITY"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type of the Event
|
// StringCode returns a string code of the activity
|
||||||
type Type string
|
func (a Activity) StringCode() string {
|
||||||
|
switch a {
|
||||||
// Operation is an action that triggered an Event
|
case PeerAddedByUser:
|
||||||
type Operation int
|
return "user.peer.add"
|
||||||
|
case PeerAddedWithSetupKey:
|
||||||
|
return "setupkey.peer.add"
|
||||||
|
case UserJoined:
|
||||||
|
return "user.join"
|
||||||
|
case UserInvited:
|
||||||
|
return "user.invite"
|
||||||
|
case AccountCreated:
|
||||||
|
return "account.create"
|
||||||
|
default:
|
||||||
|
return "UNKNOWN_ACTIVITY"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Store provides an interface to store or stream events.
|
// Store provides an interface to store or stream events.
|
||||||
type Store interface {
|
type Store interface {
|
||||||
@@ -55,31 +81,26 @@ type Store interface {
|
|||||||
type Event struct {
|
type Event struct {
|
||||||
// Timestamp of the event
|
// Timestamp of the event
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
// Operation that was performed during the event
|
// Activity that was performed during the event
|
||||||
Operation string
|
Activity Activity
|
||||||
// OperationCode that was performed during the event
|
|
||||||
OperationCode Operation
|
|
||||||
// ID of the event (can be empty, meaning that it wasn't yet generated)
|
// ID of the event (can be empty, meaning that it wasn't yet generated)
|
||||||
ID uint64
|
ID uint64
|
||||||
// Type of the event
|
// InitiatorID is the ID of an object that initiated the event (e.g., a user)
|
||||||
Type Type
|
InitiatorID string
|
||||||
// ModifierID is the ID of an object that modifies a Target
|
// TargetID is the ID of an object that was effected by the event (e.g., a peer)
|
||||||
ModifierID string
|
|
||||||
// TargetID is the ID of an object that a Modifier modifies
|
|
||||||
TargetID string
|
TargetID string
|
||||||
// AccountID where event happened
|
// AccountID is the ID of an account where the event happened
|
||||||
AccountID string
|
AccountID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the event
|
// Copy the event
|
||||||
func (e *Event) Copy() *Event {
|
func (e *Event) Copy() *Event {
|
||||||
return &Event{
|
return &Event{
|
||||||
Timestamp: e.Timestamp,
|
Timestamp: e.Timestamp,
|
||||||
Operation: e.Operation,
|
Activity: e.Activity,
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
Type: e.Type,
|
InitiatorID: e.InitiatorID,
|
||||||
ModifierID: e.ModifierID,
|
TargetID: e.TargetID,
|
||||||
TargetID: e.TargetID,
|
AccountID: e.AccountID,
|
||||||
AccountID: e.AccountID,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import (
|
|||||||
const (
|
const (
|
||||||
SQLiteEventSinkDB = "events.db"
|
SQLiteEventSinkDB = "events.db"
|
||||||
createTableQuery = "CREATE TABLE IF NOT EXISTS events " +
|
createTableQuery = "CREATE TABLE IF NOT EXISTS events " +
|
||||||
"(id INTEGER PRIMARY KEY AUTOINCREMENT, account TEXT NOT NULL, " +
|
"(id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
"operation INTEGER, " +
|
"activity INTEGER, " +
|
||||||
"type TEXT, " +
|
|
||||||
"timestamp DATETIME, " +
|
"timestamp DATETIME, " +
|
||||||
"modifier TEXT," +
|
"initiator_id TEXT," +
|
||||||
" target TEXT);"
|
"account_id TEXT," +
|
||||||
|
" target_id TEXT);"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SQLiteStore is the implementation of the activity.Store interface backed by SQLite
|
// SQLiteStore is the implementation of the activity.Store interface backed by SQLite
|
||||||
@@ -44,26 +44,23 @@ func processResult(result *sql.Rows) ([]*Event, error) {
|
|||||||
events := make([]*Event, 0)
|
events := make([]*Event, 0)
|
||||||
for result.Next() {
|
for result.Next() {
|
||||||
var id int64
|
var id int64
|
||||||
var operation Operation
|
var operation Activity
|
||||||
var timestamp time.Time
|
var timestamp time.Time
|
||||||
var modifier string
|
var initiator string
|
||||||
var target string
|
var target string
|
||||||
var account string
|
var account string
|
||||||
var typ Type
|
err := result.Scan(&id, &operation, ×tamp, &initiator, &target, &account)
|
||||||
err := result.Scan(&id, &operation, ×tamp, &modifier, &target, &account, &typ)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
events = append(events, &Event{
|
events = append(events, &Event{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
OperationCode: operation,
|
Activity: operation,
|
||||||
Operation: MessageForOperation(operation),
|
ID: uint64(id),
|
||||||
ID: uint64(id),
|
InitiatorID: initiator,
|
||||||
Type: typ,
|
TargetID: target,
|
||||||
ModifierID: modifier,
|
AccountID: account,
|
||||||
TargetID: target,
|
|
||||||
AccountID: account,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,8 +73,8 @@ func (store *SQLiteStore) Get(accountID string, offset, limit int, descending bo
|
|||||||
if !descending {
|
if !descending {
|
||||||
order = "ASC"
|
order = "ASC"
|
||||||
}
|
}
|
||||||
stmt, err := store.db.Prepare(fmt.Sprintf("SELECT id, operation, timestamp, modifier, target, account, type"+
|
stmt, err := store.db.Prepare(fmt.Sprintf("SELECT id, activity, timestamp, initiator_id, target_id, account_id"+
|
||||||
" FROM events WHERE account = ? ORDER BY timestamp %s LIMIT ? OFFSET ?;", order))
|
" FROM events WHERE account_id = ? ORDER BY timestamp %s LIMIT ? OFFSET ?;", order))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -94,12 +91,12 @@ func (store *SQLiteStore) Get(accountID string, offset, limit int, descending bo
|
|||||||
// Save an event in the SQLite events table
|
// Save an event in the SQLite events table
|
||||||
func (store *SQLiteStore) Save(event *Event) (*Event, error) {
|
func (store *SQLiteStore) Save(event *Event) (*Event, error) {
|
||||||
|
|
||||||
stmt, err := store.db.Prepare("INSERT INTO events(operation, timestamp, modifier, target, account, type) VALUES(?, ?, ?, ?, ?, ?)")
|
stmt, err := store.db.Prepare("INSERT INTO events(activity, timestamp, initiator_id, target_id, account_id) VALUES(?, ?, ?, ?, ?)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := stmt.Exec(event.OperationCode, event.Timestamp, event.ModifierID, event.TargetID, event.AccountID, event.Type)
|
result, err := stmt.Exec(event.Activity, event.Timestamp, event.InitiatorID, event.TargetID, event.AccountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ func TestNewSQLiteStore(t *testing.T) {
|
|||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
_, err = store.Save(&Event{
|
_, err = store.Save(&Event{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
OperationCode: AddPeerByUserOperation,
|
Activity: PeerAddedByUser,
|
||||||
Type: ManagementEvent,
|
InitiatorID: "user_" + fmt.Sprint(i),
|
||||||
ModifierID: "user_" + fmt.Sprint(i),
|
TargetID: "peer_" + fmt.Sprint(i),
|
||||||
TargetID: "peer_" + fmt.Sprint(i),
|
AccountID: accountID,
|
||||||
AccountID: accountID,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- email
|
- email
|
||||||
- name
|
- name
|
||||||
- role
|
- role
|
||||||
- auto_groups
|
- auto_groups
|
||||||
- status
|
- status
|
||||||
UserRequest:
|
UserRequest:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -98,8 +98,8 @@ components:
|
|||||||
description: Peer's hostname
|
description: Peer's hostname
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- name
|
- name
|
||||||
Peer:
|
Peer:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/PeerMinimum'
|
- $ref: '#/components/schemas/PeerMinimum'
|
||||||
@@ -142,15 +142,15 @@ components:
|
|||||||
description: Peer's DNS label is the parsed peer name for domain resolution. It is used to form an FQDN by appending the account's domain to the peer label. e.g. peer-dns-label.netbird.cloud
|
description: Peer's DNS label is the parsed peer name for domain resolution. It is used to form an FQDN by appending the account's domain to the peer label. e.g. peer-dns-label.netbird.cloud
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- ip
|
- ip
|
||||||
- connected
|
- connected
|
||||||
- last_seen
|
- last_seen
|
||||||
- os
|
- os
|
||||||
- version
|
- version
|
||||||
- groups
|
- groups
|
||||||
- ssh_enabled
|
- ssh_enabled
|
||||||
- hostname
|
- hostname
|
||||||
- dns_label
|
- dns_label
|
||||||
SetupKey:
|
SetupKey:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -199,19 +199,19 @@ components:
|
|||||||
description: A number of times this key can be used. The value of 0 indicates the unlimited usage.
|
description: A number of times this key can be used. The value of 0 indicates the unlimited usage.
|
||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- key
|
- key
|
||||||
- name
|
- name
|
||||||
- expires
|
- expires
|
||||||
- type
|
- type
|
||||||
- valid
|
- valid
|
||||||
- revoked
|
- revoked
|
||||||
- used_times
|
- used_times
|
||||||
- last_used
|
- last_used
|
||||||
- state
|
- state
|
||||||
- auto_groups
|
- auto_groups
|
||||||
- updated_at
|
- updated_at
|
||||||
- usage_limit
|
- usage_limit
|
||||||
SetupKeyRequest:
|
SetupKeyRequest:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -255,9 +255,9 @@ components:
|
|||||||
description: Count of peers associated to the group
|
description: Count of peers associated to the group
|
||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- name
|
- name
|
||||||
- peers_count
|
- peers_count
|
||||||
Group:
|
Group:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/GroupMinimum'
|
- $ref: '#/components/schemas/GroupMinimum'
|
||||||
@@ -269,7 +269,7 @@ components:
|
|||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/PeerMinimum'
|
$ref: '#/components/schemas/PeerMinimum'
|
||||||
required:
|
required:
|
||||||
- peers
|
- peers
|
||||||
PatchMinimum:
|
PatchMinimum:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -313,10 +313,10 @@ components:
|
|||||||
description: Rule flow, currently, only "bidirect" for bi-directional traffic is accepted
|
description: Rule flow, currently, only "bidirect" for bi-directional traffic is accepted
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- description
|
- description
|
||||||
- disabled
|
- disabled
|
||||||
- flow
|
- flow
|
||||||
Rule:
|
Rule:
|
||||||
allOf:
|
allOf:
|
||||||
- type: object
|
- type: object
|
||||||
@@ -325,7 +325,7 @@ components:
|
|||||||
description: Rule ID
|
description: Rule ID
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- $ref: '#/components/schemas/RuleMinimum'
|
- $ref: '#/components/schemas/RuleMinimum'
|
||||||
- type: object
|
- type: object
|
||||||
properties:
|
properties:
|
||||||
@@ -340,8 +340,8 @@ components:
|
|||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/GroupMinimum'
|
$ref: '#/components/schemas/GroupMinimum'
|
||||||
required:
|
required:
|
||||||
- sources
|
- sources
|
||||||
- destinations
|
- destinations
|
||||||
RulePatchOperation:
|
RulePatchOperation:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/PatchMinimum'
|
- $ref: '#/components/schemas/PatchMinimum'
|
||||||
@@ -430,7 +430,7 @@ components:
|
|||||||
ns_type:
|
ns_type:
|
||||||
description: Nameserver Type
|
description: Nameserver Type
|
||||||
type: string
|
type: string
|
||||||
enum: ["udp"]
|
enum: [ "udp" ]
|
||||||
port:
|
port:
|
||||||
description: Nameserver Port
|
description: Nameserver Port
|
||||||
type: integer
|
type: integer
|
||||||
@@ -500,7 +500,7 @@ components:
|
|||||||
path:
|
path:
|
||||||
description: Nameserver group field to update in form /<field>
|
description: Nameserver group field to update in form /<field>
|
||||||
type: string
|
type: string
|
||||||
enum: [ "name", "description", "enabled", "groups", "nameservers", "primary", "domains" ]
|
enum: [ "name", "description", "enabled", "groups", "nameservers", "primary", "domains" ]
|
||||||
required:
|
required:
|
||||||
- path
|
- path
|
||||||
Event:
|
Event:
|
||||||
@@ -513,16 +513,13 @@ components:
|
|||||||
description: The date and time when the event occurred
|
description: The date and time when the event occurred
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
operation:
|
activity:
|
||||||
description: The operation (or action) that occurred during the event
|
description: The activity that occurred during the event
|
||||||
type: string
|
type: string
|
||||||
operation_code:
|
activity_code:
|
||||||
description: The numeric code of the operation (or action) that occurred during the event
|
description: The string code of the activity that occurred during the event
|
||||||
type: integer
|
|
||||||
type:
|
|
||||||
description: The type of the event that occurred. Indicates whether it was a management or device event
|
|
||||||
type: string
|
type: string
|
||||||
enum: ["device", "management"]
|
enum: [ "account.create", "user.join", "user.invite", "user.peer.add", "setupkey.peer.add" ]
|
||||||
initiator_id:
|
initiator_id:
|
||||||
description: The ID of the initiator of the event. E.g., an ID of a user that triggered the event.
|
description: The ID of the initiator of the event. E.g., an ID of a user that triggered the event.
|
||||||
type: string
|
type: string
|
||||||
@@ -532,33 +529,32 @@ components:
|
|||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- timestamp
|
- timestamp
|
||||||
- operation
|
- activity
|
||||||
- operation_code
|
- activity_code
|
||||||
- type
|
|
||||||
- initiator_id
|
- initiator_id
|
||||||
- target_id
|
- target_id
|
||||||
responses:
|
responses:
|
||||||
not_found:
|
not_found:
|
||||||
description: Resource not found
|
description: Resource not found
|
||||||
content: {}
|
content: { }
|
||||||
validation_failed_simple:
|
validation_failed_simple:
|
||||||
description: Validation failed
|
description: Validation failed
|
||||||
content: {}
|
content: { }
|
||||||
bad_request:
|
bad_request:
|
||||||
description: Bad Request
|
description: Bad Request
|
||||||
content: {}
|
content: { }
|
||||||
internal_error:
|
internal_error:
|
||||||
description: Internal Server Error
|
description: Internal Server Error
|
||||||
content: { }
|
content: { }
|
||||||
validation_failed:
|
validation_failed:
|
||||||
description: Validation failed
|
description: Validation failed
|
||||||
content: {}
|
content: { }
|
||||||
forbidden:
|
forbidden:
|
||||||
description: Forbidden
|
description: Forbidden
|
||||||
content: {}
|
content: { }
|
||||||
requires_authentication:
|
requires_authentication:
|
||||||
description: Requires authentication
|
description: Requires authentication
|
||||||
content: {}
|
content: { }
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
BearerAuth:
|
BearerAuth:
|
||||||
type: http
|
type: http
|
||||||
@@ -570,9 +566,9 @@ paths:
|
|||||||
/api/users:
|
/api/users:
|
||||||
get:
|
get:
|
||||||
summary: Returns a list of all users
|
summary: Returns a list of all users
|
||||||
tags: [Users]
|
tags: [ Users ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: []
|
- BearerAuth: [ ]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: A JSON array of Users
|
description: A JSON array of Users
|
||||||
@@ -593,7 +589,7 @@ paths:
|
|||||||
/api/users/:
|
/api/users/:
|
||||||
post:
|
post:
|
||||||
summary: Create a User (invite)
|
summary: Create a User (invite)
|
||||||
tags: [ Users]
|
tags: [ Users ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
requestBody:
|
requestBody:
|
||||||
@@ -620,7 +616,7 @@ paths:
|
|||||||
/api/users/{id}:
|
/api/users/{id}:
|
||||||
put:
|
put:
|
||||||
summary: Update information about a User
|
summary: Update information about a User
|
||||||
tags: [ Users]
|
tags: [ Users ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -654,9 +650,9 @@ paths:
|
|||||||
/api/peers:
|
/api/peers:
|
||||||
get:
|
get:
|
||||||
summary: Returns a list of all peers
|
summary: Returns a list of all peers
|
||||||
tags: [Peers]
|
tags: [ Peers ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: []
|
- BearerAuth: [ ]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: A JSON Array of Peers
|
description: A JSON Array of Peers
|
||||||
@@ -677,7 +673,7 @@ paths:
|
|||||||
/api/peers/{id}:
|
/api/peers/{id}:
|
||||||
get:
|
get:
|
||||||
summary: Get information about a peer
|
summary: Get information about a peer
|
||||||
tags: [Peers]
|
tags: [ Peers ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -704,7 +700,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
put:
|
put:
|
||||||
summary: Update information about a peer
|
summary: Update information about a peer
|
||||||
tags: [Peers]
|
tags: [ Peers ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -745,7 +741,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
delete:
|
delete:
|
||||||
summary: Delete a peer
|
summary: Delete a peer
|
||||||
tags: [Peers]
|
tags: [ Peers ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -758,7 +754,7 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Delete status code
|
description: Delete status code
|
||||||
content: {}
|
content: { }
|
||||||
'400':
|
'400':
|
||||||
"$ref": "#/components/responses/bad_request"
|
"$ref": "#/components/responses/bad_request"
|
||||||
'401':
|
'401':
|
||||||
@@ -770,7 +766,7 @@ paths:
|
|||||||
/api/setup-keys:
|
/api/setup-keys:
|
||||||
get:
|
get:
|
||||||
summary: Returns a list of all Setup Keys
|
summary: Returns a list of all Setup Keys
|
||||||
tags: [Setup Keys]
|
tags: [ Setup Keys ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
responses:
|
responses:
|
||||||
@@ -792,7 +788,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
post:
|
post:
|
||||||
summary: Creates a Setup Key
|
summary: Creates a Setup Key
|
||||||
tags: [Setup Keys]
|
tags: [ Setup Keys ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
requestBody:
|
requestBody:
|
||||||
@@ -819,7 +815,7 @@ paths:
|
|||||||
/api/setup-keys/{id}:
|
/api/setup-keys/{id}:
|
||||||
get:
|
get:
|
||||||
summary: Get information about a Setup Key
|
summary: Get information about a Setup Key
|
||||||
tags: [Setup Keys]
|
tags: [ Setup Keys ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -846,7 +842,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
put:
|
put:
|
||||||
summary: Update information about a Setup Key
|
summary: Update information about a Setup Key
|
||||||
tags: [Setup Keys]
|
tags: [ Setup Keys ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -879,7 +875,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
delete:
|
delete:
|
||||||
summary: Delete a Setup Key
|
summary: Delete a Setup Key
|
||||||
tags: [Setup Keys]
|
tags: [ Setup Keys ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -892,7 +888,7 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Delete status code
|
description: Delete status code
|
||||||
content: {}
|
content: { }
|
||||||
'400':
|
'400':
|
||||||
"$ref": "#/components/responses/bad_request"
|
"$ref": "#/components/responses/bad_request"
|
||||||
'401':
|
'401':
|
||||||
@@ -904,7 +900,7 @@ paths:
|
|||||||
/api/groups:
|
/api/groups:
|
||||||
get:
|
get:
|
||||||
summary: Returns a list of all Groups
|
summary: Returns a list of all Groups
|
||||||
tags: [Groups]
|
tags: [ Groups ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
responses:
|
responses:
|
||||||
@@ -926,7 +922,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
post:
|
post:
|
||||||
summary: Creates a Group
|
summary: Creates a Group
|
||||||
tags: [Groups]
|
tags: [ Groups ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
requestBody:
|
requestBody:
|
||||||
@@ -962,7 +958,7 @@ paths:
|
|||||||
/api/groups/{id}:
|
/api/groups/{id}:
|
||||||
get:
|
get:
|
||||||
summary: Get information about a Group
|
summary: Get information about a Group
|
||||||
tags: [Groups]
|
tags: [ Groups ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -989,7 +985,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
put:
|
put:
|
||||||
summary: Update/Replace a Group
|
summary: Update/Replace a Group
|
||||||
tags: [Groups]
|
tags: [ Groups ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -1064,7 +1060,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
delete:
|
delete:
|
||||||
summary: Delete a Group
|
summary: Delete a Group
|
||||||
tags: [Groups]
|
tags: [ Groups ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -1077,7 +1073,7 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Delete status code
|
description: Delete status code
|
||||||
content: {}
|
content: { }
|
||||||
'400':
|
'400':
|
||||||
"$ref": "#/components/responses/bad_request"
|
"$ref": "#/components/responses/bad_request"
|
||||||
'401':
|
'401':
|
||||||
@@ -1089,7 +1085,7 @@ paths:
|
|||||||
/api/rules:
|
/api/rules:
|
||||||
get:
|
get:
|
||||||
summary: Returns a list of all Rules
|
summary: Returns a list of all Rules
|
||||||
tags: [Rules]
|
tags: [ Rules ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
responses:
|
responses:
|
||||||
@@ -1111,7 +1107,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
post:
|
post:
|
||||||
summary: Creates a Rule
|
summary: Creates a Rule
|
||||||
tags: [Rules]
|
tags: [ Rules ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
requestBody:
|
requestBody:
|
||||||
@@ -1141,7 +1137,7 @@ paths:
|
|||||||
/api/rules/{id}:
|
/api/rules/{id}:
|
||||||
get:
|
get:
|
||||||
summary: Get information about a Rules
|
summary: Get information about a Rules
|
||||||
tags: [Rules]
|
tags: [ Rules ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -1168,7 +1164,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
put:
|
put:
|
||||||
summary: Update/Replace a Rule
|
summary: Update/Replace a Rule
|
||||||
tags: [Rules]
|
tags: [ Rules ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -1247,7 +1243,7 @@ paths:
|
|||||||
"$ref": "#/components/responses/internal_error"
|
"$ref": "#/components/responses/internal_error"
|
||||||
delete:
|
delete:
|
||||||
summary: Delete a Rule
|
summary: Delete a Rule
|
||||||
tags: [Rules]
|
tags: [ Rules ]
|
||||||
security:
|
security:
|
||||||
- BearerAuth: [ ]
|
- BearerAuth: [ ]
|
||||||
parameters:
|
parameters:
|
||||||
@@ -1260,7 +1256,7 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Delete status code
|
description: Delete status code
|
||||||
content: {}
|
content: { }
|
||||||
'400':
|
'400':
|
||||||
"$ref": "#/components/responses/bad_request"
|
"$ref": "#/components/responses/bad_request"
|
||||||
'401':
|
'401':
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ const (
|
|||||||
BearerAuthScopes = "BearerAuth.Scopes"
|
BearerAuthScopes = "BearerAuth.Scopes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Defines values for EventType.
|
// Defines values for EventActivityCode.
|
||||||
const (
|
const (
|
||||||
EventTypeDevice EventType = "device"
|
EventActivityCodeAccountCreate EventActivityCode = "account.create"
|
||||||
EventTypeManagement EventType = "management"
|
EventActivityCodeSetupkeyPeerAdd EventActivityCode = "setupkey.peer.add"
|
||||||
|
EventActivityCodeUserInvite EventActivityCode = "user.invite"
|
||||||
|
EventActivityCodeUserJoin EventActivityCode = "user.join"
|
||||||
|
EventActivityCodeUserPeerAdd EventActivityCode = "user.peer.add"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Defines values for GroupPatchOperationOp.
|
// Defines values for GroupPatchOperationOp.
|
||||||
@@ -105,30 +108,27 @@ const (
|
|||||||
|
|
||||||
// Event defines model for Event.
|
// Event defines model for Event.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
|
// Activity The activity that occurred during the event
|
||||||
|
Activity string `json:"activity"`
|
||||||
|
|
||||||
|
// ActivityCode The string code of the activity that occurred during the event
|
||||||
|
ActivityCode EventActivityCode `json:"activity_code"`
|
||||||
|
|
||||||
// Id Event unique identifier
|
// Id Event unique identifier
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
|
|
||||||
// InitiatorId The ID of the initiator of the event. E.g., an ID of a user that triggered the event.
|
// InitiatorId The ID of the initiator of the event. E.g., an ID of a user that triggered the event.
|
||||||
InitiatorId string `json:"initiator_id"`
|
InitiatorId string `json:"initiator_id"`
|
||||||
|
|
||||||
// Operation The operation (or action) that occurred during the event
|
|
||||||
Operation string `json:"operation"`
|
|
||||||
|
|
||||||
// OperationCode The numeric code of the operation (or action) that occurred during the event
|
|
||||||
OperationCode int `json:"operation_code"`
|
|
||||||
|
|
||||||
// TargetId The ID of the target of the event. E.g., an ID of the peer that a user removed.
|
// TargetId The ID of the target of the event. E.g., an ID of the peer that a user removed.
|
||||||
TargetId string `json:"target_id"`
|
TargetId string `json:"target_id"`
|
||||||
|
|
||||||
// Timestamp The date and time when the event occurred
|
// Timestamp The date and time when the event occurred
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
|
|
||||||
// Type The type of the event that occurred. Indicates whether it was a management or device event
|
|
||||||
Type EventType `json:"type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventType The type of the event that occurred. Indicates whether it was a management or device event
|
// EventActivityCode The string code of the activity that occurred during the event
|
||||||
type EventType string
|
type EventActivityCode string
|
||||||
|
|
||||||
// Group defines model for Group.
|
// Group defines model for Group.
|
||||||
type Group struct {
|
type Group struct {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (h *Events) GetEvents(w http.ResponseWriter, r *http.Request) {
|
|||||||
util.WriteError(err, w)
|
util.WriteError(err, w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var events []*api.Event
|
events := make([]*api.Event, 0)
|
||||||
for _, e := range accountEvents {
|
for _, e := range accountEvents {
|
||||||
events = append(events, toEventResponse(e))
|
events = append(events, toEventResponse(e))
|
||||||
}
|
}
|
||||||
@@ -53,12 +53,11 @@ func (h *Events) GetEvents(w http.ResponseWriter, r *http.Request) {
|
|||||||
func toEventResponse(event *activity.Event) *api.Event {
|
func toEventResponse(event *activity.Event) *api.Event {
|
||||||
|
|
||||||
return &api.Event{
|
return &api.Event{
|
||||||
Id: fmt.Sprint(event.ID),
|
Id: fmt.Sprint(event.ID),
|
||||||
InitiatorId: event.ModifierID,
|
InitiatorId: event.InitiatorID,
|
||||||
Operation: event.Operation,
|
Activity: event.Activity.Message(),
|
||||||
OperationCode: int(event.OperationCode),
|
ActivityCode: api.EventActivityCode(event.Activity.StringCode()),
|
||||||
TargetId: event.TargetID,
|
TargetId: event.TargetID,
|
||||||
Timestamp: event.Timestamp,
|
Timestamp: event.Timestamp,
|
||||||
Type: api.EventType(event.Type),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,7 +363,6 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (*
|
|||||||
|
|
||||||
opEvent := &activity.Event{
|
opEvent := &activity.Event{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
Type: activity.ManagementEvent,
|
|
||||||
AccountID: account.Id,
|
AccountID: account.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,11 +378,11 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
account.SetupKeys[sk.Key] = sk.IncrementUsage()
|
account.SetupKeys[sk.Key] = sk.IncrementUsage()
|
||||||
opEvent.ModifierID = sk.Id
|
opEvent.InitiatorID = sk.Id
|
||||||
opEvent.OperationCode = activity.AddPeerWithKeyOperation
|
opEvent.Activity = activity.PeerAddedWithSetupKey
|
||||||
} else {
|
} else {
|
||||||
opEvent.ModifierID = userID
|
opEvent.InitiatorID = userID
|
||||||
opEvent.OperationCode = activity.AddPeerByUserOperation
|
opEvent.Activity = activity.PeerAddedByUser
|
||||||
}
|
}
|
||||||
|
|
||||||
takenIps := account.getTakenIPs()
|
takenIps := account.getTakenIPs()
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/netbirdio/netbird/management/server/idp"
|
"github.com/netbirdio/netbird/management/server/idp"
|
||||||
|
"github.com/netbirdio/netbird/management/server/jwtclaims"
|
||||||
"github.com/netbirdio/netbird/management/server/status"
|
"github.com/netbirdio/netbird/management/server/status"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/jwtclaims"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user