Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Sep 26, 2024
1 parent 15a981d commit aa824b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions ee/desktop/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,21 @@ func (r *DesktopUsersProcessesRunner) DetectPresence(reason string, interval tim
}

var lastErr error
var lastDurationSinceLastDetection time.Duration

for _, proc := range r.uidProcs {
client := client.New(r.userServerAuthToken, proc.socketPath)
durationSinceLastDetection, err := client.DetectPresence(reason, interval)
lastDurationSinceLastDetection, err := client.DetectPresence(reason, interval)

if err != nil {
lastErr = err
continue
}

return durationSinceLastDetection, nil
return lastDurationSinceLastDetection, nil
}

return presencedetection.DetectionFailedDurationValue, fmt.Errorf("no desktop processes detected presence, last error: %w", lastErr)
return lastDurationSinceLastDetection, fmt.Errorf("no desktop processes detected presence, last error: %w", lastErr)
}

// killDesktopProcesses kills any existing desktop processes
Expand Down
6 changes: 3 additions & 3 deletions ee/desktop/user/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ func (c *client) DetectPresence(reason string, interval time.Duration) (time.Dur
}
}

var err error
var detectionErr error
if response.Error != "" {
err = errors.New(response.Error)
detectionErr = errors.New(response.Error)
}

durationSinceLastDetection, parseErr := time.ParseDuration(response.DurationSinceLastDetection)
if parseErr != nil {
return presencedetection.DetectionFailedDurationValue, fmt.Errorf("parsing time since last detection: %w", parseErr)
}

return durationSinceLastDetection, err
return durationSinceLastDetection, detectionErr
}

func (c *client) Notify(n notify.Notification) error {
Expand Down
4 changes: 2 additions & 2 deletions ee/localserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func New(ctx context.Context, k types.Knapsack, presenceDetector presenceDetecto
// curl localhost:40978/acceleratecontrol --data '{"interval":"250ms", "duration":"1s"}'
// mux.Handle("/acceleratecontrol", ls.requestAccelerateControlHandler())
// curl localhost:40978/id
mux.Handle("/id", ls.requestIdHandler())
// mux.Handle("/id", ls.requestIdHandler())

srv := &http.Server{
Handler: otelhttp.NewHandler(
Expand Down Expand Up @@ -419,7 +419,7 @@ func (ls *localServer) presenceDetectionHandler(next http.Handler) http.Handler
}

// can test this by adding an unauthed endpoint to the mux and running, for example:
// curl -H "X-Kolide-Presence-Detection-Interval: 10s" -H "X-Kolide-Presence-Detection-Reason: my reason" localhost:12519/id
// curl -i -H "X-Kolide-Presence-Detection-Interval: 10s" -H "X-Kolide-Presence-Detection-Reason: my reason" localhost:12519/id
detectionIntervalStr := r.Header.Get(kolidePresenceDetectionInterval)

// no presence detection requested
Expand Down

0 comments on commit aa824b1

Please sign in to comment.