Skip to content

Commit 8fead8c

Browse files
author
Wilken Rivera
committed
Move to mapstructure for decoding
1 parent b61e9c7 commit 8fead8c

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

packer/registry_builder.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/preview/2021-04-30/models"
99
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
1010
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
11-
"github.com/hashicorp/packer-plugin-sdk/template/config"
1211
packerregistry "github.com/hashicorp/packer/internal/registry"
12+
"github.com/mitchellh/mapstructure"
1313
)
1414

1515
type RegistryBuilder struct {
@@ -69,9 +69,18 @@ func (b *RegistryBuilder) Run(ctx context.Context, ui packersdk.Ui, hook packers
6969
return nil, nil
7070
}
7171

72-
state := artifact.State(registryimage.ArtifactStateURI)
7372
var images []registryimage.Image
74-
err = config.Decode(&images, &config.DecodeOpts{}, state)
73+
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
74+
Result: &images,
75+
WeaklyTypedInput: true,
76+
ErrorUnused: true,
77+
})
78+
if err != nil {
79+
return artifact, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err)
80+
}
81+
82+
state := artifact.State(registryimage.ArtifactStateURI)
83+
err = decoder.Decode(state)
7584
if err != nil {
7685
return artifact, fmt.Errorf("failed to obtain HCP Packer registry image from build artifact: %w", err)
7786
}

packer/registry_post_processor.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/hashicorp/hcp-sdk-go/clients/cloud-packer-service/preview/2021-04-30/models"
1010
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
1111
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
12-
"github.com/hashicorp/packer-plugin-sdk/template/config"
1312
packerregistry "github.com/hashicorp/packer/internal/registry"
13+
"github.com/mitchellh/mapstructure"
1414
)
1515

1616
type RegistryPostProcessor struct {
@@ -61,9 +61,18 @@ func (p *RegistryPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui
6161
return source, false, false, err
6262
}
6363

64-
state := source.State(registryimage.ArtifactStateURI)
6564
var images []registryimage.Image
66-
err = config.Decode(&images, &config.DecodeOpts{}, state)
65+
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
66+
Result: &images,
67+
WeaklyTypedInput: true,
68+
ErrorUnused: true,
69+
})
70+
if err != nil {
71+
return source, false, false, fmt.Errorf("failed to create decoder for HCP Packer registry image: %w", err)
72+
}
73+
74+
state := source.State(registryimage.ArtifactStateURI)
75+
err = decoder.Decode(state)
6776
if err != nil {
6877
return source, false, false, fmt.Errorf("failed to obtain HCP Packer registry image from post-processor artifact: %w", err)
6978
}

0 commit comments

Comments
 (0)