Skip to content

Commit

Permalink
commands: reject constraints with pre-releases (#12999)
Browse files Browse the repository at this point in the history
When remotely installing a plugin, constraints are used by Packer to
determine which version of a plugin to install.

These constraints can be arbitrarily complex, including operators and
ranges in which to look for valid versions.

However, the versions specified in those constraints should always be
final releases, and not a pre-release since we don't explicitly support
remotely installing pre-releases.

This commit therefore addds checks to make sure these are reported ASAP,
even before the source is contacted to list releases and picking one to
install.
  • Loading branch information
lbajolet-hashicorp authored May 30, 2024
1 parent 8d4a9d6 commit b4a843c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions command/plugins_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ func (c *PluginsInstallCommand) RunContext(buildCtx context.Context, args *Plugi
c.Ui.Error(err.Error())
return 1
}

hasPrerelease := false
for _, con := range constraints {
if con.Prerelease() {
hasPrerelease = true
}
}
if hasPrerelease {
c.Ui.Errorf("Unsupported prerelease for constraint %q", args.Version)
return 1
}

pluginRequirement.VersionConstraints = constraints
}

Expand Down
16 changes: 16 additions & 0 deletions hcl2template/types.required_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ func decodeRequiredPluginsBlock(block *hcl.Block) (*RequiredPlugins, hcl.Diagnos
})
continue
}

hadPrerelease := false
for _, constraint := range constraints {
if constraint.Prerelease() {
hadPrerelease = true
}
}
if hadPrerelease {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid version constraint",
Detail: fmt.Sprintf("Unsupported prerelease for constraint %q", constraintStr),
Subject: attr.Expr.Range().Ptr(),
})
}

vc.Required = constraints
rp.Requirement = vc

Expand Down

0 comments on commit b4a843c

Please sign in to comment.