sdk

package
v0.0.0-...-6dcdff4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: AGPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PluginContextMDKey = "plugin_context"
)

Variables

View Source
var ErrNoPluginContextError = errors.New("no plugin context in metadata")

Functions

func ClientPluginContextInterceptor

func ClientPluginContextInterceptor(
	ctx context.Context,
	method string,
	req, reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

func GRPCDialOptions

func GRPCDialOptions() []grpc.DialOption

func GRPCServerFactory

func GRPCServerFactory(opts []grpc.ServerOption) *grpc.Server

func RegisterResourcePlugin

func RegisterResourcePlugin[ClientT, DiscoveryT, InformerT any](
	p *Plugin,
	opts IResourcePluginOpts[ClientT, DiscoveryT, InformerT],
)

RegisterResourcePlugin registers a resource plugin with the given options. Resource plugins are plugins that manage resources, such as clouds, Kubernetes clusters, etc.

func ServerPluginContextInterceptor

func ServerPluginContextInterceptor(
	ctx context.Context,
	req interface{},
	_ *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (interface{}, error)

func UseClientPluginContext

func UseClientPluginContext(ctx context.Context) (context.Context, error)

UseClientPluginContext serializes the plugin context from the context and injects it into the gRPC metadata.

func UseServerPluginContext

func UseServerPluginContext(ctx context.Context) (context.Context, error)

UseServerPluginContext extracts the plugin context from the gRPC metadata and attaches it to the context.

Types

type IResourcePluginOpts

type IResourcePluginOpts[CT, DT, IT any] interface {
	HasDiscovery() (bool, error)
	GetClientFactory() factories.ResourceClientFactory[CT]
	GetResourcers() map[types.ResourceMeta]types.Resourcer[CT]
	GetDynamicResourcers() map[string]types.DynamicResourcer[CT]
	HasDynamicResourcers() bool
	GetResourceGroups() []types.ResourceGroup
	GetDiscoveryClientFactory() factories.ResourceDiscoveryClientFactory[DT]
	GetDiscoveryFunc() func(*pkgtypes.PluginContext, *DT) ([]types.ResourceMeta, error)
	HasInformer() bool
	GetInformerOpts() *types.InformerOptions[CT, IT]
	GetLayoutOpts() *types.LayoutOpts
	GetLoadConnectionFunc() func(*pkgtypes.PluginContext) ([]pkgtypes.Connection, error)
	GetLoadConnectionNamespacesFunc() func(*pkgtypes.PluginContext, *CT) ([]string, error)
	GetCheckConnectionFunc() func(*pkgtypes.PluginContext, *pkgtypes.Connection, *CT) (pkgtypes.ConnectionStatus, error)
	GetResourceDefinitions() map[string]types.ResourceDefinition
	GetDefaultResourceDefinition() types.ResourceDefinition
}

type Plugin

type Plugin struct {
	// settingsProvider is the settings provider for the plugin.
	SettingsProvider pkgsettings.Provider

	Logger    *zap.SugaredLogger
	HCLLogger hclog.Logger
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(opts PluginOpts) *Plugin

NewPlugin creates a new plugin with the given configuration. This should be instantiated within your main function for your plugin and passed to the Register* functions to add capabilities to the plugin.

func (*Plugin) GetMeta

func (p *Plugin) GetMeta() config.PluginMeta

func (*Plugin) GetPluginID

func (p *Plugin) GetPluginID() string

func (*Plugin) GetPluginMap

func (p *Plugin) GetPluginMap() map[string]plugin.Plugin

GetPluginMap returns the plugin map for the plugin based on the capabilities that have been registered.

func (*Plugin) RegisterCapability

func (p *Plugin) RegisterCapability(capability string, registration plugin.Plugin)

registerCapability registers a plugin capability with the plugin system.

func (*Plugin) Serve

func (p *Plugin) Serve()

Serve begins serving the plugin over the given RPC server. This should be called after all capabilities have been registered.

type PluginOpts

type PluginOpts struct {
	// ID is the unique identifier for the plugin
	ID string

	// Settings is a list of settings to be used by the plugin
	Settings []pkgsettings.Setting

	// Debug is the debug mode for the plugin
	Debug bool
}

PluginOpts is the options for creating a new plugin.

type ResourcePluginOpts

type ResourcePluginOpts[ClientT, DiscoveryClientT, InformerT any] struct {
	// LoadConnectionFunc is a function that will be called to load the possible connections
	// for the resource plugin. This should be used to load the possible connections available based on either
	// settings within the ide (by pulling it off of the plugin context) or by using system defaults.
	//
	// TODO - move this and the client factory to the parent plugin opts so that multiple capabilities can
	// use the same client and connection loaders
	LoadConnectionFunc           func(*pkgtypes.PluginContext) ([]pkgtypes.Connection, error)
	LoadConnectionNamespacesFunc func(*pkgtypes.PluginContext, *ClientT) ([]string, error)
	CheckConnectionFunc          func(*pkgtypes.PluginContext, *pkgtypes.Connection, *ClientT) (pkgtypes.ConnectionStatus, error)

	// ClientFactory is the factory for creating a new resource client to interact with a backend.
	//
	// TODO - move this and the load connection func to the parent plugin opts so that multiple capabilities can
	// use the same client
	ClientFactory factories.ResourceClientFactory[ClientT]

	// DiscoveryClientFactory is the factory for creating a new discovery client to interact with a backend.
	DiscoveryClientFactory factories.ResourceDiscoveryClientFactory[DiscoveryClientT]

	// DiscoveryFunc is the function that will be called to discover resources.
	DiscoveryFunc func(*pkgtypes.PluginContext, *DiscoveryClientT) ([]types.ResourceMeta, error)

	// Resourcers is a map of resource metadata to resourcers that the plugin will manage.
	Resourcers map[types.ResourceMeta]types.Resourcer[ClientT]

	// DynamicResourcers is a map of dynamic resourcers to use as fallbacks when a registered resourcer is not available.
	// Wilcard patterns are supported in the dynamic resourcer key.
	DynamicResourcers map[string]types.DynamicResourcer[ClientT]

	// ResourceGroups is an optional array of resource groups to provide more details about the groups that
	// contain the resources. Is is highly recommended to provide this information to enrich the UI.
	ResourceGroups []types.ResourceGroup

	// ResourceDefinitions is a map of resource names to their definitions, which includes various
	// metadata about how to display the resources in the UI.
	ResourceDefinitions map[string]types.ResourceDefinition

	// DefaultResourceDefinition is the default resource definition to use for resources that do not have
	// a specific definition.
	DefaultResourceDefinition types.ResourceDefinition

	// InformerOpts allows for an additional set of custom options for setting up informers on the
	// resource backend.
	InformerOpts *types.InformerOptions[ClientT, InformerT]

	// LayoutOpts allows for customizing the layout within the UI
	LayoutOpts *types.LayoutOpts
}

DynamicResourcePluginOpts is a set of options for configuring a dynamic resource plugin. A dynamic resource plugin must consist of a discovery client factory, a discovery function, a client factory, and a set of resourcers that the plugin will manage.

func (ResourcePluginOpts[CT, DT, IT]) GetCheckConnectionFunc

func (opts ResourcePluginOpts[CT, DT, IT]) GetCheckConnectionFunc() func(*pkgtypes.PluginContext, *pkgtypes.Connection, *CT) (
	pkgtypes.ConnectionStatus,
	error,
)

func (ResourcePluginOpts[CT, DT, IT]) GetClientFactory

func (opts ResourcePluginOpts[CT, DT, IT]) GetClientFactory() factories.ResourceClientFactory[CT]

func (ResourcePluginOpts[CT, DT, IT]) GetDefaultResourceDefinition

func (opts ResourcePluginOpts[CT, DT, IT]) GetDefaultResourceDefinition() types.ResourceDefinition

func (ResourcePluginOpts[CT, DT, IT]) GetDiscoveryClientFactory

func (opts ResourcePluginOpts[CT, DT, IT]) GetDiscoveryClientFactory() factories.ResourceDiscoveryClientFactory[DT]

func (ResourcePluginOpts[CT, DT, IT]) GetDiscoveryFunc

func (opts ResourcePluginOpts[CT, DT, IT]) GetDiscoveryFunc() func(*pkgtypes.PluginContext, *DT) (
	[]types.ResourceMeta,
	error,
)

func (ResourcePluginOpts[CT, DT, IT]) GetDynamicResourcers

func (opts ResourcePluginOpts[CT, DT, IT]) GetDynamicResourcers() map[string]types.DynamicResourcer[CT]

func (ResourcePluginOpts[CT, DT, IT]) GetInformerOpts

func (opts ResourcePluginOpts[CT, DT, IT]) GetInformerOpts() *types.InformerOptions[CT, IT]

func (ResourcePluginOpts[CT, DT, IT]) GetLayoutOpts

func (opts ResourcePluginOpts[CT, DT, IT]) GetLayoutOpts() *types.LayoutOpts

func (ResourcePluginOpts[ClientT, DiscoveryClientT, InformerT]) GetLoadConnectionFunc

func (opts ResourcePluginOpts[ClientT, DiscoveryClientT, InformerT]) GetLoadConnectionFunc() func(*pkgtypes.PluginContext) (
	[]pkgtypes.Connection,
	error,
)

func (ResourcePluginOpts[ClientT, DiscoveryClientT, InformerT]) GetLoadConnectionNamespacesFunc

func (opts ResourcePluginOpts[ClientT, DiscoveryClientT, InformerT]) GetLoadConnectionNamespacesFunc() func(*pkgtypes.PluginContext, *ClientT) (
	[]string,
	error,
)

func (ResourcePluginOpts[CT, DT, IT]) GetResourceDefinitions

func (opts ResourcePluginOpts[CT, DT, IT]) GetResourceDefinitions() map[string]types.ResourceDefinition

func (ResourcePluginOpts[CT, DT, IT]) GetResourceGroups

func (opts ResourcePluginOpts[CT, DT, IT]) GetResourceGroups() []types.ResourceGroup

func (ResourcePluginOpts[CT, DT, IT]) GetResourcers

func (opts ResourcePluginOpts[CT, DT, IT]) GetResourcers() map[types.ResourceMeta]types.Resourcer[CT]

func (ResourcePluginOpts[CT, DT, IT]) HasDiscovery

func (opts ResourcePluginOpts[CT, DT, IT]) HasDiscovery() (bool, error)

func (ResourcePluginOpts[CT, DT, IT]) HasDynamicResourcers

func (opts ResourcePluginOpts[CT, DT, IT]) HasDynamicResourcers() bool

func (ResourcePluginOpts[CT, DT, IT]) HasInformer

func (opts ResourcePluginOpts[CT, DT, IT]) HasInformer() bool

Jump to

Keyboard shortcuts

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