mirror of
https://github.com/hashicorp/vault.git
synced 2025-09-11 00:41:09 +02:00
* [VAULT-39159]: pipeline: add support for querying HCP image service In order to facilitate testing Vault Enterprise directly in HCP we need tools to both request an image be built from a candidate build and to also wait for the image to be available in order to execute test scenarios with it. This PR adds a few new `pipeline` sub-commands that can will be used for this purpose. `pipeline github find workflow-artifact` can be used to find the path of an artifact that matches the given filter criteria. You'll need to provide a pull request number, workflow name, and either an exact artifact name or a pattern. When providing a pattern only the first match will be returned so make sure your regular expression is robust. `pipeline hcp get image` will return the image information for an HCP image. You will need to supply auth via the `HCP_USERNAME` and `HCP_PASSWORD` environment variables in order to query the image service. It also takes an enviroment flag so you can query the image service in different environments. `pipeline hcp wait image` is like `pipeline hcp get image` except that it will continue to retry for a given timeout and with a given delay between requests. In this way it can be used to wait for an image to be available. As part of this we also update our Go modules to the latest versions that are compatible. * [VAULT-39158]: actions(build-hcp-image): add workflow for building HCP images * copywrite: add missing headers * remove unused output * address feedback * allow prerelease artifacts --------- Signed-off-by: Ryan Cragun <me@ryan.ec> Co-authored-by: Ryan Cragun <me@ryan.ec>
65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/vault/tools/pipeline/internal/pkg/hcp"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var showHCPImageReq = &hcp.GetLatestProductVersionReq{}
|
|
|
|
func newHCPShowImageCmd() *cobra.Command {
|
|
availability := ""
|
|
|
|
showHCPImage := &cobra.Command{
|
|
Use: "image",
|
|
Short: "Show details of an HCP image",
|
|
Long: "Show details of an HCP image",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
showHCPImageReq.Availability = hcp.GetLatestProductVersionAvailability(availability)
|
|
},
|
|
RunE: runHCPImageShowLatestCmd,
|
|
}
|
|
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.ProductName, "product-name", "p", "vault", "The product or component of the image")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.ProductVersionConstraint, "product-version-constraint", "v", "", "A comma seperated list of constraints. If left unset the latest will be returned")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.HostManagerVersionConstraint, "host-manager-version-constraint", "m", "", "A semver string. If left unset the latest will be used")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.CloudProvider, "cloud", "c", "aws", "The cloud provider you wish to search. E.g. aws, azure")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.CloudRegion, "region", "r", "us-west-2", "The cloud region you wish to search")
|
|
showHCPImage.PersistentFlags().StringVarP(&availability, "availability", "a", "public", "The image availability")
|
|
showHCPImage.PersistentFlags().BoolVarP(&showHCPImageReq.ExcludeReleaseCandidates, "exclude-release-candidates", "x", false, "Exclude release candidates")
|
|
|
|
return showHCPImage
|
|
}
|
|
|
|
func runHCPImageShowLatestCmd(cmd *cobra.Command, args []string) error {
|
|
cmd.SilenceUsage = true // Don't spam the usage on failure
|
|
|
|
res, err := showHCPImageReq.Run(context.TODO(), hcpCmdState.client)
|
|
if err != nil {
|
|
return fmt.Errorf("showing HCP image: %w", err)
|
|
}
|
|
|
|
switch rootCfg.format {
|
|
case "json":
|
|
b, err := res.ToJSON()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(string(b))
|
|
case "markdown":
|
|
tbl := res.ToTable()
|
|
tbl.SetTitle("HCP Image")
|
|
fmt.Println(tbl.RenderMarkdown())
|
|
default:
|
|
fmt.Println(res.ToTable().Render())
|
|
}
|
|
|
|
return nil
|
|
}
|