Add additional logging

This commit is contained in:
Don
2020-06-17 09:18:55 -07:00
parent 7b56372dd0
commit abef61e5f9
2 changed files with 13 additions and 0 deletions
+1
View File
@@ -5,6 +5,7 @@ go 1.14
require (
github.com/drone-plugins/drone-plugin-lib v0.3.1
github.com/joho/godotenv v1.3.0
github.com/sirupsen/logrus v1.6.0
github.com/urfave/cli/v2 v2.2.0
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
)
+12
View File
@@ -17,6 +17,8 @@ import (
"path"
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
)
// Settings for the plugin.
@@ -84,6 +86,11 @@ func (p *Plugin) Execute() error {
return nil
}
logrus.WithFields(logrus.Fields{
"source": p.settings.Source,
"destination": p.settings.destination,
}).Info("Downloading file")
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("executing request failed: %w", err)
@@ -106,17 +113,21 @@ func (p *Plugin) Execute() error {
}
var h hash.Hash
alg := ""
exp := ""
if p.settings.SHA256 != "" {
exp = p.settings.SHA256
alg = "SHA256"
h = sha256.New()
} else if p.settings.MD5 != "" {
exp = p.settings.MD5
alg = "MD5"
h = md5.New()
}
if exp != "" {
logrus.WithField("hash", alg).Info("Computing checksum")
target.Seek(0, 0)
if _, err := io.Copy(h, target); err != nil {
@@ -130,6 +141,7 @@ func (p *Plugin) Execute() error {
defer os.Remove(target.Name())
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, exp)
}
logrus.WithField("checksum", check).Info("Checksum matched")
}
return nil