From 6fd1a7efed83dce62393ba8fe1debb13bcbb7fd5 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Thu, 28 Jul 2022 16:30:05 +0200 Subject: [PATCH] make linter happy Signed-off-by: Florian Lehner --- .../actions/handlers/handler_action_unenroll.go | 4 +++- internal/pkg/core/plugin/process/app.go | 9 +++++++-- internal/pkg/crypto/io.go | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/pkg/agent/application/pipeline/actions/handlers/handler_action_unenroll.go b/internal/pkg/agent/application/pipeline/actions/handlers/handler_action_unenroll.go index 66b1ce8612b..a87b457893d 100644 --- a/internal/pkg/agent/application/pipeline/actions/handlers/handler_action_unenroll.go +++ b/internal/pkg/agent/application/pipeline/actions/handlers/handler_action_unenroll.go @@ -75,7 +75,9 @@ func (h *Unenroll) Handle(ctx context.Context, a fleetapi.Action, acker store.Fl } else if h.stateStore != nil { // backup action for future start to avoid starting fleet gateway loop h.stateStore.Add(a) - h.stateStore.Save() + if err := h.stateStore.Save(); err != nil { + return err + } } // close fleet gateway loop diff --git a/internal/pkg/core/plugin/process/app.go b/internal/pkg/core/plugin/process/app.go index 1c5ad2067af..c6dff46473e 100644 --- a/internal/pkg/core/plugin/process/app.go +++ b/internal/pkg/core/plugin/process/app.go @@ -228,7 +228,10 @@ func (a *Application) watch(ctx context.Context, p app.Taggable, proc *process.I a.setState(state.Restarting, msg, nil) // it was a crash - a.start(ctx, p, cfg, true) + if err := a.start(ctx, p, cfg, true); err != nil { + a.setState(state.Failed, err.Error(), nil) + return + } }() } @@ -274,7 +277,9 @@ func (a *Application) setState(s state.Status, msg string, payload map[string]in } func (a *Application) cleanUp() { - a.monitor.Cleanup(a.desc.Spec(), a.pipelineID) + if err := a.monitor.Cleanup(a.desc.Spec(), a.pipelineID); err != nil { + a.setState(state.Failed, fmt.Sprintf("cleanup failed: %s", err.Error()), nil) + } } func (a *Application) gracefulKill(proc *process.Info) { diff --git a/internal/pkg/crypto/io.go b/internal/pkg/crypto/io.go index 1b25a9a1fa8..c4fe29dfab0 100644 --- a/internal/pkg/crypto/io.go +++ b/internal/pkg/crypto/io.go @@ -180,7 +180,6 @@ func (w *Writer) Write(b []byte) (int, error) { } func (w *Writer) writeBlock(b []byte) error { - // randomly generate the salt and the initialization vector, this information will be saved // on disk in the file as part of the header iv, err := w.generator(w.option.IVLength) @@ -189,13 +188,17 @@ func (w *Writer) writeBlock(b []byte) error { return w.err } - w.writer.Write(iv) + if _, err := w.writer.Write(iv); err != nil { + return errors.Wrap(err, "failed to write IV") + } encodedBytes := w.gcm.Seal(nil, iv, b, nil) l := make([]byte, 4) binary.LittleEndian.PutUint32(l, uint32(len(encodedBytes))) - w.writer.Write(l) + if _, err := w.writer.Write(l); err != nil { + return errors.Wrap(err, "failed to write length of encoded bytes") + } _, err = w.writer.Write(encodedBytes) if err != nil { @@ -325,7 +328,7 @@ func (r *Reader) consumeBlock() error { } encodedBytes := make([]byte, l) - _, err = io.ReadAtLeast(r.reader, encodedBytes, int(l)) + _, err = io.ReadAtLeast(r.reader, encodedBytes, l) if err != nil { r.err = errors.Wrapf(err, "fail read the block of %d bytes", l) } @@ -364,7 +367,6 @@ func (r *Reader) Close() error { func randomBytes(length int) ([]byte, error) { r := make([]byte, length) _, err := rand.Read(r) - if err != nil { return nil, err }