From 998ef4053fcc34c09bcd59eb0593e83a634795df Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 27 Jun 2019 14:29:25 -0700 Subject: [PATCH] parse checksum file so that we can use the checksums inside in the vmware-esxi builder stepuploadiso --- common/iso_config.go | 27 +++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/common/iso_config.go b/common/iso_config.go index a66042efc..47bfa94e3 100644 --- a/common/iso_config.go +++ b/common/iso_config.go @@ -1,10 +1,15 @@ package common import ( + "encoding/hex" "errors" "fmt" + "log" + "net/url" + "os" "strings" + getter "github.com/hashicorp/go-getter" "github.com/hashicorp/packer/template/interpolate" ) @@ -65,6 +70,28 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [ if c.ISOChecksum == "" { errs = append(errs, fmt.Errorf("A checksum must be specified")) } + if c.ISOChecksumType == "file" { + u, err := url.Parse(c.ISOUrls[0]) + wd, err := os.Getwd() + if err != nil { + log.Printf("get working directory: %v", err) + // here we ignore the error in case the + // working directory is not needed. + } + gc := getter.Client{ + Dst: "no-op", + Src: u.String(), + Pwd: wd, + Dir: false, + Getters: getter.Getters, + } + cksum, err := gc.ChecksumFromFile(c.ISOChecksumURL, u) + if err != nil { + errs = append(errs, fmt.Errorf("Couldn't extract checksum from checksum file")) + } + c.ISOChecksumType = cksum.Type + c.ISOChecksum = hex.EncodeToString(cksum.Value) + } return warnings, errs } diff --git a/go.mod b/go.mod index 067a8752e..0d1017dbf 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de github.com/hashicorp/go-cleanhttp v0.5.0 - github.com/hashicorp/go-getter v1.2.0 + github.com/hashicorp/go-getter v1.3.1-0.20190627194820-3fc511e2f341 github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/go-oracle-terraform v0.0.0-20181016190316-007121241b79 github.com/hashicorp/go-retryablehttp v0.5.2 // indirect diff --git a/go.sum b/go.sum index cd5e43c17..c50327e10 100644 --- a/go.sum +++ b/go.sum @@ -177,6 +177,10 @@ github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6K github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-getter v1.2.0 h1:E05bVPilzyh2yXgT6srn7WEkfMZaH+LuX9tDJw/4kaE= github.com/hashicorp/go-getter v1.2.0/go.mod h1:/O1k/AizTN0QmfEKknCYGvICeyKUDqCYA8vvWtGWDeQ= +github.com/hashicorp/go-getter v1.3.1-0.20190627194702-0c4919d4eb92 h1:Tck3az71eOyEcxueXyZfM4YO5oy2Hq8AbTpvc9HrQN0= +github.com/hashicorp/go-getter v1.3.1-0.20190627194702-0c4919d4eb92/go.mod h1:/O1k/AizTN0QmfEKknCYGvICeyKUDqCYA8vvWtGWDeQ= +github.com/hashicorp/go-getter v1.3.1-0.20190627194820-3fc511e2f341 h1:v+hsBJMakfQLeYkPuv/Y/T86jKvDQrOU1TyzximcF2Y= +github.com/hashicorp/go-getter v1.3.1-0.20190627194820-3fc511e2f341/go.mod h1:/O1k/AizTN0QmfEKknCYGvICeyKUDqCYA8vvWtGWDeQ= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4=