plugins

package
v1.19.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PluginDev   = false
	PluginsPath string
)

dev mode vars

Functions

func AddEntryToPluginManifest added in v1.11.1

func AddEntryToPluginManifest(ctx context.Context, config config.IConfig, fs afero.Fs, entry Plugin) error

AddEntryToPluginManifest update plugins.toml with a new release version

func CleanupAllClients added in v1.8.1

func CleanupAllClients()

CleanupAllClients tears down and disconnects all "managed" plugin clients

func ExtractLocalArchive added in v1.11.1

func ExtractLocalArchive(ctx context.Context, config config.IConfig, source string) error

ExtractLocalArchive extracts the local tarball body

func ExtractStdoutArchive added in v1.11.1

func ExtractStdoutArchive(ctx context.Context, config config.IConfig) error

ExtractStdoutArchive extracts the archive from stdout

func FetchAndExtractRemoteArchive added in v1.11.1

func FetchAndExtractRemoteArchive(ctx context.Context, config config.IConfig, url string) error

FetchAndExtractRemoteArchive fetches and extracts the remote tarball body

func FetchRemoteResource

func FetchRemoteResource(url string) ([]byte, error)

FetchRemoteResource returns the remote resource body

func GetBinaryExtension added in v1.8.6

func GetBinaryExtension() string

GetBinaryExtension returns the appropriate file extension for plugin binary

func IsPluginCommand added in v1.8.2

func IsPluginCommand(cmd *cobra.Command) bool

IsPluginCommand returns true if the command invoked is for a plugin false otherwise

func RefreshPluginManifest

func RefreshPluginManifest(ctx context.Context, config config.IConfig, fs afero.Fs, baseURL string) error

RefreshPluginManifest refreshes the plugin manifest

Types

type CLIPluginGRPC added in v1.13.8

type CLIPluginGRPC struct {
	// GRPCPlugin must still implement the Plugin interface
	hcplugin.Plugin
	// Concrete implementation, written in Go. This is only used for plugins
	// that are written in Go.
	Impl DispatcherGRPC
}

CLIPluginGRPC is the implementation of plugin.GRPCPlugin so we can serve/consume this.

func (*CLIPluginGRPC) GRPCClient added in v1.13.8

func (p *CLIPluginGRPC) GRPCClient(ctx context.Context, broker *hcplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient creates the GRPC client.

func (*CLIPluginGRPC) GRPCServer added in v1.13.8

func (p *CLIPluginGRPC) GRPCServer(broker *hcplugin.GRPCBroker, s *grpc.Server) error

GRPCServer creates the GRPC server.

type CLIPluginV1

type CLIPluginV1 struct {
	// Impl Injection
	Impl Dispatcher
}

CLIPluginV1 is the implementation of plugin.Plugin so we can serve/consume this

This has two methods: Server must return an RPC server for this plugin type. We construct a DispatcherRPCServer for this.

Client must return an implementation of our interface that communicates over an RPC client. We return a PluginClient for this.

Ignore MuxBroker. That is used to create more multiplexed streams on a plugin connection and is a more advanced use case.

func (CLIPluginV1) Client

func (CLIPluginV1) Client(b *hcplugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client returns the rpc client

func (*CLIPluginV1) Server

func (p *CLIPluginV1) Server(*hcplugin.MuxBroker) (interface{}, error)

Server returns the rpc server

type Dispatcher

type Dispatcher interface {
	RunCommand(args []string) (string, error)
}

Dispatcher is the interface that we're exposing as a plugin. It is named so because it is able to dispatch a command from the main CLI to the plugin

type DispatcherGRPC added in v1.13.8

type DispatcherGRPC interface {
	RunCommand(additionalInfo *proto.AdditionalInfo, args []string) error
}

DispatcherGRPC is the interface that's implemented by the plugin and used by the host.

type DispatcherRPCServer

type DispatcherRPCServer struct {
	// This is the real implementation
	Impl Dispatcher
}

DispatcherRPCServer is the RPC server that a plugin talks to, conforming to the requirements of net/rpc

func (*DispatcherRPCServer) RunCommand

func (s *DispatcherRPCServer) RunCommand(args []string, resp *string) error

RunCommand is the main entry command that can be invoked remotely by the Stripe CLI it is defined here on the plugin's RPC server then we call the internal RunCommand method finally, we then return the response back via the DispatcherRPC interface that the CLI is interacting with

type GRPCClient added in v1.13.8

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient is an implementation of the gRPC client that talks over gRPC.

func (*GRPCClient) RunCommand added in v1.13.8

func (m *GRPCClient) RunCommand(additionalInfo *proto.AdditionalInfo, args []string) error

RunCommand calls the RPC.

type GRPCServer added in v1.13.8

type GRPCServer struct {
	proto.MainServer
	// This is the real implementation
	Impl DispatcherGRPC
}

GRPCServer is the gRPC server that GRPCClient talks to.

func (*GRPCServer) RunCommand added in v1.13.8

RunCommand takes the incoming RPC request and calls the real implementation.

type Plugin

type Plugin struct {
	Shortname        string    `toml:"Shortname"`
	Shortdesc        string    `toml:"Shortdesc"`
	Binary           string    `toml:"Binary"`
	Releases         []Release `toml:"Release"`
	MagicCookieValue string    `toml:"MagicCookieValue"`
}

Plugin contains the plugin properties

func LookUpPlugin

func LookUpPlugin(ctx context.Context, config config.IConfig, fs afero.Fs, pluginName string) (Plugin, error)

LookUpPlugin returns the matching plugin object

func (*Plugin) Install

func (p *Plugin) Install(ctx context.Context, cfg config.IConfig, fs afero.Fs, version string, baseURL string) error

Install installs the plugin of the given version

func (*Plugin) LookUpLatestVersion

func (p *Plugin) LookUpLatestVersion() string

LookUpLatestVersion gets latest CLI version note: assumes versions are listed in asc order

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context, config *config.Config, fs afero.Fs, args []string) error

Run boots up the binary and then sends the command to it via RPC

func (*Plugin) Uninstall added in v1.9.0

func (p *Plugin) Uninstall(ctx context.Context, config config.IConfig, fs afero.Fs) error

Uninstall removes a plugin from the disk and from the config's installed plugins list

type PluginClient

type PluginClient struct {
	// contains filtered or unexported fields
}

PluginClient is an implementation that talks over RPC

func (*PluginClient) RunCommand

func (g *PluginClient) RunCommand(args []string) (string, error)

RunCommand is the main plugin command that can be invoked remotely by the Stripe CLI we expose the command here for the CLI to call, which then calls the method directly on the RPCServer

type PluginList

type PluginList struct {
	Plugins []Plugin `toml:"Plugin"`
}

PluginList contains a list of plugins

func GetPluginList

func GetPluginList(ctx context.Context, config config.IConfig, fs afero.Fs) (PluginList, error)

GetPluginList builds a list of allowed plugins to be installed and run by the CLI

type Release

type Release struct {
	Arch    string `toml:"Arch"`
	OS      string `toml:"OS"`
	Version string `toml:"Version"`
	Sum     string `toml:"Sum"`
}

Release is the type that holds release data for a specific build of a plugin

type TestConfig

type TestConfig struct {
	config.Config
}

TestConfig Implementations out several methods

func (*TestConfig) GetConfigFolder

func (c *TestConfig) GetConfigFolder(xdgPath string) string

GetConfigFolder returns the absolute path for the TestConfig

func (*TestConfig) GetInstalledPlugins added in v1.9.0

func (c *TestConfig) GetInstalledPlugins() []string

GetInstalledPlugins returns the mocked out list of installed plugins

func (*TestConfig) InitConfig

func (c *TestConfig) InitConfig()

InitConfig initializes the config with the values we need

func (*TestConfig) WriteConfigField added in v1.9.0

func (c *TestConfig) WriteConfigField(field string, value interface{}) error

WriteConfigField mocks out the method so that we can ensure installed plugins data is written

type TestServers

type TestServers struct {
	ArtifactoryServer *httptest.Server
	StripeServer      *httptest.Server
}

TestServers is a struct containing test servers that will be useful for unit testing plugin logic

func (*TestServers) CloseAll

func (ts *TestServers) CloseAll()

CloseAll calls Close() on each of the httptest servers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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