diff --git a/acctest/pluginacc.go b/acctest/pluginacc.go index 4f8c52355..579e9aee8 100644 --- a/acctest/pluginacc.go +++ b/acctest/pluginacc.go @@ -59,9 +59,7 @@ type TestTeardownFunc func() error //nolint:errcheck func TestPlugin(t *testing.T, testCase *PluginTestCase) { if os.Getenv(TestEnvVar) == "" { - t.Skip(fmt.Sprintf( - "Acceptance tests skipped unless env '%s' set", - TestEnvVar)) + t.Skipf("Acceptance tests skipped unless env '%s' set", TestEnvVar) return } diff --git a/adapter/adapter.go b/adapter/adapter.go index 0e27952ec..6b387ace6 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -105,7 +105,6 @@ func (c *Adapter) handleSession(newChannel ssh.NewChannel) error { // Sessions have requests such as "pty-req", "shell", "env", and "exec". // see RFC 4254, section 6 go func(in <-chan *ssh.Request) { - env := make([]envRequestPayload, 4) for req := range in { switch req.Type { case "pty-req": @@ -120,7 +119,6 @@ func (c *Adapter) handleSession(newChannel ssh.NewChannel) error { req.Reply(false, nil) continue } - env = append(env, req.Payload) log.Printf("new env request: %s", req.Payload) req.Reply(true, nil) case "exec": @@ -207,7 +205,7 @@ func (c *Adapter) exec(command string, in io.Reader, out io.Writer, err io.Write func serveSCP(args string) bool { opts, _ := scpOptions(args) - return bytes.IndexAny(opts, "tf") >= 0 + return bytes.ContainsAny(opts, "tf") } func (c *Adapter) scpExec(args string, in io.Reader, out io.Writer) error { diff --git a/adapter/scp.go b/adapter/scp.go index e65c56053..0b34c2937 100644 --- a/adapter/scp.go +++ b/adapter/scp.go @@ -42,13 +42,13 @@ well. func scpUploadSession(opts []byte, rest string, in io.Reader, out io.Writer, comm packersdk.Communicator) error { rest = strings.TrimSpace(rest) if len(rest) == 0 { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return errors.New("no scp target specified") } d, err := tmp.Dir("ansible-upload") if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } defer os.RemoveAll(d) @@ -60,20 +60,20 @@ func scpUploadSession(opts []byte, rest string, in io.Reader, out io.Writer, com // irrelevant. state := &scpUploadState{target: rest, srcRoot: d, comm: comm} - fmt.Fprintf(out, scpOK) // signal the client to start the transfer. + fmt.Fprint(out, scpOK) // signal the client to start the transfer. return state.Protocol(bufio.NewReader(in), out) } func scpDownloadSession(opts []byte, rest string, in io.Reader, out io.Writer, comm packersdk.Communicator) error { rest = strings.TrimSpace(rest) if len(rest) == 0 { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return errors.New("no scp source specified") } d, err := tmp.Dir("ansible-download") if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } defer os.RemoveAll(d) @@ -81,20 +81,20 @@ func scpDownloadSession(opts []byte, rest string, in io.Reader, out io.Writer, c if bytes.Contains([]byte{'d'}, opts) { // the only ansible module that supports downloading via scp is fetch, // fetch only supports file downloads as of Ansible 2.1. - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return errors.New("directory downloads not supported") } f, err := os.Create(filepath.Join(d, filepath.Base(rest))) if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } defer f.Close() err = comm.Download(rest, f) if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } @@ -118,7 +118,7 @@ func (state *scpDownloadState) FileProtocol(path string, info os.FileInfo, in *b defer f.Close() io.CopyN(out, f, size) - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) return scpResponse(in) } @@ -157,12 +157,12 @@ func (state *scpUploadState) Protocol(in *bufio.Reader, out io.Writer) error { return state.FileProtocol(in, out) case 'E': state.dir = filepath.Dir(state.dir) - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) return nil case 'D': return state.DirProtocol(in, out) default: - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return fmt.Errorf("unexpected message: %c", b) } } @@ -178,10 +178,10 @@ func (state *scpUploadState) FileProtocol(in *bufio.Reader, out io.Writer) error var name string _, err := fmt.Fscanf(in, "%04o %d %s\n", &mode, &size, &name) if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return fmt.Errorf("invalid file message: %v", err) } - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) var fi os.FileInfo = fileInfo{name: name, size: size, mode: mode, mtime: state.mtime} @@ -192,7 +192,7 @@ func (state *scpUploadState) FileProtocol(in *bufio.Reader, out io.Writer) error err = state.comm.Upload(dest, io.LimitReader(in, fi.Size()), &fi) if err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } @@ -200,17 +200,17 @@ func (state *scpUploadState) FileProtocol(in *bufio.Reader, out io.Writer) error return err } - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) return nil } func (state *scpUploadState) TimeProtocol(in *bufio.Reader, out io.Writer) error { var m, a int64 if _, err := fmt.Fscanf(in, "%d 0 %d 0\n", &m, &a); err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return err } - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) state.atime = time.Unix(a, 0) state.mtime = time.Unix(m, 0) @@ -223,10 +223,10 @@ func (state *scpUploadState) DirProtocol(in *bufio.Reader, out io.Writer) error var name string if _, err := fmt.Fscanf(in, "%04o %d %s\n", &mode, &length, &name); err != nil { - fmt.Fprintf(out, scpEmptyError) + fmt.Fprint(out, scpEmptyError) return fmt.Errorf("invalid directory message: %v", err) } - fmt.Fprintf(out, scpOK) + fmt.Fprint(out, scpOK) path := filepath.Join(state.dir, name) if err := os.Mkdir(path, mode); err != nil { diff --git a/chroot/communicator_test.go b/chroot/communicator_test.go index c6b6febca..0e8c383cb 100644 --- a/chroot/communicator_test.go +++ b/chroot/communicator_test.go @@ -12,6 +12,7 @@ import ( func TestCommunicator_ImplementsCommunicator(t *testing.T) { var raw interface{} raw = &Communicator{} + if _, ok := raw.(packersdk.Communicator); !ok { t.Fatalf("Communicator should be a communicator") } diff --git a/communicator/config.go b/communicator/config.go index f68190e2c..a63949159 100644 --- a/communicator/config.go +++ b/communicator/config.go @@ -627,7 +627,7 @@ func (c *Config) prepareWinRM(ctx *interpolate.Context) (errs []error) { c.WinRMTimeout = 30 * time.Minute } - if c.WinRMUseNTLM == true { + if c.WinRMUseNTLM { c.WinRMTransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} } } diff --git a/multistep/commonsteps/iso_config_test.go b/multistep/commonsteps/iso_config_test.go index e75c7dd0a..c2d0489bf 100644 --- a/multistep/commonsteps/iso_config_test.go +++ b/multistep/commonsteps/iso_config_test.go @@ -23,34 +23,6 @@ func testISOConfig() ISOConfig { } } -var cs_bsd_style = ` -MD5 (other.iso) = bAr -MD5 (the-OS.iso) = baZ -` - -var cs_bsd_style_subdir = ` -MD5 (other.iso) = bAr -MD5 (./subdir/the-OS.iso) = baZ -` - -var cs_gnu_style = ` -bAr0 *the-OS.iso -baZ0 other.iso -` - -var cs_gnu_style_subdir = ` -bAr0 *./subdir/the-OS.iso -baZ0 other.iso -` - -var cs_bsd_style_no_newline = ` -MD5 (other.iso) = bAr -MD5 (the-OS.iso) = baZ` - -var cs_gnu_style_no_newline = ` -bAr0 *the-OS.iso -baZ0 other.iso` - func TestISOConfigPrepare_ISOChecksum(t *testing.T) { i := testISOConfig() @@ -89,10 +61,8 @@ func TestISOConfigPrepare_ISOChecksumURLBad(t *testing.T) { } func TestISOConfigPrepare_ISOChecksumType(t *testing.T) { - i := testISOConfig() - // Test none - i = testISOConfig() + i := testISOConfig() i.ISOChecksum = "none" warns, err := i.Prepare(nil) if len(warns) == 0 { diff --git a/multistep/commonsteps/step_create_floppy.go b/multistep/commonsteps/step_create_floppy.go index 1757ca748..e5e2e3419 100644 --- a/multistep/commonsteps/step_create_floppy.go +++ b/multistep/commonsteps/step_create_floppy.go @@ -199,9 +199,7 @@ func (s *StepCreateFloppy) Run(ctx context.Context, state multistep.StateBag) mu return multistep.ActionHalt } - for _, filename := range matches { - pathqueue = append(pathqueue, filename) - } + pathqueue = append(pathqueue, matches...) continue } pathqueue = append(pathqueue, filename) diff --git a/multistep/commonsteps/step_create_floppy_test.go b/multistep/commonsteps/step_create_floppy_test.go index 57292ce3c..49f2babb2 100644 --- a/multistep/commonsteps/step_create_floppy_test.go +++ b/multistep/commonsteps/step_create_floppy_test.go @@ -248,7 +248,7 @@ func TestStepCreateFloppyDirectories(t *testing.T) { for _, c := range test.dirs { step.Directories = append(step.Directories, filepath.Join(dir, filepath.FromSlash(c))) } - log.Println(fmt.Sprintf("Trying against floppy_dirs : %v", step.Directories)) + log.Printf("Trying against floppy_dirs : %v\n", step.Directories) // run the step if action := step.Run(context.Background(), state); action != multistep.ActionContinue { diff --git a/multistep/commonsteps/step_download.go b/multistep/commonsteps/step_download.go index 26a00285f..e0a4272cd 100644 --- a/multistep/commonsteps/step_download.go +++ b/multistep/commonsteps/step_download.go @@ -31,8 +31,9 @@ import ( // progress reporting, interrupt handling, etc. // // Uses: -// cache packer.Cache -// ui packersdk.Ui +// +// cache packer.Cache +// ui packersdk.Ui type StepDownload struct { // The checksum and the type of the checksum for the download Checksum string @@ -124,7 +125,7 @@ func (s *StepDownload) Run(ctx context.Context, state multistep.StateBag) multis // TODO(adrien): make go-getter allow using files in place. // ovf files usually point to a file in the same directory, so // using them in place is the only way. - ui.Say(fmt.Sprintf("Using ovf inplace")) + ui.Say("Using ovf inplace") dst = source } else { dst, err = s.download(ctx, ui, source) diff --git a/multistep/commonsteps/step_provision.go b/multistep/commonsteps/step_provision.go index 77d7340aa..b132a80a1 100644 --- a/multistep/commonsteps/step_provision.go +++ b/multistep/commonsteps/step_provision.go @@ -107,7 +107,7 @@ func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBa if comm == nil { raw, ok := state.Get("communicator").(packersdk.Communicator) if ok { - comm = raw.(packersdk.Communicator) + comm = raw } } diff --git a/multistep/if.go b/multistep/if.go index ddbb4289b..b2d406afb 100644 --- a/multistep/if.go +++ b/multistep/if.go @@ -5,7 +5,7 @@ package multistep // if returns step only if on is true. func If(on bool, step Step) Step { - if on == false { + if !on { return &nullStep{} } return step diff --git a/packer/logs.go b/packer/logs.go index 0d5ad89b8..2445cb0ac 100644 --- a/packer/logs.go +++ b/packer/logs.go @@ -50,15 +50,6 @@ func (l *secretFilter) FilterString(message string) string { return message } -func (l *secretFilter) get() (s []string) { - l.m.Lock() - defer l.m.Unlock() - for k := range l.s { - s = append(s, k) - } - return -} - var LogSecretFilter secretFilter func init() { diff --git a/rpc/server.go b/rpc/server.go index 3e1a241cc..759f0594f 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -14,16 +14,16 @@ import ( const ( DefaultArtifactEndpoint string = "Artifact" - DefaultBuildEndpoint = "Build" - DefaultBuilderEndpoint = "Builder" - DefaultCacheEndpoint = "Cache" - DefaultCommandEndpoint = "Command" - DefaultCommunicatorEndpoint = "Communicator" - DefaultHookEndpoint = "Hook" - DefaultPostProcessorEndpoint = "PostProcessor" - DefaultProvisionerEndpoint = "Provisioner" - DefaultDatasourceEndpoint = "Datasource" - DefaultUiEndpoint = "Ui" + DefaultBuildEndpoint string = "Build" + DefaultBuilderEndpoint string = "Builder" + DefaultCacheEndpoint string = "Cache" + DefaultCommandEndpoint string = "Command" + DefaultCommunicatorEndpoint string = "Communicator" + DefaultHookEndpoint string = "Hook" + DefaultPostProcessorEndpoint string = "PostProcessor" + DefaultProvisionerEndpoint string = "Provisioner" + DefaultDatasourceEndpoint string = "Datasource" + DefaultUiEndpoint string = "Ui" ) // PluginServer represents an RPC server for Packer. This must be paired on the diff --git a/rpc/ui_progress_tracking.go b/rpc/ui_progress_tracking.go index 27d1b5477..c66a7911a 100644 --- a/rpc/ui_progress_tracking.go +++ b/rpc/ui_progress_tracking.go @@ -85,7 +85,7 @@ type ProgressTrackingServer struct { } func (t *ProgressTrackingServer) Add(size int, _ *interface{}) error { - stubBytes := make([]byte, size, size) + stubBytes := make([]byte, size) t.stream.Read(stubBytes) return nil } diff --git a/sdk-internals/communicator/ssh/communicator.go b/sdk-internals/communicator/ssh/communicator.go index 7d0f771b4..2cdc13d83 100644 --- a/sdk-internals/communicator/ssh/communicator.go +++ b/sdk-internals/communicator/ssh/communicator.go @@ -161,9 +161,9 @@ func (c *comm) Start(ctx context.Context, cmd *packersdk.RemoteCmd) (err error) err := session.Wait() exitStatus := 0 if err != nil { - switch err.(type) { + switch err := err.(type) { case *ssh.ExitError: - exitStatus = err.(*ssh.ExitError).ExitStatus() + exitStatus = err.ExitStatus() log.Printf("[ERROR] Remote command exited with '%d': %s", exitStatus, cmd.Command) case *ssh.ExitMissingError: log.Printf("[ERROR] Remote command exited without exit status or exit signal.") @@ -490,7 +490,6 @@ func (c *comm) connectToAgent() { } log.Printf("[INFO] agent forwarding enabled") - return } func (c *comm) sftpUploadSession(path string, input io.Reader, fi *os.FileInfo) error { diff --git a/sdk-internals/communicator/winrm/communicator.go b/sdk-internals/communicator/winrm/communicator.go index 8b18aa4fa..6d398b8bc 100644 --- a/sdk-internals/communicator/winrm/communicator.go +++ b/sdk-internals/communicator/winrm/communicator.go @@ -207,8 +207,7 @@ func (c *Communicator) newWinRMClient() (*winrm.Client, error) { // winrmcp uses even we we aren't using winrmcp. This ensures similar // behavior between upload, download, and copy functions. We can't use the // one generated by winrmcp because it isn't exported. - var endpoint *winrm.Endpoint - endpoint = &winrm.Endpoint{ + var endpoint = &winrm.Endpoint{ Host: c.endpoint.Host, Port: c.endpoint.Port, HTTPS: conf.Https, diff --git a/shell-local/config.go b/shell-local/config.go index 4e3f1d2fc..69f555a97 100644 --- a/shell-local/config.go +++ b/shell-local/config.go @@ -150,7 +150,7 @@ func Validate(config *Config) error { break } } - if supported_os != true { + if supported_os { return fmt.Errorf("Invalid OS specified in only_on: '%s'\n"+ "Supported OS names: %s", provided_os, strings.Join(supportedSyslist, ", ")) } @@ -188,11 +188,7 @@ func Validate(config *Config) error { } // drop unnecessary "." in extension; we add this later. - if config.TempfileExtension != "" { - if strings.HasPrefix(config.TempfileExtension, ".") { - config.TempfileExtension = config.TempfileExtension[1:] - } - } + config.TempfileExtension = strings.TrimPrefix(config.TempfileExtension, ".") // Do a check for bad environment variables, such as '=foo', 'foobar' for _, kv := range config.Vars { diff --git a/shell-local/run.go b/shell-local/run.go index cc97cc76a..99e734f70 100644 --- a/shell-local/run.go +++ b/shell-local/run.go @@ -39,7 +39,7 @@ func Run(ctx context.Context, ui packersdk.Ui, config *Config, generatedData map } } if !runCommand { - ui.Say(fmt.Sprintf("Skipping shell-local due to runtime OS")) + ui.Say("Skipping shell-local due to runtime OS") log.Printf("[INFO] (shell-local): skipping shell-local due to missing runtime OS") return true, nil } diff --git a/template/config/custom_types.go b/template/config/custom_types.go index a95858897..e709cc526 100644 --- a/template/config/custom_types.go +++ b/template/config/custom_types.go @@ -36,17 +36,11 @@ func (t Trilean) ToBoolPointer() *bool { } func (t Trilean) True() bool { - if t == TriTrue { - return true - } - return false + return t == TriTrue } func (t Trilean) False() bool { - if t == TriFalse { - return true - } - return false + return t == TriFalse } func TrileanFromString(s string) (Trilean, error) { @@ -57,7 +51,7 @@ func TrileanFromString(s string) (Trilean, error) { b, err := strconv.ParseBool(s) if err != nil { return TriUnset, err - } else if b == true { + } else if b { return TriTrue, nil } else { return TriFalse, nil diff --git a/template/config/decode.go b/template/config/decode.go index a9417e73a..902ee21fa 100644 --- a/template/config/decode.go +++ b/template/config/decode.go @@ -189,7 +189,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { } } } - if fixable == true { + if fixable { break } } diff --git a/template/interpolate/aws/secretsmanager/secretsmanager.go b/template/interpolate/aws/secretsmanager/secretsmanager.go index 856a88e85..9fd0d18f3 100644 --- a/template/interpolate/aws/secretsmanager/secretsmanager.go +++ b/template/interpolate/aws/secretsmanager/secretsmanager.go @@ -84,7 +84,7 @@ func getSecretValue(s *SecretString, spec *SecretSpec) (string, error) { blob := []byte(s.SecretString) //For those plaintext secrets just return the value - if json.Valid(blob) != true { + if !json.Valid(blob) { return s.SecretString, nil }