Skip to content

Commit

Permalink
backport of commit 3053b4e
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajolet-hashicorp committed Jul 18, 2024
1 parent c765ae3 commit 376d767
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 52 deletions.
2 changes: 1 addition & 1 deletion command/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Test_fmt_pipe(t *testing.T) {
p := helperCommand(t, tc.command...)
p.Stdin = strings.NewReader(tc.piped)
p.Env = append(p.Env, tc.env...)
fmt.Println(fmt.Sprintf("Path: %s", p.Path))
t.Logf("Path: %s", p.Path)
bs, err := p.Output()
if err != nil {
t.Fatalf("Error occurred running command %v: %s", err, bs)
Expand Down
7 changes: 3 additions & 4 deletions datasource/http/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func isContentTypeText(contentType string) bool {
allowedContentTypes := []*regexp.Regexp{
regexp.MustCompile("^text/.+"),
regexp.MustCompile("^application/json$"),
regexp.MustCompile("^application/samlmetadata\\+xml"),
regexp.MustCompile(`^application/samlmetadata\+xml`),
}

for _, r := range allowedContentTypes {
Expand Down Expand Up @@ -131,9 +131,8 @@ func (d *Datasource) Execute() (cty.Value, error) {

contentType := resp.Header.Get("Content-Type")
if contentType == "" || isContentTypeText(contentType) == false {
fmt.Println(fmt.Sprintf(
"Content-Type is not recognized as a text type, got %q",
contentType))
fmt.Printf("Content-Type is not recognized as a text type, got %q\n",
contentType)
fmt.Println("If the content is binary data, Packer may not properly handle the contents of the response.")
}

Expand Down
24 changes: 4 additions & 20 deletions fix/fixer_comm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FixerCommConfig struct{}

func (FixerCommConfig) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*": []string{"ssh_host_port_min", "ssh_host_port_max",
"*": {"ssh_host_port_min", "ssh_host_port_max",
"ssh_skip_nat_mapping"},
}
}
Expand Down Expand Up @@ -46,14 +46,9 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}

// ssh_host_port_min to host_port_min
if _, ok := builders["host_port_min"]; ok {

// drop ssh_host_port_min if it is also included
if _, sshHostPortMinIncluded := builders["ssh_host_port_min"]; sshHostPortMinIncluded {
delete(builders, "ssh_host_port_min")
}

delete(builders, "ssh_host_port_min")
} else if _, ok := builders["ssh_host_port_min"]; ok {

// replace ssh_host_port_min with host_port_min
sshHostPortMinRaw := builders["ssh_host_port_min"]
delete(builders, "ssh_host_port_min")
Expand All @@ -62,31 +57,20 @@ func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}

// ssh_host_port_max to host_port_max
if _, ok := builders["host_port_max"]; ok {

// drop ssh_host_port_max if it is also included
if _, sshHostPortMaxIncluded := builders["ssh_host_port_max"]; sshHostPortMaxIncluded {
delete(builders, "ssh_host_port_max")
}

delete(builders, "ssh_host_port_max")
} else if _, ok := builders["ssh_host_port_max"]; ok {

// replace ssh_host_port_max with host_port_max
sshHostPortMaxRaw := builders["ssh_host_port_max"]
delete(builders, "ssh_host_port_max")
builders["host_port_max"] = sshHostPortMaxRaw

}

// ssh_skip_nat_mapping to skip_nat_mapping
if _, ok := builders["skip_nat_mapping"]; ok {

// drop ssh_skip_nat_mapping if it is also included
if _, sshSkipNatMappingIncluded := builders["ssh_skip_nat_mapping"]; sshSkipNatMappingIncluded {
delete(builders, "ssh_skip_nat_mapping")
}

delete(builders, "ssh_skip_nat_mapping")
} else if _, ok := builders["ssh_skip_nat_mapping"]; ok {

// replace ssh_skip_nat_mapping with skip_nat_mapping
sshSkipNatMappingRaw := builders["ssh_skip_nat_mapping"]
sshSkipNatMappingBool, ok := sshSkipNatMappingRaw.(bool)
Expand Down
8 changes: 2 additions & 6 deletions fix/fixer_galaxy_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FixerGalaxyCommand struct{}

func (FixerGalaxyCommand) DeprecatedOptions() map[string][]string {
return map[string][]string{
"ansible": []string{"galaxycommand"},
"ansible": {"galaxycommand"},
}
}

Expand All @@ -40,12 +40,8 @@ func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interfac
}

if _, ok := provisioners["galaxy_command"]; ok {

// drop galaxycommand if it is also included
if _, galaxyCommandIncluded := provisioners["galaxycommand"]; galaxyCommandIncluded {
delete(provisioners, "galaxycommand")
}

delete(provisioners, "galaxycommand")
} else {

// replace galaxycommand with galaxy_command if it exists
Expand Down
8 changes: 2 additions & 6 deletions fix/fixer_ssh_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FixerSSHTimout struct{}

func (FixerSSHTimout) DeprecatedOptions() map[string][]string {
return map[string][]string{
"*": []string{"ssh_wait_timeout"},
"*": {"ssh_wait_timeout"},
}
}

Expand All @@ -35,12 +35,8 @@ func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{},
}

if _, ok := builders["ssh_timeout"]; ok {

// drop ssh_wait_timeout if it is also included
if _, sshWaitTimeoutIncluded := builders["ssh_wait_timeout"]; sshWaitTimeoutIncluded {
delete(builders, "ssh_wait_timeout")
}

delete(builders, "ssh_wait_timeout")
} else {

// replace ssh_wait_timeout with ssh_timeout if it exists
Expand Down
5 changes: 2 additions & 3 deletions packer/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func (c *Core) renderVarsRecursively() (*interpolate.Context, error) {
for _, kv := range sortedMap {
// Interpolate the default
renderedV, err := interpolate.RenderRegex(kv.Value, ctx, renderFilter)
switch err.(type) {
switch err := err.(type) {
case nil:
// We only get here if interpolation has succeeded, so something is
// different in this loop than in the last one.
Expand All @@ -910,8 +910,7 @@ func (c *Core) renderVarsRecursively() (*interpolate.Context, error) {
shouldRetry = true
}
case ttmp.ExecError:
castError := err.(ttmp.ExecError)
if strings.Contains(castError.Error(), interpolate.ErrVariableNotSetString) {
if strings.Contains(err.Error(), interpolate.ErrVariableNotSetString) {
shouldRetry = true
failedInterpolation = fmt.Sprintf(`"%s": "%s"; error: %s`, kv.Key, kv.Value, err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packer/plugin-getter/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,6 @@ func init() {
// Should never error if both components are set
localAPIVersion, err = NewAPIVersion(fmt.Sprintf("x%s.%s", pluginsdk.APIVersionMajor, pluginsdk.APIVersionMinor))
if err != nil {
panic(fmt.Sprintf("malformed API version in Packer. This is a programming error, please open an error to report it."))
panic("malformed API version in Packer. This is a programming error, please open an error to report it.")
}
}
1 change: 0 additions & 1 deletion post-processor/compress/post-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ func (config *Config) detectFromFilename() {
// We didn't match a known compression format. Default to tar + pgzip
config.Algorithm = "pgzip"
config.Archive = "tar"
return
}

func makeBGZFWriter(output io.WriteCloser, compressionLevel int) (io.WriteCloser, error) {
Expand Down
5 changes: 1 addition & 4 deletions provisioner/shell/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packe

if p.config.PauseAfter != 0 {
ui.Say(fmt.Sprintf("Pausing %s after this provisioner...", p.config.PauseAfter))
select {
case <-time.After(p.config.PauseAfter):
return nil
}
time.Sleep(p.config.PauseAfter)
}

return nil
Expand Down
10 changes: 4 additions & 6 deletions provisioner/windows-restart/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,15 @@ func TestProvision_waitForRestartTimeout(t *testing.T) {

// Block until cancel comes through
waitForCommunicator = func(context.Context, *Provisioner) error {
for {
select {
case <-waitDone:
waitContinue <- true
}
for range waitDone {
}
waitContinue <- true
return nil
}

go func() {
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
waitDone <- true
close(waitDone)
}()
<-waitContinue

Expand Down

0 comments on commit 376d767

Please sign in to comment.