Add Bearer token authen

This commit is contained in:
Suriya.S
2020-08-01 11:08:30 +07:00
parent 63eabce274
commit 739613d9dc
3 changed files with 14 additions and 0 deletions
+2
View File
@@ -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
+6
View File
@@ -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"),
+6
View File
@@ -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 {