2016-09-26 17:14:39 +00:00
|
|
|
// Package host enables setting and reading
|
|
|
|
|
// the current host from context
|
|
|
|
|
package host
|
|
|
|
|
|
|
|
|
|
import (
|
2016-09-26 18:48:55 +00:00
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
2016-10-31 22:18:05 +00:00
|
|
|
"golang.org/x/net/context"
|
2016-09-26 17:14:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type key int
|
|
|
|
|
|
|
|
|
|
const hostKey key = 0
|
|
|
|
|
|
|
|
|
|
// NewContext returns a new context carrying the current osquery host.
|
|
|
|
|
func NewContext(ctx context.Context, host kolide.Host) context.Context {
|
|
|
|
|
return context.WithValue(ctx, hostKey, host)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FromContext extracts the osquery host from context if present.
|
|
|
|
|
func FromContext(ctx context.Context) (kolide.Host, bool) {
|
|
|
|
|
host, ok := ctx.Value(hostKey).(kolide.Host)
|
|
|
|
|
return host, ok
|
|
|
|
|
}
|