Documentation
¶
Overview ¶
Package plugins provides the plugin system for extending the CLI.
Index ¶
- Variables
- func CleanupAllClients()
- func FetchRemoteResource(url string) ([]byte, error)
- func GetBinaryExtension() string
- func GetNodeBinaryPath(cfg config.IConfig, majorVersion string) string
- func GetNodeRuntimePath(cfg config.IConfig, majorVersion string) string
- func GetRuntimeRequirement(release Release) (string, bool)
- func GetRuntimesDir(cfg config.IConfig) string
- func InstallNodeRuntime(ctx context.Context, cfg config.IConfig, fs afero.Fs, majorVersion string) error
- func IsPluginCommand(cmd *cobra.Command) bool
- func IsRuntimeInstalled(cfg config.IConfig, fs afero.Fs, majorVersion string) bool
- func RefreshPluginManifest(ctx context.Context, config config.IConfig, fs afero.Fs, baseURL string) error
- type CLIPluginGRPC
- type CLIPluginV1
- type CLIPluginV3
- type CoreCLIHelper
- type CoreCLIHelperClient
- func (c *CoreCLIHelperClient) Echo(input string) (string, error)
- func (c *CoreCLIHelperClient) KeychainDeletePassword(key string) (bool, error)
- func (c *CoreCLIHelperClient) KeychainFindCredentials() ([]string, error)
- func (c *CoreCLIHelperClient) KeychainGetPassword(key string) (string, bool, error)
- func (c *CoreCLIHelperClient) KeychainSetPassword(key string, value string) error
- func (c *CoreCLIHelperClient) SendAnalytics(eventName string, eventValue string) error
- type CoreCLIHelperServer
- func (s *CoreCLIHelperServer) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error)
- func (s *CoreCLIHelperServer) KeychainDeletePassword(ctx context.Context, req *proto.KeychainDeletePasswordRequest) (*proto.KeychainDeletePasswordResponse, error)
- func (s *CoreCLIHelperServer) KeychainFindCredentials(ctx context.Context, req *proto.KeychainFindCredentialsRequest) (*proto.KeychainFindCredentialsResponse, error)
- func (s *CoreCLIHelperServer) KeychainGetPassword(ctx context.Context, req *proto.KeychainGetPasswordRequest) (*proto.KeychainGetPasswordResponse, error)
- func (s *CoreCLIHelperServer) KeychainSetPassword(ctx context.Context, req *proto.KeychainSetPasswordRequest) (*proto.KeychainSetPasswordResponse, error)
- func (s *CoreCLIHelperServer) SendAnalytics(ctx context.Context, req *proto.SendAnalyticsRequest) (*proto.SendAnalyticsResponse, error)
- type Dispatcher
- type DispatcherGRPC
- type DispatcherRPCServer
- type DispatcherV3
- type GRPCClient
- type GRPCClientV3
- type GRPCServer
- type GRPCServerV3
- type NodeRuntimeConfig
- type Plugin
- func (p *Plugin) Install(ctx context.Context, cfg config.IConfig, fs afero.Fs, version string, ...) error
- func (p *Plugin) LookUpLatestVersion() string
- func (p *Plugin) Run(ctx context.Context, config *config.Config, fs afero.Fs, args []string) error
- func (p *Plugin) Uninstall(ctx context.Context, config config.IConfig, fs afero.Fs) error
- type PluginClient
- type PluginList
- type Release
- type TestConfig
- type TestServers
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
GetNodeBinaryPath returns the path to the node executable for a specific version
func GetNodeRuntimePath ¶ added in v1.37.3
GetNodeRuntimePath returns the path to a specific Node.js runtime installation
func GetRuntimeRequirement ¶ added in v1.37.3
GetRuntimeRequirement extracts the required Node.js version from a release
func GetRuntimesDir ¶ added in v1.37.3
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
IsPluginCommand returns true if the command invoked is for a plugin false otherwise
func IsRuntimeInstalled ¶ added in v1.37.3
IsRuntimeInstalled checks if a specific Node.js runtime is already installed
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.
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 (s *CoreCLIHelperServer) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error)
func (*CoreCLIHelperServer) KeychainDeletePassword ¶ added in v1.38.0
func (s *CoreCLIHelperServer) KeychainDeletePassword(ctx context.Context, req *proto.KeychainDeletePasswordRequest) (*proto.KeychainDeletePasswordResponse, error)
func (*CoreCLIHelperServer) KeychainFindCredentials ¶ added in v1.38.0
func (s *CoreCLIHelperServer) KeychainFindCredentials(ctx context.Context, req *proto.KeychainFindCredentialsRequest) (*proto.KeychainFindCredentialsResponse, error)
func (*CoreCLIHelperServer) KeychainGetPassword ¶ added in v1.38.0
func (s *CoreCLIHelperServer) KeychainGetPassword(ctx context.Context, req *proto.KeychainGetPasswordRequest) (*proto.KeychainGetPasswordResponse, error)
func (*CoreCLIHelperServer) KeychainSetPassword ¶ added in v1.38.0
func (s *CoreCLIHelperServer) KeychainSetPassword(ctx context.Context, req *proto.KeychainSetPasswordRequest) (*proto.KeychainSetPasswordResponse, error)
func (*CoreCLIHelperServer) SendAnalytics ¶ added in v1.37.4
func (s *CoreCLIHelperServer) SendAnalytics(ctx context.Context, req *proto.SendAnalyticsRequest) (*proto.SendAnalyticsResponse, error)
type Dispatcher ¶
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
func (m *GRPCServer) RunCommand(ctx context.Context, req *proto.RunCommandRequest) (*proto.RunCommandResponse, error)
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
func (m *GRPCServerV3) RunCommand(ctx context.Context, req *proto.RunCommandRequest) (*proto.RunCommandResponse, error)
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 ¶
LookUpLatestVersion gets latest CLI version note: assumes versions are listed in asc order
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 ¶
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 ¶
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 ¶
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.