mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 14:58:33 +00:00
* WIP * Amend tests * Do not load aggregated stats for packs * Add option to host lite * Fix remaining TODOs * Fix osquery_utils tests * Fix SQL * Fix SQL (bis) * Restore AuthenticateHost to load once * Code improvements and re-add deferred host save * More fixes to the PR * Wrap users table update on tx * Add caching to ListPacksForHost and ListScheduledQueriesInPack * Remove SaveHostSoftware (replaced by UpdateHostSoftware) * Add unit tests for new functionality * Add changes file * Fix scheduled queries test
24 lines
580 B
Go
24 lines
580 B
Go
// Package host enables setting and reading
|
|
// the current host from context
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
type key int
|
|
|
|
const hostKey key = 0
|
|
|
|
// NewContext returns a new context carrying the current osquery host.
|
|
func NewContext(ctx context.Context, host *fleet.Host) context.Context {
|
|
return context.WithValue(ctx, hostKey, host)
|
|
}
|
|
|
|
// FromContext extracts the osquery host from context if present.
|
|
func FromContext(ctx context.Context) (*fleet.Host, bool) {
|
|
host, ok := ctx.Value(hostKey).(*fleet.Host)
|
|
return host, ok
|
|
}
|