mirror of
https://github.com/drone-plugins/drone-webhook.git
synced 2026-06-13 10:31:52 +08:00
Add Bearer token authen
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
module github.com/drone-plugins/drone-webhook
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
bou.ke/monkey v1.0.1 // indirect
|
||||
github.com/aymerick/raymond v2.0.2+incompatible // indirect
|
||||
|
||||
@@ -34,6 +34,11 @@ func main() {
|
||||
Usage: "password for basic auth",
|
||||
EnvVar: "PLUGIN_PASSWORD,WEBHOOK_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "token",
|
||||
Usage: "token for Bearer token auth",
|
||||
EnvVar: "PLUGIN_TOKEN,WEBHOOK_TOKEN",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "content-type",
|
||||
Usage: "content type",
|
||||
@@ -200,6 +205,7 @@ func run(c *cli.Context) error {
|
||||
Method: c.String("method"),
|
||||
Username: c.String("username"),
|
||||
Password: c.String("password"),
|
||||
Token: c.String("token"),
|
||||
ContentType: c.String("content-type"),
|
||||
Template: c.String("template"),
|
||||
Headers: c.StringSlice("headers"),
|
||||
|
||||
@@ -43,6 +43,7 @@ type (
|
||||
Method string
|
||||
Username string
|
||||
Password string
|
||||
Token string
|
||||
ContentType string
|
||||
Template string
|
||||
Headers []string
|
||||
@@ -141,6 +142,11 @@ func (p Plugin) Exec() error {
|
||||
req.SetBasicAuth(p.Config.Username, p.Config.Password)
|
||||
}
|
||||
|
||||
if p.Config.Token != "" {
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", p.Config.Token))
|
||||
}
|
||||
|
||||
|
||||
client := http.DefaultClient
|
||||
|
||||
if p.Config.SkipVerify {
|
||||
|
||||
Reference in New Issue
Block a user