From 42f46713b8fa41fe6ee61898dc886785217e125c Mon Sep 17 00:00:00 2001 From: James Pickett Date: Mon, 12 Aug 2024 14:13:26 -0700 Subject: [PATCH] use osqueryd consistently --- pkg/osquery/enrollment_details.go | 12 ++++++------ pkg/osquery/enrollment_details_test.go | 4 ++-- pkg/osquery/extension.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/osquery/enrollment_details.go b/pkg/osquery/enrollment_details.go index 22a74c006..e34d81d80 100644 --- a/pkg/osquery/enrollment_details.go +++ b/pkg/osquery/enrollment_details.go @@ -19,10 +19,10 @@ import ( "github.com/pkg/errors" ) -type osqueryNotFound struct{} +type osquerydNotFound struct{} -func (e osqueryNotFound) Error() string { - return ("osquery not found") +func (e osquerydNotFound) Error() string { + return ("osqueryd not found") } func getEnrollDetails(ctx context.Context, osquerydPath string) (service.EnrollmentDetails, error) { @@ -42,11 +42,11 @@ func getEnrollDetails(ctx context.Context, osquerydPath string) (service.Enrollm // If the binary doesn't exist, bail out early. if info, err := os.Stat(osquerydPath); os.IsNotExist(err) { - return details, fmt.Errorf("%w: no binary at %s:", osqueryNotFound{}, osquerydPath) + return details, fmt.Errorf("%w: no binary at %s:", osquerydNotFound{}, osquerydPath) } else if info.IsDir() { - return details, fmt.Errorf("%w: %s is a directory", osqueryNotFound{}, osquerydPath) + return details, fmt.Errorf("%w: %s is a directory", osquerydNotFound{}, osquerydPath) } else if err != nil { - return details, fmt.Errorf("%w: statting %s: %w", osqueryNotFound{}, osquerydPath, err) + return details, fmt.Errorf("%w: statting %s: %w", osquerydNotFound{}, osquerydPath, err) } query := ` diff --git a/pkg/osquery/enrollment_details_test.go b/pkg/osquery/enrollment_details_test.go index 53199fcb8..6715f9f2d 100644 --- a/pkg/osquery/enrollment_details_test.go +++ b/pkg/osquery/enrollment_details_test.go @@ -29,11 +29,11 @@ func Test_getEnrollDetails_binaryNotExist(t *testing.T) { enrollmentDetails, err := getEnrollDetails(context.TODO(), filepath.Join("some", "fake", "path", "to", "osqueryd")) require.Equal(t, expectedEnrollDetailsNoOsqueryd, enrollmentDetails, "expected enrollment details to have runtime values when osqueryd does not exist") - require.ErrorIs(t, err, osqueryNotFound{}, "expected error when osqueryd does not exist") + require.ErrorIs(t, err, osquerydNotFound{}, "expected error when osqueryd does not exist") enrollmentDetails, err = getEnrollDetails(context.TODO(), t.TempDir()) require.Equal(t, expectedEnrollDetailsNoOsqueryd, enrollmentDetails, "expected enrollment details to have runtime values when osqueryd does not exist") - require.ErrorIs(t, err, osqueryNotFound{}, "expected error when osqueryd does not exist") + require.ErrorIs(t, err, osquerydNotFound{}, "expected error when osqueryd does not exist") } func Test_getEnrollDetails_executionError(t *testing.T) { diff --git a/pkg/osquery/extension.go b/pkg/osquery/extension.go index ee2ef752a..21fe93e24 100644 --- a/pkg/osquery/extension.go +++ b/pkg/osquery/extension.go @@ -423,7 +423,7 @@ func (e *Extension) Enroll(ctx context.Context) (string, bool, error) { if err := backoff.WaitFor(func() error { enrollDetails, err = getEnrollDetails(ctx, osqPath) switch { - case errors.Is(err, osqueryNotFound{}): + case errors.Is(err, osquerydNotFound{}): e.slogger.Log(ctx, slog.LevelDebug, "osquery not found, using runtime values for enrollment", "err", err,