plugins

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

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 RefreshPluginManifest

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

RefreshPluginManifest refreshes the plugin manifest

Types

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 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 Plugin

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

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, config 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

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
	OS      string
	Version string
	Sum     string
}

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

type TestConfig

type TestConfig struct{}

TestConfig Implementation out the GetConfigFolder function

func (*TestConfig) EditConfig

func (c *TestConfig) EditConfig() error

EditConfig is not implemented

func (*TestConfig) GetConfigFolder

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

GetConfigFolder returns the absolute path for the TestConfig

func (*TestConfig) GetProfile

func (c *TestConfig) GetProfile() *config.Profile

GetProfile returns the Mock Profile

func (*TestConfig) InitConfig

func (c *TestConfig) InitConfig()

InitConfig is not implemented

func (*TestConfig) PrintConfig

func (c *TestConfig) PrintConfig() error

PrintConfig is not implemented

func (*TestConfig) RemoveAllProfiles

func (c *TestConfig) RemoveAllProfiles() error

RemoveAllProfiles is not implemented

func (*TestConfig) RemoveProfile

func (c *TestConfig) RemoveProfile(profileName string) error

RemoveProfile is not implemented

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.

Jump to

Keyboard shortcuts

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