plugin

package
v0.0.0-...-27d5cd9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Index

Constants

View Source
const (
	UserExecute  = 1 << 6
	GroupExecute = 1 << 3
	OtherExecute = 1 << 0
)

permission bits for execute

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextData

type ContextData map[string]string

type ContextDataConsumer

type ContextDataConsumer interface {
	// ExecuteWithContextData executes the plugin with the given args much like
	// Execute() but with an additional argument that holds the ContextData
	ExecuteWithContextData(args []string, data ContextData) error
}

type Manager

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

func NewManager

func NewManager(pluginDir string, lookupInPath bool) *Manager

NewManager creates a new manager for looking up plugins on the file system

func (*Manager) FindPlugin

func (manager *Manager) FindPlugin(parts []string) (Plugin, error)

FindPlugin checks if a plugin for the given parts exist and return it. The args given must not contain any options and contain only the commands (like in [ "source", "github" ] for a plugin called 'kn-source-github' The plugin with the most specific (longest) name is returned or nil if non is found. An error is returned if the lookup fails for some reason like an io error

func (*Manager) HelpTemplateFuncs

func (manager *Manager) HelpTemplateFuncs() *template.FuncMap

HelpTemplateFuncs returns a function map which can be used in templates for resolving plugin related help messages

func (*Manager) ListPlugins

func (manager *Manager) ListPlugins() (PluginList, error)

ListPlugins lists all plugins that can be found in the plugin directory or in the path (if configured)

func (*Manager) ListPluginsForCommandGroup

func (manager *Manager) ListPluginsForCommandGroup(commandGroupParts []string) (PluginList, error)

ListPluginsForCommandGroup lists all plugins that can be found in the plugin directory or in the path (if configured), and which fits to a command group

func (*Manager) LookupInPath

func (manager *Manager) LookupInPath() bool

LookupInPath returns true if plugins should be also looked up within the path

func (*Manager) PluginsDir

func (manager *Manager) PluginsDir() string

PluginsDir returns the configured directory holding plugins

func (*Manager) Verify

func (manager *Manager) Verify() VerificationErrorsAndWarnings

Verification of a ll plugins. This method returns all errors and warnings for the verification. The following criteria are verified (for each plugin): * If the plugin is executable * If the plugin is overshadowed by a previous plugin

type Manifest

type Manifest struct {
	// Path to external plugin binary. Always empty for inlined plugins.
	Path string `json:"path,omitempty"`

	// Plugin declares its own manifest to be included in Context Sharing feature
	HasManifest bool `json:"hasManifest"`

	// ProducesContextDataKeys is a list of keys for the ContextData that
	// a plugin can produce. Nil or an empty list declares that this
	// plugin is not ContextDataProducer
	ProducesContextDataKeys []string `json:"producesKeys,omitempty"`

	// ConsumesContextDataKeys is a list of keys from a ContextData that a
	// plugin is interested in to consume. Nil or an empty list declares
	// that this plugin is not a ContextDataConsumer
	ConsumesContextDataKeys []string `json:"consumesKeys,omitempty"`
}

Manifest represents plugin metadata

type Plugin

type Plugin interface {
	// Get the name of the plugin (the file name without extensions)
	Name() string

	// Execute the plugin with the given arguments
	Execute(args []string) error

	// Return a description of the plugin (if support by the plugin binary)
	Description() (string, error)

	// The command path leading to this plugin.
	// Eg. for a plugin "kn source github" this will be [ "source", "github" ]
	CommandParts() []string

	// Location of the plugin where it is stored in the filesystem
	Path() string
}

Interface describing a plugin

type PluginList

type PluginList []Plugin

Used for sorting a list of plugins

var InternalPlugins PluginList

Allow plugins to register to this slice for inlining

func (PluginList) Len

func (p PluginList) Len() int

func (PluginList) Less

func (p PluginList) Less(i, j int) bool

func (PluginList) Swap

func (p PluginList) Swap(i, j int)

type PluginManifest

type PluginManifest struct {
	// ProducesContextDataKeys is a list of keys for the ContextData that
	// a plugin can produce. Nil or an empty list declares that this
	// plugin is not ContextDataProducer
	ProducesContextDataKeys []string

	// ConsumesContextDataKeys is a list of keys from a ContextData that a
	// plugin is interested in to consume. Nil or an empty list declares
	// that this plugin is not a ContextDataConsumer
	ConsumesContextDataKeys []string
}

type PluginWithManifest

type PluginWithManifest interface {
	// Plugin original interface wrapper
	Plugin

	// GetManifest returns a metadata descriptor of plugin
	GetManifest() *Manifest

	// GetContextData returns a map structure that is used to share common context data from plugin
	GetContextData() map[string]string

	// ExecuteWithContextData an extended version of plugin.Execute command to allow injection and use of ContextData.
	// This is a map[string]string structure to share common value service name between kn and plugins.
	ExecuteWithContextData(ctx map[string]string, args []string) error
}

PluginWithManifest represents extended plugin support for Manifest and Context Sharing feature

type VerificationErrorsAndWarnings

type VerificationErrorsAndWarnings struct {
	Errors   []string
	Warnings []string
}

Collection of errors and warning collected during verifications

func (*VerificationErrorsAndWarnings) AddError

func (eaw *VerificationErrorsAndWarnings) AddError(format string, args ...interface{}) VerificationErrorsAndWarnings

func (*VerificationErrorsAndWarnings) AddWarning

func (eaw *VerificationErrorsAndWarnings) AddWarning(format string, args ...interface{}) VerificationErrorsAndWarnings

func (*VerificationErrorsAndWarnings) HasErrors

func (eaw *VerificationErrorsAndWarnings) HasErrors() bool

func (*VerificationErrorsAndWarnings) IsEmpty

func (eaw *VerificationErrorsAndWarnings) IsEmpty() bool

func (*VerificationErrorsAndWarnings) PrintWarningsAndErrors

func (eaw *VerificationErrorsAndWarnings) PrintWarningsAndErrors(out io.Writer)

Jump to

Keyboard shortcuts

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