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
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{}, }
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)
Serve starts the plugin server with the given implementation. This should be called from the plugin's main() function.
Example:
func main() {
plugin.Serve(&MyPlugin{})
}
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) (interface{}, 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) (interface{}, 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.