Skip to content

Commit

Permalink
Fix some linting warnings. (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmaclean authored Jan 13, 2023
1 parent 1f4d6a9 commit 34ed5d9
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 109 deletions.
4 changes: 1 addition & 3 deletions acctest/pluginacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 1 addition & 3 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 19 additions & 19 deletions adapter/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -60,41 +60,41 @@ 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)

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
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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}

Expand All @@ -192,25 +192,25 @@ 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
}

if err := scpResponse(in); err != nil {
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)
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions chroot/communicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion communicator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} }
}

Expand Down
32 changes: 1 addition & 31 deletions multistep/commonsteps/iso_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions multistep/commonsteps/step_create_floppy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion multistep/commonsteps/step_create_floppy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions multistep/commonsteps/step_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion multistep/commonsteps/step_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion multistep/if.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions packer/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
20 changes: 10 additions & 10 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpc/ui_progress_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions sdk-internals/communicator/ssh/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions sdk-internals/communicator/winrm/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 34ed5d9

Please sign in to comment.