pluginmgr

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pluginmgr manages installed lfed plugins.

A plugin lives in $XDG_DATA_HOME/lfed/plugins/<name>/ as the binary lfed-<name> and the manifest lfed-plugin.json. the lfed CLI reads manifests for listing and help. It executes a plugin only to run it, to complete its arguments, or to read its manifest at install time.

Index

Constants

View Source
const (
	// ArtifactType marks a per-platform plugin manifest.
	ArtifactType = "application/vnd.linuxfoundation.ed.cli.plugin.v1"
	// LayerMediaType is the single layer: a tar.gz holding lfed-<name>.
	LayerMediaType = "application/vnd.linuxfoundation.ed.cli.plugin.layer.v1.tar+gzip"
	// AnnotationName on the index is the plugin name.
	AnnotationName = "org.linuxfoundation.ed.cli.plugin.name"
	// AnnotationRequiresLfed on the index mirrors the manifest requires_lfed
	// range, so the lfed CLI can pick a compatible version before pulling.
	AnnotationRequiresLfed = "org.linuxfoundation.ed.cli.plugin.requires_lfed"
)

OCI artifact contract. The release workflow in p3-platform writes these; the lfed CLI reads them. Both sides MUST change together.

View Source
const (
	SourcePath = "path"
	SourceOCI  = "oci"
)

Source types stored in lfed-plugin.json.

View Source
const DefaultRegistry = "ghcr.io/lf-certification/lfed-cli-plugins"

DefaultRegistry is the OCI repository prefix a bare plugin name resolves against. LFED_PLUGIN_REGISTRY overrides it.

View Source
const ManifestFile = "lfed-plugin.json"

ManifestFile is the manifest name inside a plugin directory.

Variables

This section is empty.

Functions

func BinaryName

func BinaryName(name string) string

BinaryName returns the executable name of a plugin.

func CheckLfedVersion

func CheckLfedVersion(requires, running string) error

CheckLfedVersion verifies that the running lfed version satisfies the requires_lfed range. A pre-release tag such as 0.1.0-dev is ignored so development builds pass release ranges. Failure yields *IncompatibleError; the name is filled by the caller when it is known.

func Complete

func Complete(ctx context.Context, f *cmdutil.Factory, name string, args []string) error

Complete runs `lfed-<name> __complete args...` for shell completion. The plugin's completion output passes through unchanged. No token is resolved: completion MUST NOT prompt for the keyring or fail on auth.

func Dir

func Dir() (string, error)

Dir returns the plugin directory. LFED_PLUGIN_DIR overrides it for tests.

func Env

func Env(lfedVersion string, ctx contexts.Context, token string, mode output.Mode, reexec string) []string

Env returns the six LFED_* variables of the plugin contract. The base URL has no trailing slash; contexts.Context.APIBaseURL guarantees that. LFED_DEBUG is not set here: it passes through from the operator's environment, so a plugin sees exactly what the CLI saw.

func Exec

func Exec(ctx context.Context, f *cmdutil.Factory, p Installed, args []string) error

Exec runs the plugin binary with args and the contract environment. Streams pass through. --yes is appended when the CLI flag is set and args do not already carry it. A non-zero exit returns *ExitError.

The token is best effort. When it cannot be resolved, LFED_TOKEN is exported empty and the plugin asks `LFED_REEXEC auth token` when it needs one (sdk/auth.Token). That keeps --help and read-only paths working while logged out; the login hint appears at first API use.

func ExitCode

func ExitCode(err error) int

ExitCode maps an error to the lfed CLI exit code: 0 for nil, the plugin's code for *ExitError, 2 for *NotFoundError and *IncompatibleError, else 1.

func Remove

func Remove(name string) error

Remove deletes the plugin directory. A missing plugin yields *NotFoundError.

func Run

func Run(ctx context.Context, f *cmdutil.Factory, name string, args []string) error

Run looks up name, checks requires_lfed and executes the plugin with args. It is the unknown-command path of the root command.

Types

type ExitError

type ExitError struct {
	Code int
}

ExitError carries a plugin's non-zero exit code. main exits with Code and prints nothing; the plugin already reported the failure.

func (*ExitError) Error

func (e *ExitError) Error() string

type IncompatibleError

type IncompatibleError struct {
	Name     string
	Requires string
	Running  string
}

IncompatibleError reports a plugin whose requires_lfed range excludes the running lfed CLI. the lfed CLI exits 2.

func (*IncompatibleError) Error

func (e *IncompatibleError) Error() string

type Installed

type Installed struct {
	Manifest sdkplugin.Manifest
	// Source is where the plugin came from. Zero for installs that predate
	// source tracking.
	Source Source
	// Dir is the plugin directory: <plugins>/<name>.
	Dir string
	// Binary is the executable path: <plugins>/<name>/lfed-<name>.
	Binary string
}

Installed is one plugin found in the plugin directory.

func Install

func Install(ctx context.Context, f *cmdutil.Factory, arg string, opts Options) (Installed, error)

Install installs the plugin named by arg (see ParseSource) and returns it. The binary is staged in the plugin directory, asked for __metadata, validated against f.Version, then moved into place together with lfed-plugin.json. An existing install of the same name is replaced.

func List

func List() ([]Installed, error)

List returns installed plugins sorted by name. It reads manifests only. Directories without a manifest are skipped.

func Lookup

func Lookup(name string) (Installed, error)

Lookup returns the plugin called name. A missing binary yields *NotFoundError. A binary without a manifest yields an error that asks for a reinstall.

type NoReleaseError

type NoReleaseError struct {
	Ref     string
	Running string
	// Newest is the highest version seen and its requires_lfed range.
	// Empty when the repository has no semver tags.
	Newest, Requires string
}

NoReleaseError reports an OCI repository with no version the running lfed accepts. The lfed CLI exits 2.

func (*NoReleaseError) Error

func (e *NoReleaseError) Error() string

type NotFoundError

type NotFoundError struct {
	Name        string
	Suggestions []string
}

NotFoundError reports a word that is neither a core command nor an installed plugin. The lfed CLI exits 2. Suggestions, when the caller filled them, are close command words.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Options

type Options struct {
	// Reserved are core command words. A plugin with one of these names
	// could never be dispatched, so Install refuses it.
	Reserved []string
}

Options tune Install.

type Source

type Source struct {
	Type string `json:"type"`
	// Path is the absolute path given to `lfed plugin install`. Type path only.
	Path string `json:"path,omitempty"`
	// Ref is the OCI repository without a tag, e.g.
	// ghcr.io/lf-certification/lfed-cli-plugins/cluster. Type oci only.
	Ref string `json:"ref,omitempty"`
	// Version is the OCI tag installed, or the tag requested before
	// resolution. Empty means "highest compatible". Type oci only.
	Version string `json:"version,omitempty"`
}

Source records where a plugin was installed from. `lfed plugin upgrade` re-resolves an OCI source; a path source can only be reinstalled.

func ParseSource

func ParseSource(arg string) (Source, error)

ParseSource classifies an install argument. The rule follows Go's import path convention so a name never shadows a directory:

./x ../x /x ~/x  -> local path (file or Go main package directory)
name[@version]   -> OCI artifact under the default registry
host/path[:tag]  -> OCI artifact at a full reference

A relative directory without ./ is rejected. The error names the fix.

func (Source) Name

func (s Source) Name() string

Name returns the plugin name an OCI ref implies: its last path element.

func (Source) String

func (s Source) String() string

String renders the source for `lfed plugin list`.

type UpgradeResult

type UpgradeResult struct {
	Name string `json:"name"`
	From string `json:"from"`
	// To is the version that is or would be installed. Equal to From when
	// the plugin is current. Empty when the source cannot be upgraded.
	To       string `json:"to,omitempty"`
	Upgraded bool   `json:"upgraded"`
	// Note explains a skip: current, dry run, or a non-upgradable source.
	Note string `json:"note,omitempty"`
}

UpgradeResult is the outcome for one plugin.

func Upgrade

func Upgrade(ctx context.Context, f *cmdutil.Factory, names []string, dryRun bool, opts Options) ([]UpgradeResult, error)

Upgrade re-resolves every named plugin, or every installed plugin when names is empty, and installs a newer compatible OCI version when one exists. Path sources and installs without a recorded source are reported, not changed. dryRun resolves without installing.

Jump to

Keyboard shortcuts

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