2025-04-19 21:29:26 +02:00
|
|
|
package webhooks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WebhookData is the data structure for the webhook payload.
|
|
|
|
type WebhookData struct {
|
|
|
|
// Event is the event type (e.g. create, update, delete)
|
|
|
|
Event WebhookEvent `json:"event" example:"create"`
|
|
|
|
|
|
|
|
// Entity is the entity type (e.g. user, peer, interface)
|
|
|
|
Entity WebhookEntity `json:"entity" example:"user"`
|
|
|
|
|
|
|
|
// Identifier is the identifier of the entity
|
|
|
|
Identifier string `json:"identifier" example:"user-123"`
|
|
|
|
|
|
|
|
// Payload is the payload of the event
|
|
|
|
Payload any `json:"payload"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize serializes the WebhookData to JSON and returns it as an io.Reader.
|
|
|
|
func (d *WebhookData) Serialize() (io.Reader, error) {
|
|
|
|
data, err := json.Marshal(d)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes.NewReader(data), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type WebhookEntity = string
|
|
|
|
|
|
|
|
const (
|
|
|
|
WebhookEntityUser WebhookEntity = "user"
|
|
|
|
WebhookEntityPeer WebhookEntity = "peer"
|
|
|
|
WebhookEntityInterface WebhookEntity = "interface"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WebhookEvent = string
|
|
|
|
|
|
|
|
const (
|
add webhook event for peer state change (#444) (#468)
* add webhook event for peer state change (#444)
new event types: connect and disconnect
example payload:
```json
{
"event": "connect",
"entity": "peer",
"identifier": "Fb5TaziAs1WrPBjC/MFbWsIelVXvi0hDKZ3YQM9wmU8=",
"payload": {
"PeerId": "Fb5TaziAs1WrPBjC/MFbWsIelVXvi0hDKZ3YQM9wmU8=",
"IsConnected": true,
"IsPingable": false,
"LastPing": null,
"BytesReceived": 1860,
"BytesTransmitted": 10824,
"LastHandshake": "2025-06-26T23:04:33.325216659+02:00",
"Endpoint": "10.55.66.77:33874",
"LastSessionStart": "2025-06-26T22:50:40.10221606+02:00"
}
}
```
* add webhook docs (#444)
2025-06-27 12:37:10 +02:00
|
|
|
WebhookEventCreate WebhookEvent = "create"
|
|
|
|
WebhookEventUpdate WebhookEvent = "update"
|
|
|
|
WebhookEventDelete WebhookEvent = "delete"
|
|
|
|
WebhookEventConnect WebhookEvent = "connect"
|
|
|
|
WebhookEventDisconnect WebhookEvent = "disconnect"
|
2025-04-19 21:29:26 +02:00
|
|
|
)
|