Change token to token_value and add token_type for support other token type

This commit is contained in:
Suriya.S
2020-08-02 00:35:29 +07:00
parent 07a4386c3d
commit b2d83444d1
2 changed files with 17 additions and 10 deletions
+13 -6
View File
@@ -34,11 +34,17 @@ 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: "token-value",
Usage: "token value",
EnvVar: "PLUGIN_TOKEN_VALUE,WEBHOOK_TOKEN_VALUE",
},
cli.StringFlag{
Name: "token-type",
Usage: "type of token",
EnvVar: "PLUGIN_TOKEN_TYPE,WEBHOOK_TOKEN_TYPE",
Value: "Bearer",
},
cli.StringFlag{
Name: "content-type",
Usage: "content type",
@@ -205,7 +211,8 @@ func run(c *cli.Context) error {
Method: c.String("method"),
Username: c.String("username"),
Password: c.String("password"),
Token: c.String("token"),
TokenValue: c.String("token-value"),
TokenType: c.String("token-type"),
ContentType: c.String("content-type"),
Template: c.String("template"),
Headers: c.StringSlice("headers"),
+4 -4
View File
@@ -43,7 +43,8 @@ type (
Method string
Username string
Password string
Token string
TokenValue string
TokenType string
ContentType string
Template string
Headers []string
@@ -142,11 +143,10 @@ 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))
if p.Config.TokenValue != "" {
req.Header.Set("Authorization", fmt.Sprintf("%s %s", p.Config.TokenType, p.Config.TokenValue))
}
client := http.DefaultClient
if p.Config.SkipVerify {