Skip to content

Commit

Permalink
plugin/set: add protocol_version to Description
Browse files Browse the repository at this point in the history
When a plugin describes its capabilities, it needs to advertise whether
or not protobuf can be used in order for Packer to know which
serialisation protocol to use for communicating with the plugin.

To do so, we add a protocol_version attribute to the returned
structure, which is now set to v2, in order for Packer to know that the
plugin can use that.
  • Loading branch information
lbajolet-hashicorp committed Jun 6, 2024
1 parent 6ec7754 commit b9a8108
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
30 changes: 16 additions & 14 deletions plugin/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ type Set struct {

// SetDescription describes a Set.
type SetDescription struct {
Version string `json:"version"`
SDKVersion string `json:"sdk_version"`
APIVersion string `json:"api_version"`
Builders []string `json:"builders"`
PostProcessors []string `json:"post_processors"`
Provisioners []string `json:"provisioners"`
Datasources []string `json:"datasources"`
Version string `json:"version"`
SDKVersion string `json:"sdk_version"`
APIVersion string `json:"api_version"`
Builders []string `json:"builders"`
PostProcessors []string `json:"post_processors"`
Provisioners []string `json:"provisioners"`
Datasources []string `json:"datasources"`
ProtocolVersion string `json:"protocol_version"`
}

////
Expand Down Expand Up @@ -187,13 +188,14 @@ func (i *Set) start(kind, name string) error {

func (i *Set) description() SetDescription {
return SetDescription{
Version: i.version,
SDKVersion: i.sdkVersion,
APIVersion: i.apiVersion,
Builders: i.buildersDescription(),
PostProcessors: i.postProcessorsDescription(),
Provisioners: i.provisionersDescription(),
Datasources: i.datasourceDescription(),
Version: i.version,
SDKVersion: i.sdkVersion,
APIVersion: i.apiVersion,
Builders: i.buildersDescription(),
PostProcessors: i.postProcessorsDescription(),
Provisioners: i.provisionersDescription(),
Datasources: i.datasourceDescription(),
ProtocolVersion: "v2",
}
}

Expand Down
15 changes: 8 additions & 7 deletions plugin/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ func TestSet(t *testing.T) {

sdkVersion := pluginVersion.NewPluginVersion(pluginVersion.Version, pluginVersion.VersionPrerelease, "")
if diff := cmp.Diff(SetDescription{
Version: "1.1.1",
SDKVersion: sdkVersion.String(),
APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor,
Builders: []string{"example", "example-2"},
PostProcessors: []string{"example", "example-2"},
Provisioners: []string{"example", "example-2"},
Datasources: []string{"example", "example-2"},
Version: "1.1.1",
SDKVersion: sdkVersion.String(),
APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor,
Builders: []string{"example", "example-2"},
PostProcessors: []string{"example", "example-2"},
Provisioners: []string{"example", "example-2"},
Datasources: []string{"example", "example-2"},
ProtocolVersion: "v2",
}, outputDesc); diff != "" {
t.Fatalf("Unexpected description: %s", diff)
}
Expand Down

0 comments on commit b9a8108

Please sign in to comment.