Skip to content

Commit 92f8dfa

Browse files
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.
1 parent c617889 commit 92f8dfa

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

internal/hcp/registry/hcl.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,19 @@ func (h *HCLRegistry) PopulateVersion(ctx context.Context) error {
6565
}
6666

6767
// StartBuild is invoked when one build for the configuration is starting to be processed
68-
func (h *HCLRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error {
69-
name := build.Name()
70-
cb, ok := build.(*packer.CoreBuild)
71-
if ok {
72-
name = cb.Type
73-
}
74-
75-
return h.bucket.startBuild(ctx, name)
68+
func (h *HCLRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error {
69+
return h.bucket.startBuild(ctx, build.Type)
7670
}
7771

7872
// CompleteBuild is invoked when one build for the configuration has finished
7973
func (h *HCLRegistry) CompleteBuild(
8074
ctx context.Context,
81-
build sdkpacker.Build,
75+
build *packer.CoreBuild,
8276
artifacts []sdkpacker.Artifact,
8377
buildErr error,
8478
) ([]sdkpacker.Artifact, error) {
85-
buildName := build.Name()
86-
cb, ok := build.(*packer.CoreBuild)
87-
if ok {
88-
buildName = cb.Type
89-
}
90-
91-
buildMetadata, envMetadata := cb.GetMetadata(), h.metadata
79+
buildName := build.Type
80+
buildMetadata, envMetadata := build.GetMetadata(), h.metadata
9281
err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata)
9382
if err != nil {
9483
return nil, err

internal/hcp/registry/json.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,19 @@ func (h *JSONRegistry) PopulateVersion(ctx context.Context) error {
8484
}
8585

8686
// StartBuild is invoked when one build for the configuration is starting to be processed
87-
func (h *JSONRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error {
88-
name := build.Name()
89-
return h.bucket.startBuild(ctx, name)
87+
func (h *JSONRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error {
88+
return h.bucket.startBuild(ctx, build.Name())
9089
}
9190

9291
// CompleteBuild is invoked when one build for the configuration has finished
9392
func (h *JSONRegistry) CompleteBuild(
9493
ctx context.Context,
95-
build sdkpacker.Build,
94+
build *packer.CoreBuild,
9695
artifacts []sdkpacker.Artifact,
9796
buildErr error,
9897
) ([]sdkpacker.Artifact, error) {
9998
buildName := build.Name()
100-
buildMetadata, envMetadata := build.(*packer.CoreBuild).GetMetadata(), h.metadata
99+
buildMetadata, envMetadata := build.GetMetadata(), h.metadata
101100
err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata)
102101
if err != nil {
103102
return nil, err

internal/hcp/registry/null_registry.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88

99
sdkpacker "github.com/hashicorp/packer-plugin-sdk/packer"
10+
"github.com/hashicorp/packer/packer"
1011
)
1112

1213
// nullRegistry is a special handler that does nothing
@@ -16,13 +17,13 @@ func (r nullRegistry) PopulateVersion(context.Context) error {
1617
return nil
1718
}
1819

19-
func (r nullRegistry) StartBuild(context.Context, sdkpacker.Build) error {
20+
func (r nullRegistry) StartBuild(context.Context, *packer.CoreBuild) error {
2021
return nil
2122
}
2223

2324
func (r nullRegistry) CompleteBuild(
2425
ctx context.Context,
25-
build sdkpacker.Build,
26+
build *packer.CoreBuild,
2627
artifacts []sdkpacker.Artifact,
2728
buildErr error,
2829
) ([]sdkpacker.Artifact, error) {

internal/hcp/registry/registry.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
// Registry is an entity capable to orchestrate a Packer build and upload metadata to HCP
1717
type Registry interface {
1818
PopulateVersion(context.Context) error
19-
StartBuild(context.Context, sdkpacker.Build) error
20-
CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error)
19+
StartBuild(context.Context, *packer.CoreBuild) error
20+
CompleteBuild(ctx context.Context, build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error)
2121
VersionStatusSummary()
2222
Metadata() Metadata
2323
}

0 commit comments

Comments
 (0)