mirror of
https://github.com/drone-plugins/drone-download.git
synced 2026-06-16 14:50:33 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ce7e9cd1c9 | |||
| 77d760c2b9 | |||
| a367d8be06 | |||
| cb10efa30b | |||
| 0746c93e6d | |||
| f60fbda48d | |||
| d0e70bf7f1 |
+1
-1
@@ -45,7 +45,7 @@ deploy_script:
|
||||
if ( $env:APPVEYOR_PULL_REQUEST_NUMBER ) {
|
||||
Write-Host Nothing to deploy.
|
||||
} else {
|
||||
docker login --username $env:DOCKER_USERNAME --password $env:DOCKER_PASSWORD
|
||||
echo $env:DOCKER_PASSWORD | docker login --username $env:DOCKER_USERNAME --password-stdin
|
||||
|
||||
if ( $env:APPVEYOR_REPO_TAG -eq 'true' ) {
|
||||
$major,$minor,$patch = $env:APPVEYOR_REPO_TAG_NAME.substring(1).split('.')
|
||||
|
||||
@@ -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",
|
||||
@@ -52,9 +57,9 @@ func main() {
|
||||
EnvVar: "PLUGIN_MD5",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "sha265-checksum",
|
||||
Usage: "checksum in sha265 format",
|
||||
EnvVar: "PLUGIN_SHA265",
|
||||
Name: "sha256-checksum",
|
||||
Usage: "checksum in sha256 format",
|
||||
EnvVar: "PLUGIN_SHA256,PLUGIN_SHA265",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
SHA256: c.String("sha256-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
|
||||
SHA256 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 {
|
||||
@@ -114,7 +121,7 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
}
|
||||
|
||||
if p.Config.SHA265 != "" {
|
||||
if p.Config.SHA256 != "" {
|
||||
h := sha256.New()
|
||||
|
||||
if _, err := io.Copy(h, resp.Body); err != nil {
|
||||
@@ -124,7 +131,7 @@ func (p Plugin) Exec() error {
|
||||
check := fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
if p.Config.MD5 != check {
|
||||
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.SHA265)
|
||||
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.SHA256)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user