mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-21 15:31:41 -04:00
* Update handling of registry artifacts This change uses the github.com/hashicorp/packer-plgin-sdk/packer/registryimage for querying Artifact State for HCP Registry Image metadata. To handle the conversion of the RPC response, mapstructure was introduced to conversion state data into an registryimage.Image before publishing to a image bucket. * Update to use registry image from packersdk * Rename internal registry service pkg * Update vendored plugins to latest version * The latest release of Amazon, GoogleCompute, and Azure have support for publishing images to the HCP Packer registry.
37 lines
897 B
Go
37 lines
897 B
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
)
|
|
|
|
const (
|
|
_ = iota
|
|
InvalidClientConfig
|
|
)
|
|
|
|
// ClientError represents a generic error for the Cloud Packer Service client.
|
|
type ClientError struct {
|
|
StatusCode uint
|
|
Err error
|
|
}
|
|
|
|
// Error returns the string message for some ClientError.
|
|
func (c *ClientError) Error() string {
|
|
return fmt.Sprintf("status %d: err %v", c.StatusCode, c.Err)
|
|
}
|
|
|
|
// checkErrorCode checks the error string for err for some code and returns true if the code is found.
|
|
// Ideally this function should use status.FromError https://pkg.go.dev/google.golang.org/grpc/status#pkg-functions
|
|
// but that doesn't appear to work for all of the Cloud Packer Service response errors.
|
|
func checkErrorCode(err error, code codes.Code) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
return strings.Contains(err.Error(), fmt.Sprintf("Code:%d", code))
|
|
|
|
}
|