func authenticatedHost(svc fleet.Service, logger log.Logger, next endpoint.Endpoint) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		nodeKey, err := getNodeKey(request)
		if err != nil {
			return nil, err
		}

		host, debug, err := svc.AuthenticateHost(ctx, nodeKey)
		if err != nil {
			logging.WithErr(ctx, err)
			return nil, err
		}

		hlogger := log.With(logger, "host-id", host.ID)
		if debug {
			logJSON(hlogger, request, "request")
		}

		ctx = hostctx.NewContext(ctx, *host)
		resp, err := next(ctx, request)
		if err != nil {
			logging.WithErr(ctx, err)
			return nil, err
		}

		if debug {
			logJSON(hlogger, request, "response")
		}

		if errResp, ok := resp.(errorer); ok {
			err = errResp.error()
			if err != nil {
				logging.WithErr(ctx, err)
			}
		}
		return resp, nil
	}
}
// authenticatedHost wraps an endpoint, checks the validity of the node_key
// provided in the request, and attaches the corresponding osquery host to the
// context for the request
authenticatedHost wraps an endpoint, checks the validity of the node_key
provided in the request, and attaches the corresponding osquery host to the
context for the request
// authenticatedHost wraps an endpoint checks the validity of the node_key // provided in the request and attaches the corresponding osquery host to the // context for the request
func authenticatedHost(svc fleet.Service, logger log.Logger, next endpoint.Endpoint) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		nodeKey, err := getNodeKey(request)
		if err != nil {
			return nil, err
		}
		host, debug, err := svc.AuthenticateHost(ctx, nodeKey)
		if err != nil {
			logging.WithErr(ctx, err)
			return nil, err
		}
		hlogger := log.With(logger, "host-id", host.ID)
		if debug {
			logJSON(hlogger, request, "request")
		}
		ctx = hostctx.NewContext(ctx, *host)
		resp, err := next(ctx, request)
		if err != nil {
			logging.WithErr(ctx, err)
			return nil, err
		}
		if debug {
			logJSON(hlogger, request, "response")
		}
		if errResp, ok := resp.(errorer); ok {
			err = errResp.error()
			if err != nil {
				logging.WithErr(ctx, err)
			}
		}
		return resp, nil
	}
}
func authenticatedHost ( svc fleet . Service , logger log . Logger , next endpoint . Endpoint ) endpoint . Endpoint { return func ( ctx context . Context , request interface { } ) ( interface { } , error ) { nodeKey , err := getNodeKey ( request ) if err != nil { return nil , err } host , debug , err := svc . AuthenticateHost ( ctx , nodeKey ) if err != nil { logging . WithErr ( ctx , err ) return nil , err } hlogger := log . With ( logger , " " , host . ID ) if debug { logJSON ( hlogger , request , " " ) } ctx = hostctx . NewContext ( ctx , * host ) resp , err := next ( ctx , request ) if err != nil { logging . WithErr ( ctx , err ) return nil , err } if debug { logJSON ( hlogger , request , " " ) } if errResp , ok := resp . ( errorer ) ; ok { err = errResp . error ( ) if err != nil { logging . WithErr ( ctx , err ) } } return resp , nil } }
authenticatedHost wraps an endpoint, checks the validity of the node_key
provided in the request, and attaches the corresponding osquery host to the
context for the request
authenticatedHost wraps an endpoint checks the validity of the node_key provided in the request and attaches the corresponding osquery host to the context for the request