From 8dcd9fe1a597a550f319924adbd6245a5032c92f Mon Sep 17 00:00:00 2001 From: Jenna Goldstrich Date: Tue, 21 Jan 2025 11:24:19 -0800 Subject: [PATCH] Ensure org ID is set and move UploadSbom to api package --- internal/hcp/api/service_build.go | 25 +++++++++++++++++++++++++ internal/hcp/registry/types.bucket.go | 20 +------------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/internal/hcp/api/service_build.go b/internal/hcp/api/service_build.go index 946d8d08e..a857192c3 100644 --- a/internal/hcp/api/service_build.go +++ b/internal/hcp/api/service_build.go @@ -6,6 +6,7 @@ import ( hcpPackerAPI "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/client/packer_service" hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models" + "github.com/hashicorp/packer/packer" ) func (c *Client) CreateBuild( @@ -93,3 +94,27 @@ func (c *Client) UpdateBuild( return resp.Payload.Build.ID, nil } + +func (c *Client) UploadSbom( + ctx context.Context, + bucketName, fingerprint string, + buildID string, + sbom packer.SBOM, +) error { + + params := hcpPackerAPI.NewPackerServiceUploadSbomParamsWithContext(ctx) + params.BuildID = buildID + params.LocationOrganizationID = c.OrganizationID + params.LocationProjectID = c.ProjectID + params.BucketName = bucketName + params.Fingerprint = fingerprint + + params.Body = &hcpPackerModels.HashicorpCloudPacker20230101UploadSbomBody{ + CompressedSbom: sbom.CompressedData, + Format: &sbom.Format, + Name: sbom.Name, + } + + _, err := c.Packer.PackerServiceUploadSbom(params, nil) + return err +} diff --git a/internal/hcp/registry/types.bucket.go b/internal/hcp/registry/types.bucket.go index 184a46e2a..1e06439c4 100644 --- a/internal/hcp/registry/types.bucket.go +++ b/internal/hcp/registry/types.bucket.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/packer/packer" "github.com/hashicorp/go-multierror" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/client/packer_service" hcpPackerModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/stable/2023-01-01/models" packerSDK "github.com/hashicorp/packer-plugin-sdk/packer" packerSDKRegistry "github.com/hashicorp/packer-plugin-sdk/packer/registry/image" @@ -231,27 +230,10 @@ func (bucket *Bucket) uploadSbom(ctx context.Context, buildName string, sbom pac return err } - log.Println( - "[TRACE] jennajenna uploadsbom called", buildToUpdate.ID, - ) if buildToUpdate.ID == "" { return fmt.Errorf("the build for the component %q does not have a valid id", buildName) } - _, err = bucket.client.Packer.PackerServiceUploadSbom( - &packer_service.PackerServiceUploadSbomParams{ - Context: ctx, - BucketName: bucket.Name, - Fingerprint: bucket.Version.Fingerprint, - BuildID: buildToUpdate.ID, - Body: &hcpPackerModels.HashicorpCloudPacker20230101UploadSbomBody{ - CompressedSbom: sbom.CompressedData, - Name: sbom.Name, - Format: &sbom.Format, - }, - }, - nil, - ) - return err + return bucket.client.UploadSbom(ctx, bucket.Name, bucket.Version.Fingerprint, buildToUpdate.ID, sbom) } // markBuildComplete should be called to set a build on the HCP Packer registry to DONE.