parse checksum file so that we can use the checksums inside in the vmware-esxi builder stepuploadiso
This commit is contained in:
parent
3a56c16308
commit
998ef4053f
|
@ -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
|
||||
}
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
Loading…
Reference in New Issue