plugins

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package plugins provides the plugin system for extending the CLI.

Index

Constants

This section is empty.

Variables

View Source
var (
	PluginDev   = false
	PluginsPath string
)

dev mode vars

Functions

func CleanupAllClients added in v1.8.1

func CleanupAllClients()

CleanupAllClients tears down and disconnects all "managed" plugin clients

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 GetNodeBinaryPath added in v1.37.3

func GetNodeBinaryPath(cfg config.IConfig, majorVersion string) string

GetNodeBinaryPath returns the path to the node executable for a specific version

func GetNodeRuntimePath added in v1.37.3

func GetNodeRuntimePath(cfg config.IConfig, majorVersion string) string

GetNodeRuntimePath returns the path to a specific Node.js runtime installation

func GetRuntimeRequirement added in v1.37.3

func GetRuntimeRequirement(release Release) (string, bool)

GetRuntimeRequirement extracts the required Node.js version from a release

func GetRuntimesDir added in v1.37.3

func GetRuntimesDir(cfg config.IConfig) string

GetRuntimesDir returns the directory where runtimes are installed

func InstallNodeRuntime added in v1.37.3

func InstallNodeRuntime(ctx context.Context, cfg config.IConfig, fs afero.Fs, majorVersion string) error

InstallNodeRuntime downloads and installs a specific Node.js runtime version

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 IsRuntimeInstalled added in v1.37.3

func IsRuntimeInstalled(cfg config.IConfig, fs afero.Fs, majorVersion string) bool

IsRuntimeInstalled checks if a specific Node.js runtime is already installed

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 CLIPluginV3 added in v1.37.4

type CLIPluginV3 struct {
	hcplugin.Plugin
	Impl DispatcherV3
}

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

func (*CLIPluginV3) GRPCClient added in v1.37.4

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

GRPCClient creates the GRPC client.

func (*CLIPluginV3) GRPCServer added in v1.37.4

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

GRPCServer creates the GRPC server.

type CoreCLIHelper added in v1.37.4

type CoreCLIHelper interface {
	Echo(input string) (string, error)
	SendAnalytics(eventName string, eventValue string) error
	KeychainGetPassword(key string) (string, bool, error)
	KeychainSetPassword(key string, value string) error
	KeychainDeletePassword(key string) (bool, error)
	KeychainFindCredentials() ([]string, error)
}

CoreCLIHelper is the interface that's implemented by the host and called by the plugin.

func NewCoreCLIHelper added in v1.37.4

func NewCoreCLIHelper(ctx context.Context) CoreCLIHelper

NewCoreCLIHelper creates a new CoreCLIHelper with the given context.

type CoreCLIHelperClient added in v1.37.4

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

func (*CoreCLIHelperClient) Echo added in v1.37.4

func (c *CoreCLIHelperClient) Echo(input string) (string, error)

func (*CoreCLIHelperClient) KeychainDeletePassword added in v1.38.0

func (c *CoreCLIHelperClient) KeychainDeletePassword(key string) (bool, error)

func (*CoreCLIHelperClient) KeychainFindCredentials added in v1.38.0

func (c *CoreCLIHelperClient) KeychainFindCredentials() ([]string, error)

func (*CoreCLIHelperClient) KeychainGetPassword added in v1.38.0

func (c *CoreCLIHelperClient) KeychainGetPassword(key string) (string, bool, error)

func (*CoreCLIHelperClient) KeychainSetPassword added in v1.38.0

func (c *CoreCLIHelperClient) KeychainSetPassword(key string, value string) error

func (*CoreCLIHelperClient) SendAnalytics added in v1.37.4

func (c *CoreCLIHelperClient) SendAnalytics(eventName string, eventValue string) error

type CoreCLIHelperServer added in v1.37.4

type CoreCLIHelperServer struct {
	proto.CoreCLIHelperServer
	Impl CoreCLIHelper
}

func (*CoreCLIHelperServer) Echo added in v1.37.4

func (*CoreCLIHelperServer) KeychainDeletePassword added in v1.38.0

func (*CoreCLIHelperServer) KeychainFindCredentials added in v1.38.0

func (*CoreCLIHelperServer) KeychainGetPassword added in v1.38.0

func (*CoreCLIHelperServer) KeychainSetPassword added in v1.38.0

func (*CoreCLIHelperServer) SendAnalytics added in v1.37.4

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 DispatcherV3 added in v1.37.4

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

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

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 GRPCClientV3 added in v1.37.4

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

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

func (*GRPCClientV3) RunCommand added in v1.37.4

func (m *GRPCClientV3) RunCommand(additionalInfo *proto.AdditionalInfo, args []string, coreCLIHelper CoreCLIHelper) 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 GRPCServerV3 added in v1.37.4

type GRPCServerV3 struct {
	proto.MainServer
	Impl DispatcherV3
	// contains filtered or unexported fields
}

GRPCServerV3 is the gRPC server that GRPCClientV3 talks to.

func (*GRPCServerV3) RunCommand added in v1.37.4

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

type NodeRuntimeConfig added in v1.37.3

type NodeRuntimeConfig struct {
	Version   string
	Checksums map[string]map[string]string // OS -> Arch -> Checksum
}

NodeRuntimeConfig holds configuration for a specific Node.js runtime version

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"`
	Runtime map[string]string `toml:"Runtime,omitempty"`
}

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