mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 00:45:19 +00:00
28 lines
879 B
Go
28 lines
879 B
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
|
|
authz_ctx "github.com/fleetdm/fleet/v4/server/contexts/authz"
|
|
hostctx "github.com/fleetdm/fleet/v4/server/contexts/host"
|
|
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
// UserContext returns a new context with the provided user as the viewer.
|
|
func UserContext(ctx context.Context, user *fleet.User) context.Context {
|
|
return viewer.NewContext(ctx, viewer.Viewer{User: user})
|
|
}
|
|
|
|
// HostContext returns a new context with the provided host as the
|
|
// device-authenticated host.
|
|
func HostContext(ctx context.Context, host *fleet.Host) context.Context {
|
|
authzCtx := &authz_ctx.AuthorizationContext{}
|
|
ctx = authz_ctx.NewContext(ctx, authzCtx)
|
|
ctx = hostctx.NewContext(ctx, host)
|
|
if ac, ok := authz_ctx.FromContext(ctx); ok {
|
|
ac.SetAuthnMethod(authz_ctx.AuthnDeviceToken)
|
|
}
|
|
return ctx
|
|
}
|