Documentation
¶
Overview ¶
Package plugin provides shared types and helpers for p5 plugin authors. Plugin authors should import this package and implement the AuthPlugin interface.
This package is the canonical source for shared plugin types used by both the p5 host and external plugin implementations.
Index ¶
- Variables
- func Serve(impl AuthPlugin)
- type AuthPlugin
- type AuthPluginGRPC
- type AuthenticateRequest
- type AuthenticateResponse
- type GRPCClient
- type GRPCServer
- type ImportHelperGRPCClient
- type ImportHelperGRPCServer
- type ImportHelperPlugin
- type ImportHelperPluginGRPC
- type ImportSuggestion
- type ImportSuggestionsRequest
- type ImportSuggestionsResponse
- type OpenAction
- type OpenActionType
- type OpenResourceRequest
- type OpenResourceResponse
- type ResourceOpenerGRPCClient
- type ResourceOpenerGRPCServer
- type ResourceOpenerPlugin
- type ResourceOpenerPluginGRPC
- type SupportedOpenTypesRequest
- type SupportedOpenTypesResponse
Constants ¶
This section is empty.
Variables ¶
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "P5_PLUGIN",
MagicCookieValue: "v0",
}
Handshake is the handshake config for plugins. Both the host and plugin must agree on this configuration. This is the canonical definition - do not duplicate elsewhere.
var PluginMap = map[string]goplugin.Plugin{ "auth": &AuthPluginGRPC{}, "import_helper": &ImportHelperPluginGRPC{}, "resource_opener": &ResourceOpenerPluginGRPC{}, }
PluginMap is the map of plugins we can dispense. This is the canonical definition used by both host and plugins.
Functions ¶
func Serve ¶
func Serve(impl AuthPlugin)
Types ¶
type AuthPlugin ¶
type AuthPlugin interface {
// Authenticate performs authentication and returns environment variables
Authenticate(ctx context.Context, req *AuthenticateRequest) (*AuthenticateResponse, error)
}
AuthPlugin is the interface that plugins must implement. This is the canonical definition used by both host and plugins.
type AuthPluginGRPC ¶
type AuthPluginGRPC struct {
goplugin.Plugin
// Impl is the actual plugin implementation
Impl AuthPlugin
}
AuthPluginGRPC is the implementation of goplugin.GRPCPlugin for AuthPlugin
func (*AuthPluginGRPC) GRPCClient ¶
func (p *AuthPluginGRPC) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (any, error)
GRPCClient returns the gRPC client (host side)
func (*AuthPluginGRPC) GRPCServer ¶
func (p *AuthPluginGRPC) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error
GRPCServer registers the gRPC server (plugin side)
type AuthenticateRequest ¶
type AuthenticateRequest = proto.AuthenticateRequest
AuthenticateRequest is the request sent to the Authenticate RPC
type AuthenticateResponse ¶
type AuthenticateResponse = proto.AuthenticateResponse
AuthenticateResponse is the response from the Authenticate RPC
func ErrorResponse ¶
func ErrorResponse(format string, args ...any) *AuthenticateResponse
ErrorResponse creates an error authentication response with format string support. This helper can be used by both builtin and external plugins.
func SuccessResponse ¶
func SuccessResponse(env map[string]string, ttlSeconds int32) *AuthenticateResponse
SuccessResponse creates a successful authentication response. This helper can be used by both builtin and external plugins.
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
GRPCClient is the client-side implementation of AuthPlugin over gRPC
func (*GRPCClient) Authenticate ¶
func (c *GRPCClient) Authenticate(ctx context.Context, req *AuthenticateRequest) (*AuthenticateResponse, error)
Authenticate calls the plugin's Authenticate RPC
type GRPCServer ¶
type GRPCServer struct {
proto.UnimplementedAuthPluginServer
Impl AuthPlugin
}
GRPCServer is the server-side implementation that wraps the actual plugin
func (*GRPCServer) Authenticate ¶
func (s *GRPCServer) Authenticate(ctx context.Context, req *AuthenticateRequest) (*AuthenticateResponse, error)
Authenticate handles the Authenticate RPC
type ImportHelperGRPCClient ¶
type ImportHelperGRPCClient struct {
// contains filtered or unexported fields
}
ImportHelperGRPCClient is the client-side implementation of ImportHelperPlugin over gRPC
func (*ImportHelperGRPCClient) GetImportSuggestions ¶
func (c *ImportHelperGRPCClient) GetImportSuggestions(ctx context.Context, req *ImportSuggestionsRequest) (*ImportSuggestionsResponse, error)
GetImportSuggestions calls the plugin's GetImportSuggestions RPC
type ImportHelperGRPCServer ¶
type ImportHelperGRPCServer struct {
proto.UnimplementedImportHelperPluginServer
Impl ImportHelperPlugin
}
ImportHelperGRPCServer is the server-side implementation that wraps the actual plugin
func (*ImportHelperGRPCServer) GetImportSuggestions ¶
func (s *ImportHelperGRPCServer) GetImportSuggestions(ctx context.Context, req *ImportSuggestionsRequest) (*ImportSuggestionsResponse, error)
GetImportSuggestions handles the GetImportSuggestions RPC
type ImportHelperPlugin ¶
type ImportHelperPlugin interface {
// GetImportSuggestions returns import ID suggestions for a resource.
// Plugins should return CanProvide: false if they don't handle the resource type.
GetImportSuggestions(ctx context.Context, req *ImportSuggestionsRequest) (*ImportSuggestionsResponse, error)
}
ImportHelperPlugin is an optional interface that plugins can implement to provide import ID suggestions for resources.
type ImportHelperPluginGRPC ¶
type ImportHelperPluginGRPC struct {
goplugin.Plugin
// Impl is the actual plugin implementation
Impl ImportHelperPlugin
}
ImportHelperPluginGRPC is the implementation of goplugin.GRPCPlugin for ImportHelperPlugin
func (*ImportHelperPluginGRPC) GRPCClient ¶
func (p *ImportHelperPluginGRPC) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (any, error)
GRPCClient returns the gRPC client (host side)
func (*ImportHelperPluginGRPC) GRPCServer ¶
func (p *ImportHelperPluginGRPC) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error
GRPCServer registers the gRPC server (plugin side)
type ImportSuggestion ¶
type ImportSuggestion = proto.ImportSuggestion
ImportSuggestion represents a single import suggestion
func NewImportSuggestion ¶
func NewImportSuggestion(id, label, description string) *ImportSuggestion
NewImportSuggestion creates a new import suggestion.
type ImportSuggestionsRequest ¶
type ImportSuggestionsRequest = proto.ImportSuggestionsRequest
ImportSuggestionsRequest is the request sent to the GetImportSuggestions RPC
type ImportSuggestionsResponse ¶
type ImportSuggestionsResponse = proto.ImportSuggestionsResponse
ImportSuggestionsResponse is the response from the GetImportSuggestions RPC
func ImportSuggestionsError ¶
func ImportSuggestionsError(format string, args ...any) *ImportSuggestionsResponse
ImportSuggestionsError creates an error import suggestions response.
func ImportSuggestionsNotSupported ¶
func ImportSuggestionsNotSupported() *ImportSuggestionsResponse
ImportSuggestionsNotSupported returns a response indicating the plugin doesn't handle this resource type.
func ImportSuggestionsSuccess ¶
func ImportSuggestionsSuccess(suggestions []*ImportSuggestion) *ImportSuggestionsResponse
ImportSuggestionsSuccess creates a successful import suggestions response.
type OpenAction ¶ added in v0.3.0
type OpenAction = proto.OpenAction
OpenAction represents an action to open a resource
type OpenActionType ¶ added in v0.3.0
type OpenActionType = proto.OpenActionType
OpenActionType is the type of open action
type OpenResourceRequest ¶ added in v0.3.0
type OpenResourceRequest = proto.OpenResourceRequest
OpenResourceRequest is the request sent to the OpenResource RPC
type OpenResourceResponse ¶ added in v0.3.0
type OpenResourceResponse = proto.OpenResourceResponse
OpenResourceResponse is the response from the OpenResource RPC
func OpenBrowserResponse ¶ added in v0.3.0
func OpenBrowserResponse(url string) *OpenResourceResponse
OpenBrowserResponse creates a response to open a URL in the browser.
func OpenError ¶ added in v0.3.0
func OpenError(format string, args ...any) *OpenResourceResponse
OpenError creates an error response for resource opening.
func OpenExecResponse ¶ added in v0.3.0
func OpenExecResponse(cmd string, args []string, env map[string]string) *OpenResourceResponse
OpenExecResponse creates a response to launch an alternate screen program.
func OpenNotSupported ¶ added in v0.3.0
func OpenNotSupported() *OpenResourceResponse
OpenNotSupported returns a response indicating the plugin doesn't handle this resource type.
type ResourceOpenerGRPCClient ¶ added in v0.3.0
type ResourceOpenerGRPCClient struct {
// contains filtered or unexported fields
}
ResourceOpenerGRPCClient is the client-side implementation of ResourceOpenerPlugin over gRPC
func (*ResourceOpenerGRPCClient) GetSupportedOpenTypes ¶ added in v0.3.0
func (c *ResourceOpenerGRPCClient) GetSupportedOpenTypes(ctx context.Context, req *SupportedOpenTypesRequest) (*SupportedOpenTypesResponse, error)
GetSupportedOpenTypes calls the plugin's GetSupportedOpenTypes RPC
func (*ResourceOpenerGRPCClient) OpenResource ¶ added in v0.3.0
func (c *ResourceOpenerGRPCClient) OpenResource(ctx context.Context, req *OpenResourceRequest) (*OpenResourceResponse, error)
OpenResource calls the plugin's OpenResource RPC
type ResourceOpenerGRPCServer ¶ added in v0.3.0
type ResourceOpenerGRPCServer struct {
proto.UnimplementedResourceOpenerPluginServer
Impl ResourceOpenerPlugin
}
ResourceOpenerGRPCServer is the server-side implementation that wraps the actual plugin
func (*ResourceOpenerGRPCServer) GetSupportedOpenTypes ¶ added in v0.3.0
func (s *ResourceOpenerGRPCServer) GetSupportedOpenTypes(ctx context.Context, req *SupportedOpenTypesRequest) (*SupportedOpenTypesResponse, error)
GetSupportedOpenTypes handles the GetSupportedOpenTypes RPC
func (*ResourceOpenerGRPCServer) OpenResource ¶ added in v0.3.0
func (s *ResourceOpenerGRPCServer) OpenResource(ctx context.Context, req *OpenResourceRequest) (*OpenResourceResponse, error)
OpenResource handles the OpenResource RPC
type ResourceOpenerPlugin ¶ added in v0.3.0
type ResourceOpenerPlugin interface {
// GetSupportedOpenTypes returns regex patterns for resource types this plugin can open.
GetSupportedOpenTypes(ctx context.Context, req *SupportedOpenTypesRequest) (*SupportedOpenTypesResponse, error)
// OpenResource returns the action to open a specific resource.
// Plugins should return CanOpen: false if they don't handle this resource type.
OpenResource(ctx context.Context, req *OpenResourceRequest) (*OpenResourceResponse, error)
}
ResourceOpenerPlugin is an optional interface that plugins can implement to provide resource opening capabilities (browser URLs or alternate screen programs).
type ResourceOpenerPluginGRPC ¶ added in v0.3.0
type ResourceOpenerPluginGRPC struct {
goplugin.Plugin
// Impl is the actual plugin implementation
Impl ResourceOpenerPlugin
}
ResourceOpenerPluginGRPC is the implementation of goplugin.GRPCPlugin for ResourceOpenerPlugin
func (*ResourceOpenerPluginGRPC) GRPCClient ¶ added in v0.3.0
func (p *ResourceOpenerPluginGRPC) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (any, error)
GRPCClient returns the gRPC client (host side)
func (*ResourceOpenerPluginGRPC) GRPCServer ¶ added in v0.3.0
func (p *ResourceOpenerPluginGRPC) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error
GRPCServer registers the gRPC server (plugin side)
type SupportedOpenTypesRequest ¶ added in v0.3.0
type SupportedOpenTypesRequest = proto.SupportedOpenTypesRequest
SupportedOpenTypesRequest is the request sent to the GetSupportedOpenTypes RPC
type SupportedOpenTypesResponse ¶ added in v0.3.0
type SupportedOpenTypesResponse = proto.SupportedOpenTypesResponse
SupportedOpenTypesResponse is the response from the GetSupportedOpenTypes RPC
func SupportedOpenTypesPatterns ¶ added in v0.3.0
func SupportedOpenTypesPatterns(patterns ...string) *SupportedOpenTypesResponse
SupportedOpenTypesPatterns creates a response with supported resource type patterns.