mirror of
https://github.com/drone-plugins/drone-download.git
synced 2026-06-04 10:15:28 +08:00
added ability to specify a authorization header
This commit is contained in:
@@ -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"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user