sdk

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: AGPL-3.0 Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MDKeyRequestID       = "omniview-request-id"
	MDKeyRequesterID     = "omniview-requester-id"
	MDKeyConnectionID    = "omniview-connection-id"
	MDKeyResourceKey     = "omniview-resource-key"
	MDKeyProtocolVersion = "omniview-protocol-version"
)

Individual metadata keys for the new format.

Variables

This section is empty.

Functions

func CleanupDevInfo

func CleanupDevInfo(pluginID string) error

CleanupDevInfo removes the .devinfo file for the given plugin ID. This should be called when the plugin process is shutting down.

func ClientPluginContextInterceptor

func ClientPluginContextInterceptor(
	ctx context.Context,
	method string,
	req, reply any,
	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 NewClientDiscoveryProvider

func NewClientDiscoveryProvider[DiscoveryClientT any](
	createClient func(*pkgtypes.PluginContext) (*DiscoveryClientT, error),
	stopClient func(*pkgtypes.PluginContext, *DiscoveryClientT) error,
	syncer func(*pkgtypes.PluginContext, *DiscoveryClientT) ([]types.ResourceMeta, error),
) types.DiscoveryProvider

NewClientDiscoveryProvider creates a DiscoveryProvider from client lifecycle functions and a syncer. createClient is required. stopClient is optional (nil = no-op).

func RegisterResourcePlugin

func RegisterResourcePlugin[ClientT any](
	p *Plugin,
	opts ResourcePluginOpts[ClientT],
)

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

func UseClientPluginContext

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

UseClientPluginContext serializes the plugin context and injects it into gRPC metadata using both the new individual keys and the legacy JSON blob for backward compatibility with older plugin binaries.

func WriteDevInfo

func WriteDevInfo(pluginID, version, handshakeLine string, vitePort int) error

WriteDevInfo writes a .devinfo file for the running plugin process. It parses the go-plugin handshake line from stdout to extract the network address, then writes the file atomically.

The handshake line format is:

CORE-PROTOCOL-VERSION|APP-PROTOCOL-VERSION|NETWORK-TYPE|NETWORK-ADDR|PROTOCOL

Example: 1|1|tcp|127.0.0.1:42367|grpc

func WriteDevInfoFromAddr

func WriteDevInfoFromAddr(pluginID, version string, addr net.Addr, vitePort int) error

WriteDevInfoFromAddr writes a .devinfo file using a pre-known address (for cases where the handshake line is not directly available).

Types

type ConnectionEvent

type ConnectionEvent struct {
	// Type is the type of change that happened to the connection data
	// TODO: change to enum
	Type string // 'SYNC', 'CREATE', 'DELETE'

	// Data is the series of connection data associated with the update event
	Data []pkgtypes.Connection
}

ConnectionEvent is a change of some kind to a connection. This could be the result of a new credential being added, an existing one updating, or possibly getting deleted.

It is recommended that if it is impractical to distinguish events for individual connections (such as a new connection being created not being able to be detected), a 'SYNC' event with all of the connections available should be sent to provided a minimum amount of feedback.

type ConnectionManager

type ConnectionManager interface {
	// ListConnections should list all of the connections available from the plugin
	ListConnections(ctx pkgtypes.PluginContext) ([]pkgtypes.Connection, error)

	// GetConnection should take a unique ID and return the connection data for that connection
	GetConnection(ctx pkgtypes.PluginContext, id string) (pkgtypes.Connection, error)

	// UpdateConnections should take a map of change data, with the keys being unique IDs of connetion and the values being new connection
	// data, and return the map of new, full data
	UpdateConnections(
		ctx pkgtypes.PluginContext,
		data map[string]pkgtypes.Connection,
	) (map[string]pkgtypes.Connection, error)

	// DeleteConnections should take an array of connection ID's to delete, and return a map of connection ID to states.
	DeleteConnections(ctx pkgtypes.PluginContext, ids []string) map[string]error

	// SubscribeConnections should stream changes to underlying connection data so that the IDE can respond in real time to changes
	// to connections. This function should initiate any watchers (such as a inotify watcher on credential files) to submit to the passed
	// in channel.
	SubscribeConnections(ctx pkgtypes.PluginContext, reciever chan []ConnectionEvent) error
}

ConnectionManager is the interface the plugin must satisfy in order to provide connection information back to the IDE.

TODO: figure out how we want to manage creating connections themselves.

type DevInfo

type DevInfo struct {
	PID             int       `json:"pid"`
	Protocol        string    `json:"protocol"`
	ProtocolVersion int       `json:"protocolVersion"`
	Addr            string    `json:"addr"`
	VitePort        int       `json:"vitePort,omitempty"`
	PluginID        string    `json:"pluginId"`
	Version         string    `json:"version"`
	StartedAt       time.Time `json:"startedAt"`
}

DevInfo represents the contents of a .devinfo file that advertises a running plugin process to the IDE.

func ReadDevInfo

func ReadDevInfo(pluginID string) (*DevInfo, error)

ReadDevInfo reads and parses a .devinfo file.

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.

The lifecycle service is auto-registered before serving — it reads capabilities from the plugin map so plugin authors never need to touch it.

When the OMNIVIEW_DEV environment variable is set to "1", the function will:

  • Intercept the go-plugin handshake line from stdout to capture the listen address
  • Write a .devinfo file so the IDE can connect via ReattachConfig
  • Register a signal handler to clean up .devinfo on graceful shutdown

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 any] struct {
	// LoadConnectionFunc is a function that will be called to load the possible connections
	// for the resource plugin.
	LoadConnectionFunc           func(*pkgtypes.PluginContext) ([]pkgtypes.Connection, error)
	LoadConnectionNamespacesFunc func(*pkgtypes.PluginContext, *ClientT) ([]string, error)
	CheckConnectionFunc          func(*pkgtypes.PluginContext, *pkgtypes.Connection, *ClientT) (pkgtypes.ConnectionStatus, error)
	WatchConnectionsFunc         func(*pkgtypes.PluginContext) (chan []pkgtypes.Connection, error)

	// CreateClient creates a new client for a connection. Required.
	CreateClient func(*pkgtypes.PluginContext) (*ClientT, error)
	// RefreshClient refreshes an existing client (e.g., rotate credentials). Optional; if nil, not called.
	RefreshClient func(*pkgtypes.PluginContext, *ClientT) error
	// StartClient is called when a connection starts. Optional; if nil, no-op.
	StartClient func(*pkgtypes.PluginContext, *ClientT) error
	// StopClient is called when a connection stops. Optional; if nil, no-op.
	StopClient func(*pkgtypes.PluginContext, *ClientT) error

	// DiscoveryProvider handles dynamic resource type discovery. If nil, a static type manager is used.
	DiscoveryProvider types.DiscoveryProvider

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

	// PatternResourcers is a map of pattern resourcers to use as fallbacks when a registered resourcer is not available.
	PatternResourcers map[string]types.Resourcer[ClientT]

	// ResourceGroups is an optional array of resource groups to provide more details about the groups.
	ResourceGroups []types.ResourceGroup

	// ResourceDefinitions is a map of resource names to their definitions.
	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

	// SyncPolicies maps resource keys to their sync policy.
	// Resources not in this map default to SyncOnConnect.
	SyncPolicies map[string]types.InformerSyncPolicy

	// CreateInformerFunc creates an InformerHandle for a given connection client. If nil, informers are disabled.
	CreateInformerFunc types.CreateInformerHandleFunc[ClientT]

	// SchemaFunc is an optional connection-level schema provider. When set, it is called
	// with the connection client to return editor schemas (e.g., OpenAPI specs from a K8s cluster).
	// These are merged with any per-resourcer schemas from SchemaResourcer implementations.
	SchemaFunc func(*pkgtypes.PluginContext, *ClientT) ([]types.EditorSchema, error)

	// ErrorClassifier is an optional function that classifies raw errors from
	// resource operations into structured ResourceOperationError values.
	// When set, the gRPC server calls it before falling back to a generic INTERNAL error.
	ErrorClassifier func(error) error

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

ResourcePluginOpts is a set of options for configuring a resource plugin.

Jump to

Keyboard shortcuts

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