hcp: use enum for HCP SBOM upload

Since the protos for uploading an SBOM for a build have been changed to
use an enumeration instead of a plain string with the latest revisions
to the HCP Packer SBOM support feature, we update how we reference those
values for the SBOM format to use that enum instead.
pull/13268/head
Jenna Goldstrich 1 year ago committed by Lucas Bajolet
parent 619c524afb
commit 347c57306c

@ -246,7 +246,7 @@ func (bucket *Bucket) uploadSbom(ctx context.Context, buildName string, sbom pac
Body: &hcpPackerModels.HashicorpCloudPacker20230101UploadSbomBody{
CompressedSbom: sbom.CompressedData,
Name: sbom.Name,
Format: sbom.Format,
Format: &sbom.Format,
},
},
nil,

@ -9,6 +9,7 @@ import (
"log"
"sync"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
"github.com/hashicorp/packer-plugin-sdk/common"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/packerbuilderdata"
@ -56,7 +57,7 @@ type CoreBuild struct {
type SBOM struct {
Name string
Format string
Format hcpPackerModels.HashicorpCloudPacker20230101SbomFormat
CompressedData []byte
}

@ -12,6 +12,7 @@ import (
hcpSbomProvisioner "github.com/hashicorp/packer/provisioner/hcp-sbom"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
"github.com/klauspost/compress/zstd"
"time"
@ -249,7 +250,7 @@ func (p *DebuggedProvisioner) Provision(ctx context.Context, ui packersdk.Ui, co
type SBOMInternalProvisioner struct {
Provisioner packersdk.Provisioner
CompressedData []byte
SBOMFormat string
SBOMFormat hcpPackerModels.HashicorpCloudPacker20230101SbomFormat
SBOMName string
}

@ -20,6 +20,7 @@ import (
"path/filepath"
"github.com/hashicorp/hcl/v2/hcldec"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
"github.com/hashicorp/packer-plugin-sdk/common"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
@ -116,8 +117,8 @@ type PackerSBOM struct {
RawSBOM []byte `json:"raw_sbom"`
// Format is the format detected by the provisioner
//
// Supported values: `spdx` or `cyclonedx`
Format string `json:"format"`
// Supported values: `SPDX` or `CYCLONEDX`
Format hcpPackerModels.HashicorpCloudPacker20230101SbomFormat `json:"format"`
// Name is the name of the SBOM to be set on HCP Packer
//
// If unset, HCP Packer will generate one

@ -6,6 +6,7 @@ import (
"strings"
"github.com/CycloneDX/cyclonedx-go"
hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models"
spdxjson "github.com/spdx/tools-golang/json"
)
@ -61,11 +62,11 @@ func validateSPDX(content []byte) error {
}
// validateSBOM validates the SBOM file and returns the format of the SBOM.
func validateSBOM(content []byte) (string, error) {
func validateSBOM(content []byte) (hcpPackerModels.HashicorpCloudPacker20230101SbomFormat, error) {
// Try validating as SPDX
spdxErr := validateSPDX(content)
if spdxErr == nil {
return "spdx", nil
return hcpPackerModels.HashicorpCloudPacker20230101SbomFormatSPDX, nil
}
if vErr, ok := spdxErr.(*ValidationError); ok {
@ -74,7 +75,7 @@ func validateSBOM(content []byte) (string, error) {
cycloneDxErr := validateCycloneDX(content)
if cycloneDxErr == nil {
return "cyclonedx", nil
return hcpPackerModels.HashicorpCloudPacker20230101SbomFormatCYCLONEDX, nil
}
if vErr, ok := cycloneDxErr.(*ValidationError); ok {

Loading…
Cancel
Save