Skip to content

Commit

Permalink
Fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman committed May 21, 2024
1 parent 0902e38 commit c4ecb92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 7 additions & 7 deletions x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package cmd
import (
"bytes"
"context"
stderror "errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -269,7 +269,7 @@ func (c *enrollCmd) writeDelayEnroll(streams *cli.IOStreams) error {
errors.TypeConfig,
errors.M("path", enrollPath))
}
err = ioutil.WriteFile(enrollPath, data, 0600)
err = os.WriteFile(enrollPath, data, 0600)
if err != nil {
return errors.New(
err,
Expand Down Expand Up @@ -602,7 +602,7 @@ func (c *enrollCmd) startAgent(ctx context.Context) (<-chan *os.ProcessState, er

func (c *enrollCmd) stopAgent() {
if c.agentProc != nil {
c.agentProc.StopWait()
c.agentProc.StopWait() //nolint:errcheck // no error check here
c.agentProc = nil
}
}
Expand Down Expand Up @@ -664,7 +664,7 @@ func waitForAgent(ctx context.Context, timeout time.Duration) error {
for {
backOff.Wait()
_, err := getDaemonStatus(innerCtx)
if err == context.Canceled {
if stderror.Is(err, context.Canceled) {
resChan <- waitResult{err: err}
return
}
Expand Down Expand Up @@ -714,7 +714,7 @@ func waitForFleetServer(ctx context.Context, agentSubproc <-chan *os.ProcessStat
for {
backExp.Wait()
status, err := getDaemonStatus(innerCtx)
if err == context.Canceled {
if stderror.Is(err, context.Canceled) {
resChan <- waitResult{err: err}
return
}
Expand Down Expand Up @@ -827,7 +827,7 @@ func safelyStoreAgentInfo(s saver, reader io.Reader) error {
for i := 0; i <= maxRetriesstoreAgentInfo; i++ {
backExp.Wait()
err = storeAgentInfo(s, reader)
if err != filelock.ErrAppAlreadyRunning {
if stderror.Is(err, filelock.ErrAppAlreadyRunning) {
break
}
}
Expand All @@ -841,7 +841,7 @@ func storeAgentInfo(s saver, reader io.Reader) error {
if err := fileLock.TryLock(); err != nil {
return err
}
defer fileLock.Unlock()
defer fileLock.Unlock() //nolint:errcheck // defered call

if err := s.Save(reader); err != nil {
return errors.New(err, "could not save enrollment information", errors.TypeFilesystem)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions x-pack/elastic-agent/pkg/agent/control/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (s *Server) Upgrade(ctx context.Context, request *cproto.UpgradeRequest) (*
}
cb, err := u.Upgrade(ctx, &upgradeRequest{request}, false, request.SkipVerify, request.PgpBytes...)
if err != nil {
return &cproto.UpgradeResponse{
return &cproto.UpgradeResponse{ //nolint:nilerr // error is wrapped in response
Status: cproto.ActionStatus_FAILURE,
Error: err.Error(),
}, nil
Expand Down Expand Up @@ -235,7 +235,13 @@ func (s *Server) ProcMeta(ctx context.Context, _ *cproto.Empty) (*cproto.ProcMet
endpoint = "npipe"
}

res, err := client.Get("http://" + endpoint + "/")
req, err := http.NewRequestWithContext(ctx, "GET", "http://"+endpoint+"/", nil)
if err != nil {
procMeta.Error = err.Error()
resp.Procs = append(resp.Procs, procMeta)
continue
}
res, err := client.Do(req)
if err != nil {
procMeta.Error = err.Error()
resp.Procs = append(resp.Procs, procMeta)
Expand Down

0 comments on commit c4ecb92

Please sign in to comment.