updated GHA
Update to v2 SDK updated dependencies
This commit is contained in:
2
vendor/github.com/hashicorp/hc-install/README.md
generated
vendored
2
vendor/github.com/hashicorp/hc-install/README.md
generated
vendored
@ -31,7 +31,7 @@ The `Installer` offers a few high-level methods:
|
||||
The `Installer` methods accept number of different `Source` types.
|
||||
Each comes with different trade-offs described below.
|
||||
|
||||
- `fs.{AnyVersion,ExactVersion}` - Finds a binary in `$PATH` (or additional paths)
|
||||
- `fs.{AnyVersion,ExactVersion,Version}` - Finds a binary in `$PATH` (or additional paths)
|
||||
- **Pros:**
|
||||
- This is most convenient when you already have the product installed on your system
|
||||
which you already manage.
|
||||
|
97
vendor/github.com/hashicorp/hc-install/fs/version.go
generated
vendored
Normal file
97
vendor/github.com/hashicorp/hc-install/fs/version.go
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/hc-install/errors"
|
||||
"github.com/hashicorp/hc-install/internal/src"
|
||||
"github.com/hashicorp/hc-install/internal/validators"
|
||||
"github.com/hashicorp/hc-install/product"
|
||||
)
|
||||
|
||||
// Version finds the first executable binary of the product name
|
||||
// which matches the version constraint within system $PATH and any declared ExtraPaths
|
||||
// (which are *appended* to any directories in $PATH)
|
||||
type Version struct {
|
||||
Product product.Product
|
||||
Constraints version.Constraints
|
||||
ExtraPaths []string
|
||||
Timeout time.Duration
|
||||
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func (*Version) IsSourceImpl() src.InstallSrcSigil {
|
||||
return src.InstallSrcSigil{}
|
||||
}
|
||||
|
||||
func (v *Version) SetLogger(logger *log.Logger) {
|
||||
v.logger = logger
|
||||
}
|
||||
|
||||
func (v *Version) log() *log.Logger {
|
||||
if v.logger == nil {
|
||||
return discardLogger
|
||||
}
|
||||
return v.logger
|
||||
}
|
||||
|
||||
func (v *Version) Validate() error {
|
||||
if !validators.IsBinaryNameValid(v.Product.BinaryName()) {
|
||||
return fmt.Errorf("invalid binary name: %q", v.Product.BinaryName())
|
||||
}
|
||||
if len(v.Constraints) == 0 {
|
||||
return fmt.Errorf("undeclared version constraints")
|
||||
}
|
||||
if v.Product.GetVersion == nil {
|
||||
return fmt.Errorf("undeclared version getter")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Version) Find(ctx context.Context) (string, error) {
|
||||
timeout := defaultTimeout
|
||||
if v.Timeout > 0 {
|
||||
timeout = v.Timeout
|
||||
}
|
||||
ctx, cancelFunc := context.WithTimeout(ctx, timeout)
|
||||
defer cancelFunc()
|
||||
|
||||
execPath, err := findFile(lookupDirs(v.ExtraPaths), v.Product.BinaryName(), func(file string) error {
|
||||
err := checkExecutable(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ver, err := v.Product.GetVersion(ctx, file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, vc := range v.Constraints {
|
||||
if !vc.Check(ver) {
|
||||
return fmt.Errorf("version (%s) doesn't meet constraints %s", ver, vc.String())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", errors.SkippableErr(err)
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(execPath) {
|
||||
var err error
|
||||
execPath, err = filepath.Abs(execPath)
|
||||
if err != nil {
|
||||
return "", errors.SkippableErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
return execPath, nil
|
||||
}
|
15
vendor/github.com/hashicorp/hc-install/internal/releasesjson/checksum_downloader.go
generated
vendored
15
vendor/github.com/hashicorp/hc-install/internal/releasesjson/checksum_downloader.go
generated
vendored
@ -121,12 +121,23 @@ func fileMapFromChecksums(checksums strings.Builder) (ChecksumFileMap, error) {
|
||||
return csMap, nil
|
||||
}
|
||||
|
||||
func compareChecksum(logger *log.Logger, r io.Reader, verifiedHashSum HashSum) error {
|
||||
func compareChecksum(logger *log.Logger, r io.Reader, verifiedHashSum HashSum, filename string, expectedSize int64) error {
|
||||
h := sha256.New()
|
||||
_, err := io.Copy(h, r)
|
||||
|
||||
// This may take a while depending on network connection as the io.Reader
|
||||
// is expected to be http.Response.Body which streams the bytes
|
||||
// on demand over the network.
|
||||
logger.Printf("copying %q (%d bytes) to calculate checksum", filename, expectedSize)
|
||||
bytesCopied, err := io.Copy(h, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Printf("copied %d bytes of %q", bytesCopied, filename)
|
||||
|
||||
if expectedSize != 0 && bytesCopied != int64(expectedSize) {
|
||||
return fmt.Errorf("unexpected size (downloaded: %d, expected: %d)",
|
||||
bytesCopied, expectedSize)
|
||||
}
|
||||
|
||||
calculatedSum := h.Sum(nil)
|
||||
if !bytes.Equal(calculatedSum, verifiedHashSum) {
|
||||
|
21
vendor/github.com/hashicorp/hc-install/internal/releasesjson/downloader.go
generated
vendored
21
vendor/github.com/hashicorp/hc-install/internal/releasesjson/downloader.go
generated
vendored
@ -12,7 +12,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/hc-install/internal/httpclient"
|
||||
)
|
||||
@ -95,14 +94,16 @@ func (d *Downloader) DownloadAndUnpack(ctx context.Context, pv *ProductVersion,
|
||||
contentType, zipMimeTypes)
|
||||
}
|
||||
|
||||
expectedSize := resp.ContentLength
|
||||
|
||||
if d.VerifyChecksum {
|
||||
d.Logger.Printf("calculating checksum of %q", pb.Filename)
|
||||
d.Logger.Printf("verifying checksum of %q", pb.Filename)
|
||||
// provide extra reader to calculate & compare checksum
|
||||
var buf bytes.Buffer
|
||||
r := io.TeeReader(resp.Body, &buf)
|
||||
pkgReader = &buf
|
||||
|
||||
err := compareChecksum(d.Logger, r, verifiedChecksum)
|
||||
err := compareChecksum(d.Logger, r, verifiedChecksum, pb.Filename, expectedSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -114,21 +115,17 @@ func (d *Downloader) DownloadAndUnpack(ctx context.Context, pv *ProductVersion,
|
||||
}
|
||||
defer pkgFile.Close()
|
||||
|
||||
d.Logger.Printf("copying downloaded file to %s", pkgFile.Name())
|
||||
d.Logger.Printf("copying %q (%d bytes) to %s", pb.Filename, expectedSize, pkgFile.Name())
|
||||
// Unless the bytes were already downloaded above for checksum verification
|
||||
// this may take a while depending on network connection as the io.Reader
|
||||
// is expected to be http.Response.Body which streams the bytes
|
||||
// on demand over the network.
|
||||
bytesCopied, err := io.Copy(pkgFile, pkgReader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Logger.Printf("copied %d bytes to %s", bytesCopied, pkgFile.Name())
|
||||
|
||||
expectedSize := 0
|
||||
if length := resp.Header.Get("content-length"); length != "" {
|
||||
var err error
|
||||
expectedSize, err = strconv.Atoi(length)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if expectedSize != 0 && bytesCopied != int64(expectedSize) {
|
||||
return fmt.Errorf("unexpected size (downloaded: %d, expected: %d)",
|
||||
bytesCopied, expectedSize)
|
||||
|
4
vendor/github.com/hashicorp/hc-install/internal/releasesjson/releases.go
generated
vendored
4
vendor/github.com/hashicorp/hc-install/internal/releasesjson/releases.go
generated
vendored
@ -79,7 +79,7 @@ func (r *Releases) ListProductVersions(ctx context.Context, productName string)
|
||||
}
|
||||
|
||||
contentType := resp.Header.Get("content-type")
|
||||
if contentType != "application/json" {
|
||||
if contentType != "application/json" && contentType != "application/vnd+hashicorp.releases-api.v0+json" {
|
||||
return nil, fmt.Errorf("unexpected Content-Type: %q", contentType)
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ func (r *Releases) GetProductVersion(ctx context.Context, product string, versio
|
||||
}
|
||||
|
||||
contentType := resp.Header.Get("content-type")
|
||||
if contentType != "application/json" {
|
||||
if contentType != "application/json" && contentType != "application/vnd+hashicorp.releases-api.v0+json" {
|
||||
return nil, fmt.Errorf("unexpected Content-Type: %q", contentType)
|
||||
}
|
||||
|
||||
|
6
vendor/github.com/hashicorp/hc-install/product/consul.go
generated
vendored
6
vendor/github.com/hashicorp/hc-install/product/consul.go
generated
vendored
@ -15,9 +15,7 @@ import (
|
||||
var consulVersionOutputRe = regexp.MustCompile(`Consul ` + simpleVersionRe)
|
||||
|
||||
var (
|
||||
v1_16 = version.Must(version.NewVersion("1.16"))
|
||||
// TODO: version.MustConstraint() ?
|
||||
v1_16c, _ = version.NewConstraint("1.16")
|
||||
v1_18 = version.Must(version.NewVersion("1.18"))
|
||||
)
|
||||
|
||||
var Consul = Product{
|
||||
@ -52,6 +50,6 @@ var Consul = Product{
|
||||
BuildInstructions: &BuildInstructions{
|
||||
GitRepoURL: "https://github.com/hashicorp/consul.git",
|
||||
PreCloneCheck: &build.GoIsInstalled{},
|
||||
Build: &build.GoBuild{Version: v1_16},
|
||||
Build: &build.GoBuild{Version: v1_18},
|
||||
},
|
||||
}
|
||||
|
54
vendor/github.com/hashicorp/hc-install/product/vault.go
generated
vendored
Normal file
54
vendor/github.com/hashicorp/hc-install/product/vault.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/hc-install/internal/build"
|
||||
)
|
||||
|
||||
var (
|
||||
vaultVersionOutputRe = regexp.MustCompile(`Vault ` + simpleVersionRe)
|
||||
v1_17 = version.Must(version.NewVersion("1.17"))
|
||||
)
|
||||
|
||||
var Vault = Product{
|
||||
Name: "vault",
|
||||
BinaryName: func() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "vault.exe"
|
||||
}
|
||||
return "vault"
|
||||
},
|
||||
GetVersion: func(ctx context.Context, path string) (*version.Version, error) {
|
||||
cmd := exec.CommandContext(ctx, path, "version")
|
||||
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stdout := strings.TrimSpace(string(out))
|
||||
|
||||
submatches := vaultVersionOutputRe.FindStringSubmatch(stdout)
|
||||
if len(submatches) != 2 {
|
||||
return nil, fmt.Errorf("unexpected number of version matches %d for %s", len(submatches), stdout)
|
||||
}
|
||||
v, err := version.NewVersion(submatches[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse version %q: %w", submatches[1], err)
|
||||
}
|
||||
|
||||
return v, err
|
||||
},
|
||||
BuildInstructions: &BuildInstructions{
|
||||
GitRepoURL: "https://github.com/hashicorp/vault.git",
|
||||
PreCloneCheck: &build.GoIsInstalled{},
|
||||
Build: &build.GoBuild{Version: v1_17},
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user