terraform-provider-gitea/vendor/github.com/hashicorp/hc-install/product/vault.go
dependabot[bot] 84c9110a24
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.24.1 to 2.26.0
Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.24.1 to 2.26.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.24.1...v2.26.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-20 20:25:53 +00:00

54 lines
1.2 KiB
Go

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)
)
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{},
},
}