Compare commits

..

7 Commits

Author SHA1 Message Date
Thomas Boerger f06bb4fcc7 Merge pull request #11 from drone-plugins/checksum-fix
Copy the target file first and fix checksum checks
2018-09-27 20:29:14 +02:00
Thomas Boerger 852b0b104c Copy the target file first and fix checksum checks 2018-09-27 14:37:43 +02:00
Thomas Boerger 125c08a2e6 Merge pull request #9 from patrickjahns/fix_checksum_miscalculation
fix comparison for sha256 checksum
2018-09-26 07:38:35 +02:00
Patrick Jahns 64bc79b1db fix comparison for sha256 checksum 2018-09-25 22:38:06 +02:00
Thomas Boerger ce7e9cd1c9 Merge pull request #8 from patrickjahns/fix_checksumming
fixed typo regards to sha checksumming
2018-09-25 21:01:32 +02:00
Patrick Jahns 77d760c2b9 provide legacy fallback option to avoid breaking changes 2018-09-25 19:33:31 +02:00
Patrick Jahns a367d8be06 fixed typo regards to sha checksumming 2018-09-25 16:29:22 +02:00
2 changed files with 39 additions and 33 deletions
+4 -4
View File
@@ -57,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",
},
}
@@ -78,7 +78,7 @@ func run(c *cli.Context) error {
Password: c.String("password"),
SkipVerify: c.Bool("skip-verify"),
MD5: c.String("md5-checksum"),
SHA265: c.String("sha265-checksum"),
SHA256: c.String("sha256-checksum"),
},
}
+35 -29
View File
@@ -26,7 +26,7 @@ type (
Password string
SkipVerify bool
MD5 string
SHA265 string
SHA256 string
}
Plugin struct {
@@ -107,39 +107,45 @@ func (p Plugin) Exec() error {
defer target.Close()
if p.Config.MD5 != "" {
h := md5.New()
if _, err := io.Copy(h, resp.Body); err != nil {
return errors.Wrap(err, "failed to compare checksum")
}
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.MD5)
}
}
if p.Config.SHA265 != "" {
h := sha256.New()
if _, err := io.Copy(h, resp.Body); err != nil {
return errors.Wrap(err, "failed to compare checksum")
}
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)
}
}
_, err = io.Copy(target, resp.Body)
if err != nil {
return errors.Wrap(err, "copying destination failed")
}
if p.Config.MD5 != "" {
h := md5.New()
target.Seek(0, 0)
if _, err := io.Copy(h, target); err != nil {
defer os.Remove(target.Name())
return errors.Wrap(err, "failed to compare checksum")
}
check := fmt.Sprintf("%x", h.Sum(nil))
if p.Config.MD5 != check {
defer os.Remove(target.Name())
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.MD5)
}
}
if p.Config.SHA256 != "" {
h := sha256.New()
target.Seek(0, 0)
if _, err := io.Copy(h, target); err != nil {
defer os.Remove(target.Name())
return errors.Wrap(err, "failed to compare checksum")
}
check := fmt.Sprintf("%x", h.Sum(nil))
if p.Config.SHA256 != check {
defer os.Remove(target.Name())
return fmt.Errorf("checksum doesn't match, got %s and expected %s", check, p.Config.SHA256)
}
}
return nil
}