Skip to content

Commit

Permalink
Ensure org ID is set and move UploadSbom to api package
Browse files Browse the repository at this point in the history
  • Loading branch information
JenGoldstrich authored and lbajolet-hashicorp committed Jan 21, 2025
1 parent 347c573 commit 8dcd9fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
25 changes: 25 additions & 0 deletions internal/hcp/api/service_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
20 changes: 1 addition & 19 deletions internal/hcp/registry/types.bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8dcd9fe

Please sign in to comment.