Documentation
¶
Overview ¶
Package plugins installs, records and finds the plugins of the sf-compatible mode. A plugin is one executable for each operating system and architecture, published as an OCI artifact on a container registry.
Index ¶
- Constants
- Variables
- func CheckConflicts(records []Record, manifest sfplugin.Manifest, ...) error
- func DefaultDir() (string, error)
- func ExecutableName(pluginName string, platform Platform) string
- func RegistryPrefix() string
- type Client
- func (c *Client) Fetch(ctx context.Context, resolved Resolved, store *Store) (string, error)
- func (c *Client) Publish(ctx context.Context, ref Reference, manifest sfplugin.Manifest, ...) (PublishResult, error)
- func (c *Client) Resolve(ctx context.Context, ref Reference, platform Platform) (Resolved, error)
- type Match
- type Platform
- type PublishOptions
- type PublishResult
- type Record
- type Reference
- type Resolved
- type Store
Constants ¶
const ( ArtifactType = "application/vnd.forcecli.sf.plugin.v1" ConfigMediaType = "application/vnd.forcecli.sf.plugin.config.v1+json" ExecutableMediaType = "application/vnd.forcecli.sf.plugin.executable.v1" )
Media types of a published plugin. A tag points to an OCI image index with one image manifest for each platform. Each manifest has the plugin manifest as its config and the executable as its only layer.
const DefaultRegistryPrefix = "ghcr.io/forcecli/sf-plugins"
DefaultRegistryPrefix is put in front of a plugin name that has no registry host: "sfdx-git-delta" is read as "ghcr.io/forcecli/sf-plugins/sfdx-git-delta".
const DefaultTag = "latest"
DefaultTag is the tag used when a reference has none.
const DirEnv = "SF_PLUGINS_DIR"
DirEnv names the environment variable that replaces the default plugin directory, ~/.sf/plugins.
const RegistryPrefixEnv = "SF_PLUGINS_REGISTRY"
RegistryPrefixEnv names the environment variable that replaces DefaultRegistryPrefix.
Variables ¶
var ErrNotFound = errors.New("not found in the registry")
ErrNotFound is returned when a tag does not exist in the registry.
Functions ¶
func CheckConflicts ¶
func CheckConflicts(records []Record, manifest sfplugin.Manifest, isBuiltin func(words []string) bool) error
CheckConflicts returns an error when a command of manifest has the id of a built-in command or of a command of another recorded plugin. isBuiltin reports whether the words name a built-in command.
func DefaultDir ¶
DefaultDir returns the plugin directory: $SF_PLUGINS_DIR, or ~/.sf/plugins.
func ExecutableName ¶
ExecutableName returns the file name of the executable of a plugin on a platform.
func RegistryPrefix ¶
func RegistryPrefix() string
RegistryPrefix returns the prefix for names without a registry host.
Types ¶
type Client ¶
type Client struct {
// PlainHTTP makes requests with HTTP instead of HTTPS, for a registry
// on a local machine.
PlainHTTP bool
// contains filtered or unexported fields
}
Client reads and writes plugins in registries.
func NewClient ¶
func NewClient() *Client
NewClient returns a client that authenticates with the credentials of the Docker configuration (~/.docker/config.json and its credential helpers), which "docker login" writes. Without stored credentials for a registry the requests are anonymous.
func (*Client) Fetch ¶
Fetch downloads the executable of a resolved plugin into the store and returns its path. The bytes are checked against the digest in the manifest before the file is given its final name. An executable that is already in the store is not downloaded again.
type Match ¶
type Match struct {
Record Record
Command sfplugin.Command
// Words is the number of leading words that form the command id.
Words int
}
Match is the plugin command that the first words of a command line name.
type Platform ¶
Platform is an operating system and architecture, with the names Go uses for GOOS and GOARCH.
func HostPlatform ¶
func HostPlatform() Platform
HostPlatform returns the platform this program runs on.
func ParsePlatform ¶
ParsePlatform reads "os/arch".
type PublishOptions ¶
type PublishOptions struct {
// Source is the URL of the source repository. GitHub Container
// Registry links a package to the repository named here.
Source string
// Revision is the source control revision the executables were built
// from.
Revision string
// Overwrite allows the tag to be moved when it already exists.
Overwrite bool
}
PublishOptions are the optional parts of a publish.
type PublishResult ¶
type PublishResult struct {
Reference Reference
IndexDigest string
// Platforms maps "os/arch" to the digest of its manifest.
Platforms map[string]string
// Replaced is the digest the tag pointed to before, when the tag
// existed.
Replaced string
}
PublishResult describes a published plugin.
type Record ¶
type Record struct {
Name string `json:"name"`
// Reference is the registry name without the tag. It is empty for a
// linked plugin.
Reference string `json:"reference,omitempty"`
Tag string `json:"tag,omitempty"`
// IndexDigest is the digest the tag pointed to at install.
// ManifestDigest is the digest of the manifest for this platform, and
// names the directory that holds the executable.
IndexDigest string `json:"indexDigest,omitempty"`
ManifestDigest string `json:"manifestDigest,omitempty"`
PlainHTTP bool `json:"plainHTTP,omitempty"`
// Executable is the absolute path of the plugin executable.
Executable string `json:"executable"`
// Linked is true for an executable registered with "plugins link".
Linked bool `json:"linked,omitempty"`
Manifest sfplugin.Manifest `json:"manifest"`
}
Record is one installed or linked plugin in plugins.json.
type Reference ¶
Reference names a plugin in a registry: host, repository path and tag.
func ParseReference ¶
ParseReference reads "name" or "name:tag". A name whose first path segment is not a registry host (it has no "." and no ":", and is not "localhost") is placed under RegistryPrefix. A digest is not accepted; the digest of an installed plugin is recorded at install.
type Resolved ¶
type Resolved struct {
Reference Reference
Platform Platform
// IndexDigest is the digest the tag points to.
IndexDigest string
// ManifestDigest is the digest of the manifest for the platform.
ManifestDigest string
Manifest sfplugin.Manifest
// FileName is the name of the executable.
FileName string
// contains filtered or unexported fields
}
Resolved is a published plugin for one platform.
type Store ¶
type Store struct {
Dir string
}
Store is the plugin directory: plugins.json and the downloaded executables.
func OpenDefault ¶
OpenDefault returns the store in the default plugin directory.
func (*Store) Load ¶
Load returns the recorded plugins sorted by name. A missing plugins.json is an empty list.
func (*Store) Put ¶
Put adds the record, replacing a record of the same name, and removes the replaced plugin's files when no other record uses them.