added ability to specify a authorization header

This commit is contained in:
Patrick Jahns
2018-09-25 12:56:29 +02:00
parent 67694d2750
commit 0746c93e6d
2 changed files with 28 additions and 15 deletions
+13 -7
View File
@@ -31,6 +31,11 @@ func main() {
Usage: "destination for the download",
EnvVar: "PLUGIN_DESTINATION",
},
cli.StringFlag{
Name: "authorization",
Usage: "value to send in the authorization header",
EnvVar: "PLUGIN_AUTHORIZATION,DOWNLOAD_AUTHORIZATION",
},
cli.StringFlag{
Name: "username",
Usage: "username for basic auth",
@@ -66,13 +71,14 @@ func main() {
func run(c *cli.Context) error {
plugin := Plugin{
Config: Config{
Source: c.String("source"),
Destination: c.String("destination"),
Username: c.String("username"),
Password: c.String("password"),
SkipVerify: c.Bool("skip-verify"),
MD5: c.String("md5-checksum"),
SHA265: c.String("sha265-checksum"),
Source: c.String("source"),
Destination: c.String("destination"),
Authorization: c.String("authorization"),
Username: c.String("username"),
Password: c.String("password"),
SkipVerify: c.Bool("skip-verify"),
MD5: c.String("md5-checksum"),
SHA265: c.String("sha265-checksum"),
},
}
+15 -8
View File
@@ -19,13 +19,14 @@ import (
type (
Config struct {
Source string
Destination string
Username string
Password string
SkipVerify bool
MD5 string
SHA265 string
Source string
Destination string
Authorization string
Username string
Password string
SkipVerify bool
MD5 string
SHA265 string
}
Plugin struct {
@@ -61,7 +62,9 @@ func (p Plugin) Exec() error {
if p.Config.Username != "" && p.Config.Password != "" {
req.SetBasicAuth(p.Config.Username, p.Config.Password)
}
if p.Config.Authorization != "" {
req.Header.Add("Authorization", p.Config.Authorization)
}
return nil
},
}
@@ -80,6 +83,10 @@ func (p Plugin) Exec() error {
req.SetBasicAuth(p.Config.Username, p.Config.Password)
}
if p.Config.Authorization != "" {
req.Header.Add("Authorization", p.Config.Authorization)
}
resp, err := client.Do(req)
if err != nil {