Skip to content

Commit

Permalink
use osqueryd consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Aug 12, 2024
1 parent 5657a8d commit 42f4671
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pkg/osquery/enrollment_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 := `
Expand Down
4 changes: 2 additions & 2 deletions pkg/osquery/enrollment_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/osquery/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 42f4671

Please sign in to comment.