fleet/server/contexts/host/host.go
Lucas Manuel Rodriguez 371c533bfc
Improved Datastore usage of osquery hosts requests (#3601)
* 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
2022-01-17 22:52:09 -03:00

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
}