plugin

package
v29.0.0-...-a2903dc Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package plugin implements ignite plugin management. An ignite plugin is a binary which communicates with the ignite binary via RPC thanks to the github.com/hashicorp/go-plugin library.

Index

Constants

View Source
const (
	FlagTypeString      = v1.Flag_TYPE_FLAG_STRING_UNSPECIFIED
	FlagTypeInt         = v1.Flag_TYPE_FLAG_INT
	FlagTypeUint        = v1.Flag_TYPE_FLAG_UINT
	FlagTypeInt64       = v1.Flag_TYPE_FLAG_INT64
	FlagTypeUint64      = v1.Flag_TYPE_FLAG_UINT64
	FlagTypeBool        = v1.Flag_TYPE_FLAG_BOOL
	FlagTypeStringSlice = v1.Flag_TYPE_FLAG_STRING_SLICE
)

Flag type aliases.

Variables

View Source
var ErrAppChainNotFound = errors.New("blockchain app not found")

ErrAppChainNotFound indicates that the plugin command is not running inside a blockchain app.

PluginsPath holds the plugin cache directory.

Functions

func HandshakeConfig

func HandshakeConfig() hplugin.HandshakeConfig

HandshakeConfig are used to just do a basic handshake between a plugin and host. If the handshake fails, a user friendly error is shown. This prevents users from executing bad plugins or executing a plugin directory. It is a UX feature, not a security feature.

func NewGRPC

func NewGRPC(impl Interface) hplugin.Plugin

NewGRPC returns a new gRPC plugin that implements the interface over gRPC.

func Scaffold

func Scaffold(ctx context.Context, dir, appName string, sharedHost bool) (string, error)

Scaffold generates a plugin structure under dir/path.Base(appName).

func Update

func Update(plugins ...*Plugin) error

Update removes the cache directory of plugins and fetch them again.

Types

type APIOption

type APIOption func(*apiOptions)

APIOption defines options for the client API.

func WithChain

func WithChain(c Chainer) APIOption

WithChain configures the chain to use for the client API.

type AppInfo

type AppInfo struct {
	Description string `yaml:"description"`
	Path        string `yaml:"path"`
}

AppInfo is the structure of app info in app.ignite.yml file which only holds the description and the relative path of the app.

type AppsConfig

type AppsConfig struct {
	Version uint               `yaml:"version"`
	Apps    map[string]AppInfo `yaml:"apps"`
}

AppsConfig is the structure of app.ignite.yml file.

type ChainInfo

type ChainInfo = v1.ChainInfo

Type aliases for the current plugin version.

type Chainer

type Chainer interface {
	// AppPath returns the configured App's path.
	AppPath() string

	// ID returns the configured App's chain id.
	ID() (string, error)

	// ConfigPath returns the path to the App's config file.
	ConfigPath() string

	// RPCPublicAddress returns the configured App's rpc endpoint.
	RPCPublicAddress() (string, error)

	// Home returns the App's home dir.
	Home() (string, error)
}

type ClientAPI

type ClientAPI interface {
	// GetChainInfo returns basic info for the configured blockchain app.
	GetChainInfo(context.Context) (*ChainInfo, error)
}

ClientAPI defines the interface for plugins to get chain app code analysis info.

func NewClientAPI

func NewClientAPI(options ...APIOption) ClientAPI

NewClientAPI creates a new app ClientAPI.

type Command

type Command = v1.Command

Type aliases for the current plugin version.

type ExecutedCommand

type ExecutedCommand = v1.ExecutedCommand

Type aliases for the current plugin version.

type ExecutedHook

type ExecutedHook = v1.ExecutedHook

Type aliases for the current plugin version.

type Flag

type Flag = v1.Flag

Type aliases for the current plugin version.

type FlagType

type FlagType = v1.Flag_Type

Type aliases for the current plugin version.

type Hook

type Hook = v1.Hook

Type aliases for the current plugin version.

type Interface

type Interface interface {
	// Manifest declares the app's Command(s) and Hook(s).
	Manifest(context.Context) (*Manifest, error)

	// Execute will be invoked by ignite when an app Command is executed.
	// It is global for all commands declared in Manifest, if you have declared
	// multiple commands, use cmd.Path to distinguish them.
	// The clientAPI argument can be used by plugins to get chain app analysis info.
	Execute(context.Context, *ExecutedCommand, ClientAPI) error

	// ExecuteHookPre is invoked by ignite when a command specified by the Hook
	// path is invoked.
	// It is global for all hooks declared in Manifest, if you have declared
	// multiple hooks, use hook.Name to distinguish them.
	// The clientAPI argument can be used by plugins to get chain app analysis info.
	ExecuteHookPre(context.Context, *ExecutedHook, ClientAPI) error

	// ExecuteHookPost is invoked by ignite when a command specified by the hook
	// path is invoked.
	// It is global for all hooks declared in Manifest, if you have declared
	// multiple hooks, use hook.Name to distinguish them.
	// The clientAPI argument can be used by plugins to get chain app analysis info.
	ExecuteHookPost(context.Context, *ExecutedHook, ClientAPI) error

	// ExecuteHookCleanUp is invoked by ignite when a command specified by the
	// hook path is invoked. Unlike ExecuteHookPost, it is invoked regardless of
	// execution status of the command and hooks.
	// It is global for all hooks declared in Manifest, if you have declared
	// multiple hooks, use hook.Name to distinguish them.
	// The clientAPI argument can be used by plugins to get chain app analysis info.
	ExecuteHookCleanUp(context.Context, *ExecutedHook, ClientAPI) error
}

Interface defines the interface that all Ignite App must implement.

type Manifest

type Manifest = v1.Manifest

Type aliases for the current plugin version.

type Option

type Option func(*Plugin)

Option configures Plugin.

func CollectEvents

func CollectEvents(ev events.Bus) Option

CollectEvents collects events from the chain.

func RedirectStdout

func RedirectStdout(w io.Writer) Option

type Plugin

type Plugin struct {
	// Embed the plugin configuration.
	pluginsconfig.Plugin

	// Interface allows to communicate with the plugin via RPC.
	Interface Interface

	// If any error occurred during the plugin load, it's stored here.
	Error error
	// contains filtered or unexported fields
}

Plugin represents a ignite plugin.

func Load

func Load(ctx context.Context, plugins []pluginsconfig.Plugin, options ...Option) ([]*Plugin, error)

Load loads the plugins found in the chain config.

There's 2 kinds of plugins, local or remote. Local plugins have their path starting with a `/`, while remote plugins don't. Local plugins are useful for development purpose. Remote plugins require to be fetched first, in $HOME/.ignite/apps folder, then they are loaded from there.

If an error occurs during a plugin load, it's not returned but rather stored in the `Plugin.Error` field. This prevents the loading of other plugins to be interrupted.

func (*Plugin) KillClient

func (p *Plugin) KillClient()

KillClient kills the running plugin client.

func (Plugin) Manifest

func (p Plugin) Manifest() *Manifest

Manifest returns plugin's manigest. The manifest is available after the plugin has been loaded.

Directories

Path Synopsis
grpc
v1

Jump to

Keyboard shortcuts

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