source

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 16 Imported by: 5

Documentation

Index

Constants

View Source
const ProtocolVersion = 1

ProtocolVersion is the version that must match between Botkube core and Botkube plugins. This should be bumped whenever a change happens in one or the other that makes it so that they can't safely communicate. This could be adding a new interface value, it could be how helper/schema computes diffs, etc.

NOTE: In the future we can consider using VersionedPlugins. These can be used to negotiate a compatible version between client and server. If this is set, Handshake.ProtocolVersion is not required.

Variables

View Source
var File_source_proto protoreflect.FileDescriptor
View Source
var Source_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "source.Source",
	HandlerType: (*SourceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Metadata",
			Handler:    _Source_Metadata_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Stream",
			Handler:       _Source_Stream_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "source.proto",
}

Source_ServiceDesc is the grpc.ServiceDesc for Source service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func NewLogger added in v1.0.1

func NewLogger() logrus.FieldLogger

NewLogger returns a new logger used internally. We should replace it in the near future, as we shouldn't be so opinionated.

func RegisterSourceServer

func RegisterSourceServer(s grpc.ServiceRegistrar, srv SourceServer)

func Serve

func Serve(p map[string]plugin.Plugin)

Serve serves given plugins.

Types

type Config

type Config struct {

	// RawYAML contains the Source configuration in YAML definitions.
	RawYAML []byte `protobuf:"bytes,1,opt,name=rawYAML,proto3" json:"rawYAML,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) Descriptor deprecated

func (*Config) Descriptor() ([]byte, []int)

Deprecated: Use Config.ProtoReflect.Descriptor instead.

func (*Config) GetRawYAML

func (x *Config) GetRawYAML() []byte

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) ProtoReflect

func (x *Config) ProtoReflect() protoreflect.Message

func (*Config) Reset

func (x *Config) Reset()

func (*Config) String

func (x *Config) String() string

type Dependency added in v0.18.0

type Dependency struct {

	// urls is the map of URL of the dependency. The key is in format of "os/arch", such as "linux/amd64".
	Urls map[string]string `` /* 149-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Dependency) Descriptor deprecated added in v0.18.0

func (*Dependency) Descriptor() ([]byte, []int)

Deprecated: Use Dependency.ProtoReflect.Descriptor instead.

func (*Dependency) GetUrls added in v0.18.0

func (x *Dependency) GetUrls() map[string]string

func (*Dependency) ProtoMessage added in v0.18.0

func (*Dependency) ProtoMessage()

func (*Dependency) ProtoReflect added in v0.18.0

func (x *Dependency) ProtoReflect() protoreflect.Message

func (*Dependency) Reset added in v0.18.0

func (x *Dependency) Reset()

func (*Dependency) SetUrls added in v0.18.0

func (d *Dependency) SetUrls(in map[string]string)

SetUrls sets the urls map for the dependency.

This method is needed because of current Go limitation: > The Go compiler does not support accessing a struct field x.f where x is of type parameter type even if all types in the type parameter's type set have a field f. We may remove this restriction in a future release. See https://go.dev/doc/go1.18 and https://github.com/golang/go/issues/48522

func (*Dependency) String added in v0.18.0

func (x *Dependency) String() string

type Event added in v1.0.0

type Event struct {
	Message         api.Message
	RawObject       any
	AnalyticsLabels map[string]interface{}
}

type JSONSchema added in v0.18.0

type JSONSchema struct {

	// value is the string value of the JSON schema.
	Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	// ref_url is the remote reference of the JSON schema.
	RefUrl string `protobuf:"bytes,2,opt,name=ref_url,json=refUrl,proto3" json:"ref_url,omitempty"`
	// contains filtered or unexported fields
}

func (*JSONSchema) Descriptor deprecated added in v0.18.0

func (*JSONSchema) Descriptor() ([]byte, []int)

Deprecated: Use JSONSchema.ProtoReflect.Descriptor instead.

func (*JSONSchema) GetRefUrl added in v0.18.0

func (x *JSONSchema) GetRefUrl() string

func (*JSONSchema) GetValue added in v0.18.0

func (x *JSONSchema) GetValue() string

func (*JSONSchema) ProtoMessage added in v0.18.0

func (*JSONSchema) ProtoMessage()

func (*JSONSchema) ProtoReflect added in v0.18.0

func (x *JSONSchema) ProtoReflect() protoreflect.Message

func (*JSONSchema) Reset added in v0.18.0

func (x *JSONSchema) Reset()

func (*JSONSchema) String added in v0.18.0

func (x *JSONSchema) String() string

type MetadataResponse

type MetadataResponse struct {

	// version is a version of a given plugin. It should follow the SemVer syntax.
	Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
	// description is a description of a given plugin.
	Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
	// json_schema is a JSON schema of a given plugin.
	JsonSchema *JSONSchema `protobuf:"bytes,3,opt,name=json_schema,json=jsonSchema,proto3" json:"json_schema,omitempty"`
	// dependencies is a list of dependencies of a given plugin.
	Dependencies map[string]*Dependency `` /* 165-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*MetadataResponse) Descriptor deprecated

func (*MetadataResponse) Descriptor() ([]byte, []int)

Deprecated: Use MetadataResponse.ProtoReflect.Descriptor instead.

func (*MetadataResponse) GetDependencies added in v0.18.0

func (x *MetadataResponse) GetDependencies() map[string]*Dependency

func (*MetadataResponse) GetDescription

func (x *MetadataResponse) GetDescription() string

func (*MetadataResponse) GetJsonSchema added in v0.18.0

func (x *MetadataResponse) GetJsonSchema() *JSONSchema

func (*MetadataResponse) GetVersion

func (x *MetadataResponse) GetVersion() string

func (*MetadataResponse) ProtoMessage

func (*MetadataResponse) ProtoMessage()

func (*MetadataResponse) ProtoReflect

func (x *MetadataResponse) ProtoReflect() protoreflect.Message

func (*MetadataResponse) Reset

func (x *MetadataResponse) Reset()

func (*MetadataResponse) String

func (x *MetadataResponse) String() string

type Plugin

type Plugin struct {
	// The GRPC plugin must still implement the Plugin interface.
	plugin.NetRPCUnsupportedPlugin

	// Source represent a concrete implementation that handles the business logic.
	Source Source
}

Plugin This is the implementation of plugin.GRPCPlugin, so we can serve and consume different Botkube Sources.

func (*Plugin) GRPCClient

func (p *Plugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient returns the interface implementation for the plugin that is serving via gRPC by GRPCServer.

func (*Plugin) GRPCServer

func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer registers plugin for serving with the given GRPCServer.

type Source

type Source interface {
	Stream(context.Context, StreamInput) (StreamOutput, error)
	Metadata(context.Context) (api.MetadataOutput, error)
}

Source defines the Botkube source plugin functionality.

type SourceClient

type SourceClient interface {
	Stream(ctx context.Context, in *StreamRequest, opts ...grpc.CallOption) (Source_StreamClient, error)
	Metadata(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*MetadataResponse, error)
}

SourceClient is the client API for Source service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewSourceClient

func NewSourceClient(cc grpc.ClientConnInterface) SourceClient

type SourceServer

type SourceServer interface {
	Stream(*StreamRequest, Source_StreamServer) error
	Metadata(context.Context, *emptypb.Empty) (*MetadataResponse, error)
	// contains filtered or unexported methods
}

SourceServer is the server API for Source service. All implementations must embed UnimplementedSourceServer for forward compatibility

type Source_StreamClient

type Source_StreamClient interface {
	Recv() (*StreamResponse, error)
	grpc.ClientStream
}

type Source_StreamServer

type Source_StreamServer interface {
	Send(*StreamResponse) error
	grpc.ServerStream
}

type StreamContext added in v1.0.0

type StreamContext struct {
	IsInteractivitySupported bool `protobuf:"varint,1,opt,name=isInteractivitySupported,proto3" json:"isInteractivitySupported,omitempty"`
	// kubeConfig is is kubeConfig represented in bytes
	KubeConfig  []byte `protobuf:"bytes,2,opt,name=kubeConfig,proto3" json:"kubeConfig,omitempty"`
	ClusterName string `protobuf:"bytes,3,opt,name=clusterName,proto3" json:"clusterName,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamContext) Descriptor deprecated added in v1.0.0

func (*StreamContext) Descriptor() ([]byte, []int)

Deprecated: Use StreamContext.ProtoReflect.Descriptor instead.

func (*StreamContext) GetClusterName added in v1.0.0

func (x *StreamContext) GetClusterName() string

func (*StreamContext) GetIsInteractivitySupported added in v1.0.0

func (x *StreamContext) GetIsInteractivitySupported() bool

func (*StreamContext) GetKubeConfig added in v1.0.0

func (x *StreamContext) GetKubeConfig() []byte

func (*StreamContext) ProtoMessage added in v1.0.0

func (*StreamContext) ProtoMessage()

func (*StreamContext) ProtoReflect added in v1.0.0

func (x *StreamContext) ProtoReflect() protoreflect.Message

func (*StreamContext) Reset added in v1.0.0

func (x *StreamContext) Reset()

func (*StreamContext) String added in v1.0.0

func (x *StreamContext) String() string

type StreamInput

type StreamInput struct {
	// Configs is a list of Source configurations specified by users.
	Configs []*Config
	// Context holds streaming context.
	Context StreamInputContext
}

StreamInput holds the input of the Stream function.

type StreamInputContext added in v1.0.0

type StreamInputContext struct {
	// IsInteractivitySupported is set to true only if communication platform supports interactive Messages.
	IsInteractivitySupported bool

	// KubeConfig is the path to kubectl configuration file.
	KubeConfig []byte

	// ClusterName is the name of underlying Kubernetes cluster which is provided by end user.
	ClusterName string
}

StreamInputContext holds streaming context.

type StreamOutput

type StreamOutput struct {
	// Output represents the streamed events. It is from start of plugin execution.
	// Deprecated: Use the Message field instead.
	//
	// Migration path:
	//
	//	Old approach:
	//	  out := source.StreamOutput{
	//	  	Output: make(chan []byte),
	//	  }
	//	  go func() {
	//	  	out.Output <- []byte("Ticker Event")
	//	  }()
	//	  return out, nil
	//
	//	New approach:
	//	  out := source.StreamOutput{
	//	  	Event: make(chan source.Event),
	//	  }
	//	  go func() {
	//	  	out.Event <- source.Event{
	//	  		Message: api.NewPlaintextMessage("Ticker Event", true),
	//	  	}
	//	  }()
	//	  return out, nil
	Output chan []byte
	// Event represents the streamed events with message,raw object, and analytics data. It is from start of plugin consumption.
	// You can construct a complex message.data or just use one of our helper functions:
	//   - api.NewCodeBlockMessage("body", true)
	//   - api.NewPlaintextMessage("body", true)
	Event chan Event
}

StreamOutput holds the output of the Stream function.

type StreamRequest

type StreamRequest struct {

	// Configs is a list of Source configurations specified by users.
	Configs []*Config `protobuf:"bytes,1,rep,name=configs,proto3" json:"configs,omitempty"`
	// context holds context stream.
	Context *StreamContext `protobuf:"bytes,3,opt,name=context,proto3" json:"context,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamRequest) Descriptor deprecated

func (*StreamRequest) Descriptor() ([]byte, []int)

Deprecated: Use StreamRequest.ProtoReflect.Descriptor instead.

func (*StreamRequest) GetConfigs

func (x *StreamRequest) GetConfigs() []*Config

func (*StreamRequest) GetContext added in v1.0.0

func (x *StreamRequest) GetContext() *StreamContext

func (*StreamRequest) ProtoMessage

func (*StreamRequest) ProtoMessage()

func (*StreamRequest) ProtoReflect

func (x *StreamRequest) ProtoReflect() protoreflect.Message

func (*StreamRequest) Reset

func (x *StreamRequest) Reset()

func (*StreamRequest) String

func (x *StreamRequest) String() string

type StreamResponse

type StreamResponse struct {

	// Output represents the streamed Source events. It is from start of Source execution.
	Output []byte `protobuf:"bytes,1,opt,name=output,proto3" json:"output,omitempty"`
	Event  []byte `protobuf:"bytes,2,opt,name=event,proto3" json:"event,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamResponse) Descriptor deprecated

func (*StreamResponse) Descriptor() ([]byte, []int)

Deprecated: Use StreamResponse.ProtoReflect.Descriptor instead.

func (*StreamResponse) GetEvent added in v1.0.0

func (x *StreamResponse) GetEvent() []byte

func (*StreamResponse) GetOutput

func (x *StreamResponse) GetOutput() []byte

func (*StreamResponse) ProtoMessage

func (*StreamResponse) ProtoMessage()

func (*StreamResponse) ProtoReflect

func (x *StreamResponse) ProtoReflect() protoreflect.Message

func (*StreamResponse) Reset

func (x *StreamResponse) Reset()

func (*StreamResponse) String

func (x *StreamResponse) String() string

type UnimplementedSourceServer

type UnimplementedSourceServer struct {
}

UnimplementedSourceServer must be embedded to have forward compatible implementations.

func (UnimplementedSourceServer) Metadata

func (UnimplementedSourceServer) Stream

type UnsafeSourceServer

type UnsafeSourceServer interface {
	// contains filtered or unexported methods
}

UnsafeSourceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to SourceServer will result in compilation errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL