aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2021-06-27 21:21:09 +0200
committerGitHub <noreply@github.com>2021-06-27 20:21:09 +0100
commit9b1b4b543358c212a3da2b480d361d0c1375b279 (patch)
tree2bb767491b82bde8a76bf8b3148f8b7aaae9167c /models/webhook.go
parent0b27b93728fd3cf2ecc82ac6a2b5859270543ef2 (diff)
downloadgitea-9b1b4b543358c212a3da2b480d361d0c1375b279.tar.gz
gitea-9b1b4b543358c212a3da2b480d361d0c1375b279.zip
Refactor Webhook + Add X-Hub-Signature (#16176)
This PR removes multiple unneeded fields from the `HookTask` struct and adds the two headers `X-Hub-Signature` and `X-Hub-Signature-256`. ## :warning: BREAKING :warning: * The `Secret` field is no longer passed as part of the payload. * "Breaking" change (or fix?): The webhook history shows the real called url and not the url registered in the webhook (`deliver.go`@129). Close #16115 Fixes #7788 Fixes #11755 Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/webhook.go')
-rw-r--r--models/webhook.go52
1 files changed, 23 insertions, 29 deletions
diff --git a/models/webhook.go b/models/webhook.go
index 24510cc6f7..29cfcf6ed4 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -109,6 +109,22 @@ type HookEvent struct {
HookEvents `json:"events"`
}
+// HookType is the type of a webhook
+type HookType = string
+
+// Types of webhooks
+const (
+ GITEA HookType = "gitea"
+ GOGS HookType = "gogs"
+ SLACK HookType = "slack"
+ DISCORD HookType = "discord"
+ DINGTALK HookType = "dingtalk"
+ TELEGRAM HookType = "telegram"
+ MSTEAMS HookType = "msteams"
+ FEISHU HookType = "feishu"
+ MATRIX HookType = "matrix"
+)
+
// HookStatus is the status of a web hook
type HookStatus int
@@ -126,17 +142,15 @@ type Webhook struct {
OrgID int64 `xorm:"INDEX"`
IsSystemWebhook bool
URL string `xorm:"url TEXT"`
- Signature string `xorm:"TEXT"`
HTTPMethod string `xorm:"http_method"`
ContentType HookContentType
Secret string `xorm:"TEXT"`
Events string `xorm:"TEXT"`
*HookEvent `xorm:"-"`
- IsSSL bool `xorm:"is_ssl"`
- IsActive bool `xorm:"INDEX"`
- Type HookTaskType `xorm:"VARCHAR(16) 'type'"`
- Meta string `xorm:"TEXT"` // store hook-specific attributes
- LastStatus HookStatus // Last delivery status
+ IsActive bool `xorm:"INDEX"`
+ Type HookType `xorm:"VARCHAR(16) 'type'"`
+ Meta string `xorm:"TEXT"` // store hook-specific attributes
+ LastStatus HookStatus // Last delivery status
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -558,22 +572,6 @@ func copyDefaultWebhooksToRepo(e Engine, repoID int64) error {
// \___|_ / \____/ \____/|__|_ \ |____| (____ /____ >__|_ \
// \/ \/ \/ \/ \/
-// HookTaskType is the type of an hook task
-type HookTaskType = string
-
-// Types of hook tasks
-const (
- GITEA HookTaskType = "gitea"
- GOGS HookTaskType = "gogs"
- SLACK HookTaskType = "slack"
- DISCORD HookTaskType = "discord"
- DINGTALK HookTaskType = "dingtalk"
- TELEGRAM HookTaskType = "telegram"
- MSTEAMS HookTaskType = "msteams"
- FEISHU HookTaskType = "feishu"
- MATRIX HookTaskType = "matrix"
-)
-
// HookEventType is the type of an hook event
type HookEventType string
@@ -635,7 +633,9 @@ func (h HookEventType) Event() string {
// HookRequest represents hook task request information.
type HookRequest struct {
- Headers map[string]string `json:"headers"`
+ URL string `json:"url"`
+ HTTPMethod string `json:"http_method"`
+ Headers map[string]string `json:"headers"`
}
// HookResponse represents hook task response information.
@@ -651,15 +651,9 @@ type HookTask struct {
RepoID int64 `xorm:"INDEX"`
HookID int64
UUID string
- Typ HookTaskType `xorm:"VARCHAR(16) index"`
- URL string `xorm:"TEXT"`
- Signature string `xorm:"TEXT"`
api.Payloader `xorm:"-"`
PayloadContent string `xorm:"TEXT"`
- HTTPMethod string `xorm:"http_method"`
- ContentType HookContentType
EventType HookEventType
- IsSSL bool
IsDelivered bool
Delivered int64
DeliveredString string `xorm:"-"`