mirror of
https://github.com/drone-plugins/drone-webhook.git
synced 2026-06-04 18:24:05 +08:00
Customizable signature header name, rename secret to signature_secret
This commit is contained in:
@@ -71,9 +71,15 @@ func main() {
|
||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "secret",
|
||||
Name: "signature_header",
|
||||
Usage: "header name to use in request",
|
||||
EnvVar: "PLUGIN_SIGNATURE_HEADER,WEBHOOK_SIGNATURE_HEADER",
|
||||
Value: "X-Drone-Signature",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "signature_secret",
|
||||
Usage: "secret to generate signature",
|
||||
EnvVar: "PLUGIN_SECRET,WEBHOOK_SECRET",
|
||||
EnvVar: "PLUGIN_SIGNATURE_SECRET,WEBHOOK_SIGNATURE_SECRET",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo.owner",
|
||||
@@ -191,17 +197,18 @@ func run(c *cli.Context) error {
|
||||
Started: c.Int64("job.started"),
|
||||
},
|
||||
Config: Config{
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
ContentType: c.String("content-type"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
URLs: c.StringSlice("urls"),
|
||||
ValidCodes: c.IntSlice("valid-response-codes"),
|
||||
Debug: c.Bool("debug"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
Secret: c.String("secret"),
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
ContentType: c.String("content-type"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
URLs: c.StringSlice("urls"),
|
||||
ValidCodes: c.IntSlice("valid-response-codes"),
|
||||
Debug: c.Bool("debug"),
|
||||
SkipVerify: c.Bool("skip-verify"),
|
||||
SignatureHeader: c.String("signature_header"),
|
||||
SignatureSecret: c.String("signature_secret"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -40,17 +40,18 @@ type (
|
||||
}
|
||||
|
||||
Config struct {
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
ValidCodes []int
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
Secret string
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
URLs []string
|
||||
ValidCodes []int
|
||||
Debug bool
|
||||
SkipVerify bool
|
||||
SignatureHeader string
|
||||
SignatureSecret string
|
||||
}
|
||||
|
||||
Job struct {
|
||||
@@ -121,14 +122,14 @@ func (p Plugin) Exec() error {
|
||||
|
||||
req.Header.Set("Content-Type", p.Config.ContentType)
|
||||
|
||||
if p.Config.Secret != "" {
|
||||
if p.Config.SignatureSecret != "" {
|
||||
// generate signature with secret and body
|
||||
h := hmac.New(sha256.New, []byte(p.Config.Secret))
|
||||
h := hmac.New(sha256.New, []byte(p.Config.SignatureSecret))
|
||||
h.Write(b)
|
||||
sha := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
// append signature to headers
|
||||
req.Header.Set("X-Drone-Signature", fmt.Sprintf("sha256=%s", sha))
|
||||
req.Header.Set(p.Config.SignatureHeader, fmt.Sprintf("sha256=%s", sha))
|
||||
}
|
||||
|
||||
for _, value := range p.Config.Headers {
|
||||
|
||||
Reference in New Issue
Block a user