mirror of
https://github.com/drone-plugins/drone-download.git
synced 2026-06-04 18:24:21 +08:00
Add additional logging
This commit is contained in:
@@ -5,6 +5,7 @@ go 1.14
|
|||||||
require (
|
require (
|
||||||
github.com/drone-plugins/drone-plugin-lib v0.3.1
|
github.com/drone-plugins/drone-plugin-lib v0.3.1
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
|
github.com/sirupsen/logrus v1.6.0
|
||||||
github.com/urfave/cli/v2 v2.2.0
|
github.com/urfave/cli/v2 v2.2.0
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings for the plugin.
|
// Settings for the plugin.
|
||||||
@@ -84,6 +86,11 @@ func (p *Plugin) Execute() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"source": p.settings.Source,
|
||||||
|
"destination": p.settings.destination,
|
||||||
|
}).Info("Downloading file")
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("executing request failed: %w", err)
|
return fmt.Errorf("executing request failed: %w", err)
|
||||||
@@ -106,17 +113,21 @@ func (p *Plugin) Execute() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var h hash.Hash
|
var h hash.Hash
|
||||||
|
alg := ""
|
||||||
exp := ""
|
exp := ""
|
||||||
|
|
||||||
if p.settings.SHA256 != "" {
|
if p.settings.SHA256 != "" {
|
||||||
exp = p.settings.SHA256
|
exp = p.settings.SHA256
|
||||||
|
alg = "SHA256"
|
||||||
h = sha256.New()
|
h = sha256.New()
|
||||||
} else if p.settings.MD5 != "" {
|
} else if p.settings.MD5 != "" {
|
||||||
exp = p.settings.MD5
|
exp = p.settings.MD5
|
||||||
|
alg = "MD5"
|
||||||
h = md5.New()
|
h = md5.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
if exp != "" {
|
if exp != "" {
|
||||||
|
logrus.WithField("hash", alg).Info("Computing checksum")
|
||||||
target.Seek(0, 0)
|
target.Seek(0, 0)
|
||||||
|
|
||||||
if _, err := io.Copy(h, target); err != nil {
|
if _, err := io.Copy(h, target); err != nil {
|
||||||
@@ -130,6 +141,7 @@ func (p *Plugin) Execute() error {
|
|||||||
defer os.Remove(target.Name())
|
defer os.Remove(target.Name())
|
||||||
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, exp)
|
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, exp)
|
||||||
}
|
}
|
||||||
|
logrus.WithField("checksum", check).Info("Checksum matched")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user