Documentation
¶
Overview ¶
Package adapter is the host side of the adapter system: manifests, the installed-adapter store, package lifecycle, trust checks and executable invocation. Any ext product can use it; a product supplies only the store home and the wording of its trust hint. The adapter process protocol that executables implement lives in pkg/ext-go (the root package).
Index ¶
- Constants
- func BuildGoPackage(options GoBuildOptions) (string, error)
- func ConfigHome() string
- func FileSHA256(path string) (string, error)
- func Home() string
- func IsKnownRuntime(runtime string) bool
- func PackageDirectory(directory, output, goos, goarch string) error
- func Seal(directory string, target Target) (packagekit.Manifest, error)
- func TemplateFromKeyValues(text string) (packagekit.Manifest, error)
- func ValidateDependency(dependency Dependency, target *Adapter) error
- func WriteIndex(output string, packages []string) error
- func WriteKeyValueManifest(directory, text string) error
- func WriteManifest(directory string, pm packagekit.Manifest) error
- type Adapter
- func (a *Adapter) Checksum() (string, error)
- func (a *Adapter) Command(invocation Invocation) (*exec.Cmd, error)
- func (a *Adapter) CommandContext(ctx context.Context, invocation Invocation) (*exec.Cmd, error)
- func (a *Adapter) ConfigKeys() []string
- func (a *Adapter) DisplayLabel() string
- func (a *Adapter) ExecutablePath() string
- func (a *Adapter) ExecutablePathForOS(goos string) string
- func (a *Adapter) HasBrowserManagement(operation string) bool
- func (a *Adapter) HasBrowserShare(operation string) bool
- func (a *Adapter) HasCapability(capability string) bool
- func (a *Adapter) HasCommand(command string) bool
- func (a *Adapter) HasComputerCapability(capability string) bool
- func (a *Adapter) HasComputerCommand(command string) bool
- func (a *Adapter) IsComputerEndpoint() bool
- func (a *Adapter) IsKnownRuntime() bool
- func (a *Adapter) IsRuntime(runtimeName string) bool
- func (a *Adapter) IsSelectable() bool
- func (a *Adapter) PluginDescriptor() (plugin.Descriptor, error)
- func (a *Adapter) SupportsSurface(surface string) bool
- type Check
- type Dependency
- type GoBuildOptions
- type Invocation
- type Manifest
- type Store
- func (s *Store) AssertTrusted(a *Adapter) error
- func (s *Store) Install(source string) (*Adapter, error)
- func (s *Store) InstallSource(source, expectedSHA256 string) (*Adapter, error)
- func (s *Store) IsTrusted(a *Adapter) (bool, error)
- func (s *Store) List() ([]*Adapter, error)
- func (s *Store) Load(name string) (*Adapter, error)
- func (s *Store) Remove(name string) error
- func (s *Store) RemoveTrust(name string) error
- func (s *Store) Replace(source string) (*Adapter, error)
- func (s *Store) Trust(a *Adapter) error
- func (s *Store) TrustState(a *Adapter) (TrustState, error)
- func (s *Store) Verify(names ...string) ([]Check, error)
- type Target
- type TrustState
Constants ¶
const ( // ManifestFileName is the manifest at the top of an adapter directory. ManifestFileName = "plugin.json" // MetadataKey names the metadata object that carries what ctx interprets. MetadataKey = "ctx.adapter/v1" // BrowserShareContract and BrowserManagementContract carry the browser // operations an adapter declares; BrowserContractVersion is their version. BrowserManagementContract = "ext.adapter.browser.management" BrowserContractVersion = "1" // ArgvRuntime is the entrypoint runtime of an adapter: the host invokes the // executable once per operation with arguments and streams, not as a // long-lived JSON-line session. ArgvRuntime = "argv" )
An adapter is an ext package. Its manifest is plugin.json, the same ext.package/v1 document every package has, and nothing else: this file turns that document into the fields hosts use (Manifest) and back.
- The adapter name is the package identity id.
- The capabilities are the operations of the ext.adapter contract, at the adapter API version; browser share and management operations are the operations of two more contracts.
- The launchers are artifacts and entrypoints: "main" runs the executable under the "argv" runtime, "main.windows" is the native Windows one.
- Runtime assets are further artifacts (a file, or a tree for a directory).
- Everything ctx itself interprets is one metadata object, MetadataKey. Its schema belongs to ctx; ext never reads it (see docs/adapter-api.md).
const APIVersion = "2.0"
const Protocol = "ext.adapter/" + APIVersion
Protocol is the entrypoint protocol of an adapter: its argv and stream binding at the adapter API version.
Variables ¶
This section is empty.
Functions ¶
func BuildGoPackage ¶
func BuildGoPackage(options GoBuildOptions) (string, error)
BuildGoPackage compiles a local Go adapter and creates a platform archive. Only the sealed plugin.json, the resulting executable, and the artifacts it lists are shipped.
func ConfigHome ¶
func ConfigHome() string
ConfigHome is the root of ext's per-user state, shared by every product so that ctx and ctn see the same installed adapters and the same trust decisions. EXT_HOME overrides it. CTX_HOME is honored for installations that predate the shared home.
func FileSHA256 ¶
FileSHA256 returns the checksum users can pin when publishing an adapter index.
func Home ¶
func Home() string
Home is the directory holding installed adapters and their trust records. It is global to the user: trusting an adapter once makes it available to every product. EXT_ADAPTER_HOME overrides it, then EXT_HOME. The CTX_ADAPTER_HOME and CTX_HOME names remain accepted for earlier installations.
func IsKnownRuntime ¶
IsKnownRuntime reports whether this library defines the runtime.
func PackageDirectory ¶
PackageDirectory writes a platform-specific adapter archive from a ready-to-run directory: a source directory with a plugin.json template and the files it lists, or an already sealed package. The archive holds the sealed plugin.json and exactly the artifacts it lists, so unlisted files in the directory are not shipped. A template is sealed for the target: the launcher that does not apply is dropped and the platform is recorded on the one that does.
func Seal ¶
Seal turns the template in directory into a sealed manifest and writes it as plugin.json. The artifacts the template declares must exist; every other regular file in the directory is added as an artifact too, in path order, so the sealed manifest lists exactly the files the directory holds and a first-party adapter keeps shipping the helper binaries built beside its launcher. Seal computes each digest (a declared directory is a tree artifact), stamps the platform on the launchers when target is set, and sets the revision to the digest of the first launcher. For a target it first drops the launcher of the other kind (see pruneToTarget); the dropped launcher's file is not listed.
func TemplateFromKeyValues ¶
TemplateFromKeyValues converts the compact key = "value" notation of earlier ext versions into a package template. It exists for tooling and for tests that write adapters; the loader reads plugin.json only.
func ValidateDependency ¶
func ValidateDependency(dependency Dependency, target *Adapter) error
ValidateDependency checks the declared API and capability of a runtime dependency. Trust is checked separately against the installed package.
func WriteIndex ¶
WriteIndex records platform archives and their digests for one adapter. Archives must sit beside the index so its references work locally and over HTTPS.
func WriteKeyValueManifest ¶
WriteKeyValueManifest writes the plugin.json template of an adapter given in the compact key = "value" notation to directory.
func WriteManifest ¶
WriteManifest writes pm as the plugin.json of directory.
Types ¶
type Adapter ¶
type Adapter struct {
Directory string
Manifest Manifest
// Package is the ext.package/v1 document the Manifest was derived from: a
// template in a source directory, sealed in an installed or packaged one.
Package packagekit.Manifest
}
func LoadDirectory ¶
func LoadDirectoryForOS ¶
LoadDirectoryForOS validates a package for a specific target operating system.
func LoadSource ¶
LoadSource validates the plugin.json template of an adapter source directory without requiring its executable to exist yet: a Go adapter is built before it can run. Everything else is checked as LoadDirectoryForOS does.
func (*Adapter) CommandContext ¶
CommandContext prepares an adapter invocation whose process is cancelled when ctx is done. A nil context retains Command's behavior.
func (*Adapter) ConfigKeys ¶
func (*Adapter) DisplayLabel ¶
DisplayLabel is presentation metadata, never an authentication identity.
func (*Adapter) ExecutablePath ¶
func (*Adapter) ExecutablePathForOS ¶
func (*Adapter) HasBrowserManagement ¶
func (*Adapter) HasBrowserShare ¶
func (*Adapter) HasCapability ¶
func (*Adapter) HasCommand ¶
func (*Adapter) HasComputerCapability ¶
func (*Adapter) HasComputerCommand ¶
func (*Adapter) IsComputerEndpoint ¶
func (*Adapter) IsKnownRuntime ¶
IsKnownRuntime reports whether the adapter's runtime is one this library defines; products should skip adapters for which it is false.
func (*Adapter) IsSelectable ¶
func (*Adapter) PluginDescriptor ¶
func (a *Adapter) PluginDescriptor() (plugin.Descriptor, error)
PluginDescriptor gives CTX adapters the same immutable selection contract used by library consumers. The directory digest covers all adapter assets.
func (*Adapter) SupportsSurface ¶
type Check ¶
type Check struct {
Name string
State TrustState
// Err is why the adapter could not be loaded: a malformed manifest, an
// escaping path, a symbolic link, a name that does not match its directory.
// State is empty when Err is set.
Err error
}
Check is the verification result for one adapter directory.
type Dependency ¶
Dependency binds a share space to a separately installed adapter using an exact adapter API version. The binding is platform-specific in the manifest.
type GoBuildOptions ¶
type Invocation ¶
type Manifest ¶
type Manifest struct {
APIVersion string
Name string
Runtime string
Surfaces []string
Executable string
ExecutableWindows string
Description string
DisplayName string
Capabilities []string
Supports []string
SelectorKey string
Selectable bool
ExtraKeys []string
Commands []string
ComputerCommands []string
ComputerCapabilities []string
ComputerHookEvents []string
ComputerHookDefaults []string
ComputerHookSettings string
ComputerHookTemplate string
Dependencies map[string]Dependency
BrowserQueryPriority int
BrowserQueryAuto bool
OverrideEnv []string
DefaultProvider bool
SelfContained bool
BrowserManagement []string
}
type Store ¶
func (*Store) AssertTrusted ¶
func (*Store) InstallSource ¶
InstallSource installs a local adapter directory, a package archive, or an HTTPS archive. Remote archives require a caller-supplied SHA-256 digest.
func (*Store) RemoveTrust ¶
func (*Store) Replace ¶
Replace validates and stages an adapter before swapping it into the store. If the final rename fails, the previous adapter is restored.
func (*Store) TrustState ¶
func (s *Store) TrustState(a *Adapter) (TrustState, error)
TrustState compares a's current content with the recorded digest. IsTrusted reports only match or no match; this separates an adapter nobody reviewed from one that was reviewed and has since been modified.
func (*Store) Verify ¶
Verify checks installed adapters without running any of them: it loads each one with the same validation an install applies, then compares its content with the recorded trust digest. With no names it checks every adapter directory under Home. Unlike List, it reports an adapter that fails to load instead of skipping it, so a damaged install is visible. An unreadable trust file is an error, since no adapter can then be called trusted. Results are sorted by name.
type Target ¶
type Target struct{ OS, Arch string }
Target is the platform a package is built for. A zero Target is portable.
type TrustState ¶
type TrustState string
TrustState is how an installed adapter's content compares with the digest recorded when it was trusted.
const ( // TrustTrusted means the content matches the recorded digest. TrustTrusted TrustState = "trusted" // TrustUntrusted means no digest was ever recorded for the adapter. TrustUntrusted TrustState = "untrusted" // TrustChanged means a digest was recorded and the content no longer matches. TrustChanged TrustState = "changed" )