Add headers to webhook.

This commit is contained in:
Yang Luo
2021-12-26 20:40:13 +08:00
parent 5015bf1c7d
commit 0c665edcbc
6 changed files with 170 additions and 8 deletions

View File

@ -16,11 +16,11 @@ package object
import (
"fmt"
"github.com/casbin/casdoor/util"
"runtime"
"github.com/astaxie/beego"
"github.com/casbin/casdoor/conf"
"github.com/casbin/casdoor/util"
//_ "github.com/denisenkom/go-mssqldb" // db = mssql
_ "github.com/go-sql-driver/mysql" // db = mysql
//_ "github.com/lib/pq" // db = postgres
@ -185,4 +185,4 @@ func GetSession(owner string, offset, limit int, field, value, sortField, sortOr
session = session.Desc(util.SnakeString(sortField))
}
return session
}
}

View File

@ -21,17 +21,23 @@ import (
"xorm.io/core"
)
type Header struct {
Name string `json:"name"`
Value string `json:"value"`
}
type Webhook struct {
Owner string `xorm:"varchar(100) notnull pk" json:"owner"`
Name string `xorm:"varchar(100) notnull pk" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
Url string `xorm:"varchar(100)" json:"url"`
Method string `xorm:"varchar(100)" json:"method"`
ContentType string `xorm:"varchar(100)" json:"contentType"`
Events []string `xorm:"varchar(100)" json:"events"`
Organization string `xorm:"varchar(100) index" json:"organization"`
Url string `xorm:"varchar(100)" json:"url"`
Method string `xorm:"varchar(100)" json:"method"`
ContentType string `xorm:"varchar(100)" json:"contentType"`
Headers []*Header `xorm:"mediumtext" json:"headers"`
Events []string `xorm:"varchar(100)" json:"events"`
}
func GetWebhookCount(owner, field, value string) int {

View File

@ -33,6 +33,10 @@ func sendWebhook(webhook *Webhook, record *Record) error {
req.Header.Set("Content-Type", webhook.ContentType)
for _, header := range webhook.Headers {
req.Header.Set(header.Name, header.Value)
}
_, err = client.Do(req)
return err
}