diff options
| author | Ibrahim Konsowa <imkonsowa@gmail.com> | 2025-07-10 20:22:05 +0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 09:22:05 -0700 |
| commit | 93bbaa1fb486f95ff40f5891057f8415bdf3fc27 (patch) | |
| tree | 7365c496d06e00c594fcac35e706e29c507bce04 /weed/notification/webhook/webhook_queue.go | |
| parent | 804979d68bdc1763878b91741e22c913fba62d73 (diff) | |
| download | seaweedfs-93bbaa1fb486f95ff40f5891057f8415bdf3fc27.tar.xz seaweedfs-93bbaa1fb486f95ff40f5891057f8415bdf3fc27.zip | |
[Notifications] Support webhook notifications (#6962)
Add webhook notification support
Diffstat (limited to 'weed/notification/webhook/webhook_queue.go')
| -rw-r--r-- | weed/notification/webhook/webhook_queue.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/weed/notification/webhook/webhook_queue.go b/weed/notification/webhook/webhook_queue.go new file mode 100644 index 000000000..d209b74e2 --- /dev/null +++ b/weed/notification/webhook/webhook_queue.go @@ -0,0 +1,71 @@ +package webhook + +import ( + "fmt" + "net/url" + + "github.com/seaweedfs/seaweedfs/weed/notification" + "github.com/seaweedfs/seaweedfs/weed/util" + "google.golang.org/protobuf/proto" +) + +// client defines the interface for transport client +// could be extended to support gRPC +type client interface { + sendMessage(key string, message proto.Message) error +} + +func init() { + notification.MessageQueues = append(notification.MessageQueues, &WebhookQueue{}) +} + +type WebhookQueue struct { + client client +} + +type config struct { + endpoint string + authBearerToken string +} + +func (c *config) validate() error { + _, err := url.Parse(c.endpoint) + if err != nil { + return fmt.Errorf("invalid webhook endpoint %w", err) + } + + return nil +} + +func (w *WebhookQueue) GetName() string { + return "webhook" +} + +func (w *WebhookQueue) Initialize(configuration util.Configuration, prefix string) error { + c := &config{ + endpoint: configuration.GetString(prefix + "endpoint"), + authBearerToken: configuration.GetString(prefix + "bearer_token"), + } + + if err := c.validate(); err != nil { + return err + } + + return w.initialize(c) +} + +func (w *WebhookQueue) initialize(cfg *config) error { + client, err := newHTTPClient(cfg) + if err != nil { + return fmt.Errorf("failed to create webhook client: %v", err) + } + w.client = client + return nil +} + +func (w *WebhookQueue) SendMessage(key string, message proto.Message) error { + if w.client == nil { + return fmt.Errorf("webhook client not initialized") + } + return w.client.sendMessage(key, message) +} |
