Skip to content

Commit

Permalink
common: validate iso_file input
Browse files Browse the repository at this point in the history
  • Loading branch information
mpywell authored and lbajolet-hashicorp committed Oct 28, 2024
1 parent 75dded5 commit 7661fdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st
// (possibly to a local file) to an ISO file that will be downloaded and
// then uploaded to Proxmox.
if c.ISOs[idx].ISOFile != "" {
// ISOFile should match <storage>:iso/<ISO filename> format
res := regexp.MustCompile(`^.+:iso\/.+$`)
if !res.MatchString(c.ISOs[idx].ISOFile) {
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("iso_path should match pattern \"<storage>:iso/<ISO filename>\". Provided value was \"%s\"", c.ISOs[idx].ISOFile))
}
c.ISOs[idx].ShouldUploadISO = false
} else {
c.ISOs[idx].DownloadPathKey = "downloaded_additional_iso_path_" + strconv.Itoa(idx)
Expand Down
11 changes: 11 additions & 0 deletions builder/proxmox/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ func TestISOs(t *testing.T) {
"type": "ide",
},
},
{
name: "iso_file should fail if not correct format",
expectedToFail: true,
ISOs: map[string]interface{}{
"type": "ide",
"cd_files": []string{
"config_test.go",
},
"iso_file": "local:/test.iso",
},
},
{
name: "cd_files and iso_file specified should fail",
expectedToFail: true,
Expand Down

0 comments on commit 7661fdf

Please sign in to comment.