mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 11:20:27 -06:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/live/livecontext"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
)
|
|
|
|
type BuiltinDataOutput struct {
|
|
channelHandlerGetter ChannelHandlerGetter
|
|
}
|
|
|
|
const DataOutputTypeBuiltin = "builtin"
|
|
|
|
func NewBuiltinDataOutput(channelHandlerGetter ChannelHandlerGetter) *BuiltinDataOutput {
|
|
return &BuiltinDataOutput{channelHandlerGetter: channelHandlerGetter}
|
|
}
|
|
|
|
func (s *BuiltinDataOutput) Type() string {
|
|
return DataOutputTypeBuiltin
|
|
}
|
|
|
|
func (s *BuiltinDataOutput) OutputData(ctx context.Context, vars Vars, data []byte) ([]*ChannelData, error) {
|
|
u, ok := livecontext.GetContextSignedUser(ctx)
|
|
if !ok {
|
|
return nil, errors.New("user not found in context")
|
|
}
|
|
handler, _, err := s.channelHandlerGetter.GetChannelHandler(u, vars.Channel)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_, status, err := handler.OnPublish(ctx, u, models.PublishEvent{
|
|
Channel: vars.Channel,
|
|
Data: data,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if status != backend.PublishStreamStatusOK {
|
|
return nil, errors.New("unauthorized publish")
|
|
}
|
|
return nil, nil
|
|
}
|