MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / CreateWebhook

Method CreateWebhook

internal/store/webhooks.go:11–37  ·  view source on GitHub ↗

CreateWebhook registers a new webhook for a workspace.

(workspaceID string, input models.WebhookCreate)

Source from the content-addressed store, hash-verified

9
10// CreateWebhook registers a new webhook for a workspace.
11func (s *Store) CreateWebhook(workspaceID string, input models.WebhookCreate) (*models.Webhook, error) {
12 id := newID()
13 ts := now()
14
15 evts := input.Events
16 if evts == "" {
17 evts = `["*"]`
18 }
19
20 // Encrypt the HMAC secret at rest. With no encryption key configured
21 // (common on self-host) encrypt() returns the plaintext unchanged, so
22 // this stays a no-op fallback rather than a hard requirement.
23 encSecret, err := s.encrypt(input.Secret)
24 if err != nil {
25 return nil, fmt.Errorf("encrypt webhook secret: %w", err)
26 }
27
28 _, err = s.db.Exec(s.q(`
29 INSERT INTO webhooks (id, workspace_id, url, secret, events, active, created_at, updated_at, failure_count)
30 VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)
31 `), id, workspaceID, input.URL, encSecret, evts, s.dialect.BoolToInt(true), ts, ts)
32 if err != nil {
33 return nil, fmt.Errorf("insert webhook: %w", err)
34 }
35
36 return s.GetWebhook(id)
37}
38
39// GetWebhook retrieves a single webhook by ID.
40func (s *Store) GetWebhook(id string) (*models.Webhook, error) {

Calls 7

encryptMethod · 0.95
qMethod · 0.95
GetWebhookMethod · 0.95
newIDFunction · 0.85
nowFunction · 0.85
ExecMethod · 0.80
BoolToIntMethod · 0.65