From 62befd70bf68847a97fe5f8a953da430a1d02035 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 13 Feb 2025 14:56:45 -0500 Subject: [PATCH] hcp: replace packersdk.Build by *CoreBuild As the rest of the build process was updated to remove references to the Build interface exposed by the SDK, we change the usage of such types in the hcp internal package, so they are typed with *CoreBuild too. --- internal/hcp/registry/hcl.go | 21 +++++---------------- internal/hcp/registry/json.go | 9 ++++----- internal/hcp/registry/null_registry.go | 5 +++-- internal/hcp/registry/registry.go | 4 ++-- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/internal/hcp/registry/hcl.go b/internal/hcp/registry/hcl.go index d512e3c0d..019b4d860 100644 --- a/internal/hcp/registry/hcl.go +++ b/internal/hcp/registry/hcl.go @@ -65,30 +65,19 @@ func (h *HCLRegistry) PopulateVersion(ctx context.Context) error { } // StartBuild is invoked when one build for the configuration is starting to be processed -func (h *HCLRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error { - name := build.Name() - cb, ok := build.(*packer.CoreBuild) - if ok { - name = cb.Type - } - - return h.bucket.startBuild(ctx, name) +func (h *HCLRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error { + return h.bucket.startBuild(ctx, build.Type) } // CompleteBuild is invoked when one build for the configuration has finished func (h *HCLRegistry) CompleteBuild( ctx context.Context, - build sdkpacker.Build, + build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error, ) ([]sdkpacker.Artifact, error) { - buildName := build.Name() - cb, ok := build.(*packer.CoreBuild) - if ok { - buildName = cb.Type - } - - buildMetadata, envMetadata := cb.GetMetadata(), h.metadata + buildName := build.Type + buildMetadata, envMetadata := build.GetMetadata(), h.metadata err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata) if err != nil { return nil, err diff --git a/internal/hcp/registry/json.go b/internal/hcp/registry/json.go index 2bf62148c..f3f142ee0 100644 --- a/internal/hcp/registry/json.go +++ b/internal/hcp/registry/json.go @@ -84,20 +84,19 @@ func (h *JSONRegistry) PopulateVersion(ctx context.Context) error { } // StartBuild is invoked when one build for the configuration is starting to be processed -func (h *JSONRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error { - name := build.Name() - return h.bucket.startBuild(ctx, name) +func (h *JSONRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error { + return h.bucket.startBuild(ctx, build.Name()) } // CompleteBuild is invoked when one build for the configuration has finished func (h *JSONRegistry) CompleteBuild( ctx context.Context, - build sdkpacker.Build, + build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error, ) ([]sdkpacker.Artifact, error) { buildName := build.Name() - buildMetadata, envMetadata := build.(*packer.CoreBuild).GetMetadata(), h.metadata + buildMetadata, envMetadata := build.GetMetadata(), h.metadata err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata) if err != nil { return nil, err diff --git a/internal/hcp/registry/null_registry.go b/internal/hcp/registry/null_registry.go index 9767e8414..f91a8fe99 100644 --- a/internal/hcp/registry/null_registry.go +++ b/internal/hcp/registry/null_registry.go @@ -7,6 +7,7 @@ import ( "context" sdkpacker "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer/packer" ) // nullRegistry is a special handler that does nothing @@ -16,13 +17,13 @@ func (r nullRegistry) PopulateVersion(context.Context) error { return nil } -func (r nullRegistry) StartBuild(context.Context, sdkpacker.Build) error { +func (r nullRegistry) StartBuild(context.Context, *packer.CoreBuild) error { return nil } func (r nullRegistry) CompleteBuild( ctx context.Context, - build sdkpacker.Build, + build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error, ) ([]sdkpacker.Artifact, error) { diff --git a/internal/hcp/registry/registry.go b/internal/hcp/registry/registry.go index e1c0ca5eb..15c7bc005 100644 --- a/internal/hcp/registry/registry.go +++ b/internal/hcp/registry/registry.go @@ -16,8 +16,8 @@ import ( // Registry is an entity capable to orchestrate a Packer build and upload metadata to HCP type Registry interface { PopulateVersion(context.Context) error - StartBuild(context.Context, sdkpacker.Build) error - CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error) + StartBuild(context.Context, *packer.CoreBuild) error + CompleteBuild(ctx context.Context, build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error) VersionStatusSummary() Metadata() Metadata }