extensions

package
v2.57.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 10 Imported by: 1 module, 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

Index

Constants

View Source
const (
	ProviderFormatAuto   = "auto"
	ProviderFormatJSON   = "json"
	ProviderFormatDotenv = "dotenv"
)

Session provider output formats

View Source
const (
	CompletionNone  = "none"
	CompletionCobra = "cobra"
)

Binary completion modes

View Source
const (
	OutputRaw  = "raw"
	OutputJSON = "json"
)

Binary command output modes

View Source
const (
	// ContextVersion is the version of the runtime context (environment variables) which is
	// passed to extensions. Increase it when variables are added or changed, together with
	// extsdk.ContextVersion
	ContextVersion = "1"

	// Environment variables passed to extensions
	EnvExtensionName    = "C8Y_EXTENSION_NAME"
	EnvExtensionDir     = "C8Y_EXTENSION_DIR"
	EnvContextVersion   = "C8Y_EXTENSION_CONTEXT_VERSION"
	EnvBin              = "C8Y_BIN"
	EnvSettingsDryRun   = "C8Y_SETTINGS_DEFAULTS_DRY"
	EnvSettingsMode     = "C8Y_SETTINGS_MODE"
	EnvSettingsInsecure = "C8Y_SETTINGS_DEFAULTS_INSECURE"
)
View Source
const CommandAnnotation = "c8y.extension"

CommandAnnotation is the annotation which marks the root command of an extension. Its value is the extension name

View Source
const NameFormat = "^[a-z0-9][a-z0-9-]*$"

NameFormat is the format of a normalized extension name

View Source
const NamePrefix = "c8y-"

NamePrefix is the prefix of the extension folders. It's not part of the extension name

Variables

View Source
var ErrAmbiguousSessionProvider = errors.New("ambiguous session provider")

ErrAmbiguousSessionProvider is returned when a short provider name is provided by more than one extension

View Source
var ErrUnknownSessionProvider = errors.New("unknown session provider")

ErrUnknownSessionProvider is returned when no installed extension provides the session provider

Functions

func MergeEnv added in v2.57.0

func MergeEnv(base []string, set map[string]string, unset map[string]bool) []string

MergeEnv returns base ("KEY=value" items) without the variables in set and unset, followed by the variables in set. Names are compared case-insensitively on Windows

func NormalizeName added in v2.57.0

func NormalizeName(name string) (string, error)

NormalizeName returns the extension name without the c8y- prefix and in lowercase. An error is returned if the result is not a valid extension name, e.g. it contains spaces, underscores, or path separators

func SessionProviderCompletions added in v2.57.0

func SessionProviderCompletions(providers []InstalledSessionProvider) []string

SessionProviderCompletions returns the completion values for the providers, in the format "<ref>\t<description>". The short name is used when it is unique, otherwise the qualified reference

func Variables added in v2.57.0

func Variables(ext Extension, fallbackBin string) map[string]string

Variables returns the extension variables (name, folder, path to c8y, and context version). fallbackBin is used for C8Y_BIN if the path of the running executable can't be determined

Types

type Alias

type Alias interface {
	GetCommand() string
	GetName() string
	GetDescription() string
	IsShell() bool
}

type AliasMock

type AliasMock struct {
	// GetCommandFunc mocks the GetCommand method.
	GetCommandFunc func() string

	// GetDescriptionFunc mocks the GetDescription method.
	GetDescriptionFunc func() string

	// GetNameFunc mocks the GetName method.
	GetNameFunc func() string

	// IsShellFunc mocks the IsShell method.
	IsShellFunc func() bool
	// contains filtered or unexported fields
}

AliasMock is a mock implementation of Alias.

func TestSomethingThatUsesAlias(t *testing.T) {

	// make and configure a mocked Alias
	mockedAlias := &AliasMock{
		GetCommandFunc: func() string {
			panic("mock out the GetCommand method")
		},
		GetDescriptionFunc: func() string {
			panic("mock out the GetDescription method")
		},
		GetNameFunc: func() string {
			panic("mock out the GetName method")
		},
		IsShellFunc: func() bool {
			panic("mock out the IsShell method")
		},
	}

	// use mockedAlias in code that requires Alias
	// and then make assertions.

}

func (*AliasMock) GetCommand

func (mock *AliasMock) GetCommand() string

GetCommand calls GetCommandFunc.

func (*AliasMock) GetCommandCalls

func (mock *AliasMock) GetCommandCalls() []struct {
}

GetCommandCalls gets all the calls that were made to GetCommand. Check the length with:

len(mockedAlias.GetCommandCalls())

func (*AliasMock) GetDescription

func (mock *AliasMock) GetDescription() string

GetDescription calls GetDescriptionFunc.

func (*AliasMock) GetDescriptionCalls

func (mock *AliasMock) GetDescriptionCalls() []struct {
}

GetDescriptionCalls gets all the calls that were made to GetDescription. Check the length with:

len(mockedAlias.GetDescriptionCalls())

func (*AliasMock) GetName

func (mock *AliasMock) GetName() string

GetName calls GetNameFunc.

func (*AliasMock) GetNameCalls

func (mock *AliasMock) GetNameCalls() []struct {
}

GetNameCalls gets all the calls that were made to GetName. Check the length with:

len(mockedAlias.GetNameCalls())

func (*AliasMock) IsShell

func (mock *AliasMock) IsShell() bool

IsShell calls IsShellFunc.

func (*AliasMock) IsShellCalls

func (mock *AliasMock) IsShellCalls() []struct {
}

IsShellCalls gets all the calls that were made to IsShell. Check the length with:

len(mockedAlias.IsShellCalls())

type BinaryCommand added in v2.57.0

type BinaryCommand struct {
	// Name is the space separated command path under the extension name, e.g. "services list"
	Name string `json:"name" yaml:"name"`

	// Description shown in the help
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Exec are the arguments passed to the binary before the user's arguments.
	// Defaults to the name split on spaces
	Exec []string `json:"exec,omitempty" yaml:"exec,omitempty"`

	// Output mode: raw (default) or json
	Output string `json:"output,omitempty" yaml:"output,omitempty"`
}

BinaryCommand is a command which is provided by the extension's binary

func (*BinaryCommand) ExecArgs added in v2.57.0

func (c *BinaryCommand) ExecArgs() []string

ExecArgs returns the arguments which are passed to the binary before the user's arguments

func (*BinaryCommand) IsJSON added in v2.57.0

func (c *BinaryCommand) IsJSON() bool

IsJSON returns true if the command output should be processed by c8y

func (*BinaryCommand) Path added in v2.57.0

func (c *BinaryCommand) Path() []string

Path returns the command path as a list of command names

type BinarySpec added in v2.57.0

type BinarySpec struct {
	// Path to the binary, relative to the extension folder. Defaults to bin/<extension-dir-name>
	Path string `json:"path,omitempty" yaml:"path,omitempty"`

	// Mount is the space separated command path (under the extension name) where all
	// unknown arguments are passed to the binary. Defaults to the extension root
	Mount string `json:"mount,omitempty" yaml:"mount,omitempty"`

	// Completion mode: cobra or none (default)
	Completion string `json:"completion,omitempty" yaml:"completion,omitempty"`
}

BinarySpec declares the binary provided by an extension

func (*BinarySpec) CompletionEnabled added in v2.57.0

func (b *BinarySpec) CompletionEnabled() bool

CompletionEnabled returns true if completion requests should be forwarded to the binary

func (*BinarySpec) MountPath added in v2.57.0

func (b *BinarySpec) MountPath() []string

MountPath returns the mount as a list of command names

type Command

type Command interface {
	Command() string
	Name() string
	Description() string
}

type ExecOptions added in v2.57.0

type ExecOptions struct {
	// Executable to run
	Executable string

	// Args passed to the executable
	Args []string

	// IsBinary runs the executable directly on all platforms. Otherwise it is
	// treated as a script, which is run via sh on Windows to support shebang lines
	IsBinary bool

	// Env is the environment of the process. The current environment is used if nil
	Env []string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ExecOptions are the options to run an extension command

type ExtTemplateType

type ExtTemplateType int
const (
	GitTemplateType      ExtTemplateType = 0
	GoBinTemplateType    ExtTemplateType = 1
	OtherBinTemplateType ExtTemplateType = 2
)

type Extension

type Extension interface {
	Name() string // Extension Name without c8y-
	Path() string // Path to the extension folder
	URL() string
	CurrentVersion() string
	IsPinned() bool
	UpdateAvailable() bool
	IsBinary() bool
	IsLocal() bool

	// Kind is how the extension was installed (git, local, binary or system)
	Kind() Kind

	// Executable returns the absolute path to the extension's binary, as declared in the
	// extension manifest (extension.yaml). It is empty if the extension does not declare a binary.
	// The file is not checked for existence.
	Executable() string

	// Manifest returns the parsed extension manifest (extension.yaml). An empty manifest
	// is returned if the extension does not have one
	Manifest() (*Manifest, error)

	// Extension components
	TemplatePath() string
	ViewPath() string
	Aliases() ([]Alias, error)
	Commands() ([]Command, error)
}

type ExtensionManager

type ExtensionManager interface {
	List() []Extension

	// Install installs an extension from a repository, and returns the name it was installed as
	Install(repo ghrepo.Interface, opts InstallOptions) (string, error)

	// InstallLocal installs an extension from a local folder, and returns the name it was installed as
	InstallLocal(dir string, opts InstallOptions) (string, error)
	Upgrade(name string, force bool) error
	Remove(name string) error
	Execute(opts ExecOptions) error
	Create(name string, tmplType ExtTemplateType) error
	EnableDryRunMode()
}

type ExtensionManagerMock

type ExtensionManagerMock struct {
	// CreateFunc mocks the Create method.
	CreateFunc func(name string, tmplType ExtTemplateType) error

	// EnableDryRunModeFunc mocks the EnableDryRunMode method.
	EnableDryRunModeFunc func()

	// ExecuteFunc mocks the Execute method.
	ExecuteFunc func(opts ExecOptions) error

	// InstallFunc mocks the Install method.
	InstallFunc func(repo ghrepo.Interface, opts InstallOptions) (string, error)

	// InstallLocalFunc mocks the InstallLocal method.
	InstallLocalFunc func(dir string, opts InstallOptions) (string, error)

	// ListFunc mocks the List method.
	ListFunc func() []Extension

	// RemoveFunc mocks the Remove method.
	RemoveFunc func(name string) error

	// UpgradeFunc mocks the Upgrade method.
	UpgradeFunc func(name string, force bool) error
	// contains filtered or unexported fields
}

ExtensionManagerMock is a mock implementation of ExtensionManager.

func TestSomethingThatUsesExtensionManager(t *testing.T) {

	// make and configure a mocked ExtensionManager
	mockedExtensionManager := &ExtensionManagerMock{
		CreateFunc: func(name string, tmplType ExtTemplateType) error {
			panic("mock out the Create method")
		},
		EnableDryRunModeFunc: func()  {
			panic("mock out the EnableDryRunMode method")
		},
		ExecuteFunc: func(opts ExecOptions) error {
			panic("mock out the Execute method")
		},
		InstallFunc: func(repo ghrepo.Interface, opts InstallOptions) (string, error) {
			panic("mock out the Install method")
		},
		InstallLocalFunc: func(dir string, opts InstallOptions) (string, error) {
			panic("mock out the InstallLocal method")
		},
		ListFunc: func() []Extension {
			panic("mock out the List method")
		},
		RemoveFunc: func(name string) error {
			panic("mock out the Remove method")
		},
		UpgradeFunc: func(name string, force bool) error {
			panic("mock out the Upgrade method")
		},
	}

	// use mockedExtensionManager in code that requires ExtensionManager
	// and then make assertions.

}

func (*ExtensionManagerMock) Create

func (mock *ExtensionManagerMock) Create(name string, tmplType ExtTemplateType) error

Create calls CreateFunc.

func (*ExtensionManagerMock) CreateCalls

func (mock *ExtensionManagerMock) CreateCalls() []struct {
	Name     string
	TmplType ExtTemplateType
}

CreateCalls gets all the calls that were made to Create. Check the length with:

len(mockedExtensionManager.CreateCalls())

func (*ExtensionManagerMock) EnableDryRunMode

func (mock *ExtensionManagerMock) EnableDryRunMode()

EnableDryRunMode calls EnableDryRunModeFunc.

func (*ExtensionManagerMock) EnableDryRunModeCalls

func (mock *ExtensionManagerMock) EnableDryRunModeCalls() []struct {
}

EnableDryRunModeCalls gets all the calls that were made to EnableDryRunMode. Check the length with:

len(mockedExtensionManager.EnableDryRunModeCalls())

func (*ExtensionManagerMock) Execute

func (mock *ExtensionManagerMock) Execute(opts ExecOptions) error

Execute calls ExecuteFunc.

func (*ExtensionManagerMock) ExecuteCalls

func (mock *ExtensionManagerMock) ExecuteCalls() []struct {
	Opts ExecOptions
}

ExecuteCalls gets all the calls that were made to Execute. Check the length with:

len(mockedExtensionManager.ExecuteCalls())

func (*ExtensionManagerMock) Install

func (mock *ExtensionManagerMock) Install(repo ghrepo.Interface, opts InstallOptions) (string, error)

Install calls InstallFunc.

func (*ExtensionManagerMock) InstallCalls

func (mock *ExtensionManagerMock) InstallCalls() []struct {
	Repo ghrepo.Interface
	Opts InstallOptions
}

InstallCalls gets all the calls that were made to Install. Check the length with:

len(mockedExtensionManager.InstallCalls())

func (*ExtensionManagerMock) InstallLocal

func (mock *ExtensionManagerMock) InstallLocal(dir string, opts InstallOptions) (string, error)

InstallLocal calls InstallLocalFunc.

func (*ExtensionManagerMock) InstallLocalCalls

func (mock *ExtensionManagerMock) InstallLocalCalls() []struct {
	Dir  string
	Opts InstallOptions
}

InstallLocalCalls gets all the calls that were made to InstallLocal. Check the length with:

len(mockedExtensionManager.InstallLocalCalls())

func (*ExtensionManagerMock) List

func (mock *ExtensionManagerMock) List() []Extension

List calls ListFunc.

func (*ExtensionManagerMock) ListCalls

func (mock *ExtensionManagerMock) ListCalls() []struct {
}

ListCalls gets all the calls that were made to List. Check the length with:

len(mockedExtensionManager.ListCalls())

func (*ExtensionManagerMock) Remove

func (mock *ExtensionManagerMock) Remove(name string) error

Remove calls RemoveFunc.

func (*ExtensionManagerMock) RemoveCalls

func (mock *ExtensionManagerMock) RemoveCalls() []struct {
	Name string
}

RemoveCalls gets all the calls that were made to Remove. Check the length with:

len(mockedExtensionManager.RemoveCalls())

func (*ExtensionManagerMock) Upgrade

func (mock *ExtensionManagerMock) Upgrade(name string, force bool) error

Upgrade calls UpgradeFunc.

func (*ExtensionManagerMock) UpgradeCalls

func (mock *ExtensionManagerMock) UpgradeCalls() []struct {
	Name  string
	Force bool
}

UpgradeCalls gets all the calls that were made to Upgrade. Check the length with:

len(mockedExtensionManager.UpgradeCalls())

type ExtensionMock

type ExtensionMock struct {
	// AliasesFunc mocks the Aliases method.
	AliasesFunc func() ([]Alias, error)

	// CommandsFunc mocks the Commands method.
	CommandsFunc func() ([]Command, error)

	// CurrentVersionFunc mocks the CurrentVersion method.
	CurrentVersionFunc func() string

	// ExecutableFunc mocks the Executable method.
	ExecutableFunc func() string

	// IsBinaryFunc mocks the IsBinary method.
	IsBinaryFunc func() bool

	// IsLocalFunc mocks the IsLocal method.
	IsLocalFunc func() bool

	// IsPinnedFunc mocks the IsPinned method.
	IsPinnedFunc func() bool

	// KindFunc mocks the Kind method.
	KindFunc func() Kind

	// ManifestFunc mocks the Manifest method.
	ManifestFunc func() (*Manifest, error)

	// NameFunc mocks the Name method.
	NameFunc func() string

	// PathFunc mocks the Path method.
	PathFunc func() string

	// TemplatePathFunc mocks the TemplatePath method.
	TemplatePathFunc func() string

	// URLFunc mocks the URL method.
	URLFunc func() string

	// UpdateAvailableFunc mocks the UpdateAvailable method.
	UpdateAvailableFunc func() bool

	// ViewPathFunc mocks the ViewPath method.
	ViewPathFunc func() string
	// contains filtered or unexported fields
}

ExtensionMock is a mock implementation of Extension.

func TestSomethingThatUsesExtension(t *testing.T) {

	// make and configure a mocked Extension
	mockedExtension := &ExtensionMock{
		AliasesFunc: func() ([]Alias, error) {
			panic("mock out the Aliases method")
		},
		CommandsFunc: func() ([]Command, error) {
			panic("mock out the Commands method")
		},
		CurrentVersionFunc: func() string {
			panic("mock out the CurrentVersion method")
		},
		ExecutableFunc: func() string {
			panic("mock out the Executable method")
		},
		IsBinaryFunc: func() bool {
			panic("mock out the IsBinary method")
		},
		IsLocalFunc: func() bool {
			panic("mock out the IsLocal method")
		},
		IsPinnedFunc: func() bool {
			panic("mock out the IsPinned method")
		},
		KindFunc: func() Kind {
			panic("mock out the Kind method")
		},
		ManifestFunc: func() (*Manifest, error) {
			panic("mock out the Manifest method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		PathFunc: func() string {
			panic("mock out the Path method")
		},
		TemplatePathFunc: func() string {
			panic("mock out the TemplatePath method")
		},
		URLFunc: func() string {
			panic("mock out the URL method")
		},
		UpdateAvailableFunc: func() bool {
			panic("mock out the UpdateAvailable method")
		},
		ViewPathFunc: func() string {
			panic("mock out the ViewPath method")
		},
	}

	// use mockedExtension in code that requires Extension
	// and then make assertions.

}

func (*ExtensionMock) Aliases

func (mock *ExtensionMock) Aliases() ([]Alias, error)

Aliases calls AliasesFunc.

func (*ExtensionMock) AliasesCalls

func (mock *ExtensionMock) AliasesCalls() []struct {
}

AliasesCalls gets all the calls that were made to Aliases. Check the length with:

len(mockedExtension.AliasesCalls())

func (*ExtensionMock) Commands

func (mock *ExtensionMock) Commands() ([]Command, error)

Commands calls CommandsFunc.

func (*ExtensionMock) CommandsCalls

func (mock *ExtensionMock) CommandsCalls() []struct {
}

CommandsCalls gets all the calls that were made to Commands. Check the length with:

len(mockedExtension.CommandsCalls())

func (*ExtensionMock) CurrentVersion

func (mock *ExtensionMock) CurrentVersion() string

CurrentVersion calls CurrentVersionFunc.

func (*ExtensionMock) CurrentVersionCalls

func (mock *ExtensionMock) CurrentVersionCalls() []struct {
}

CurrentVersionCalls gets all the calls that were made to CurrentVersion. Check the length with:

len(mockedExtension.CurrentVersionCalls())

func (*ExtensionMock) Executable added in v2.57.0

func (mock *ExtensionMock) Executable() string

Executable calls ExecutableFunc.

func (*ExtensionMock) ExecutableCalls added in v2.57.0

func (mock *ExtensionMock) ExecutableCalls() []struct {
}

ExecutableCalls gets all the calls that were made to Executable. Check the length with:

len(mockedExtension.ExecutableCalls())

func (*ExtensionMock) IsBinary

func (mock *ExtensionMock) IsBinary() bool

IsBinary calls IsBinaryFunc.

func (*ExtensionMock) IsBinaryCalls

func (mock *ExtensionMock) IsBinaryCalls() []struct {
}

IsBinaryCalls gets all the calls that were made to IsBinary. Check the length with:

len(mockedExtension.IsBinaryCalls())

func (*ExtensionMock) IsLocal

func (mock *ExtensionMock) IsLocal() bool

IsLocal calls IsLocalFunc.

func (*ExtensionMock) IsLocalCalls

func (mock *ExtensionMock) IsLocalCalls() []struct {
}

IsLocalCalls gets all the calls that were made to IsLocal. Check the length with:

len(mockedExtension.IsLocalCalls())

func (*ExtensionMock) IsPinned

func (mock *ExtensionMock) IsPinned() bool

IsPinned calls IsPinnedFunc.

func (*ExtensionMock) IsPinnedCalls

func (mock *ExtensionMock) IsPinnedCalls() []struct {
}

IsPinnedCalls gets all the calls that were made to IsPinned. Check the length with:

len(mockedExtension.IsPinnedCalls())

func (*ExtensionMock) Kind added in v2.57.0

func (mock *ExtensionMock) Kind() Kind

Kind calls KindFunc.

func (*ExtensionMock) KindCalls added in v2.57.0

func (mock *ExtensionMock) KindCalls() []struct {
}

KindCalls gets all the calls that were made to Kind. Check the length with:

len(mockedExtension.KindCalls())

func (*ExtensionMock) Manifest added in v2.57.0

func (mock *ExtensionMock) Manifest() (*Manifest, error)

Manifest calls ManifestFunc.

func (*ExtensionMock) ManifestCalls added in v2.57.0

func (mock *ExtensionMock) ManifestCalls() []struct {
}

ManifestCalls gets all the calls that were made to Manifest. Check the length with:

len(mockedExtension.ManifestCalls())

func (*ExtensionMock) Name

func (mock *ExtensionMock) Name() string

Name calls NameFunc.

func (*ExtensionMock) NameCalls

func (mock *ExtensionMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedExtension.NameCalls())

func (*ExtensionMock) Path

func (mock *ExtensionMock) Path() string

Path calls PathFunc.

func (*ExtensionMock) PathCalls

func (mock *ExtensionMock) PathCalls() []struct {
}

PathCalls gets all the calls that were made to Path. Check the length with:

len(mockedExtension.PathCalls())

func (*ExtensionMock) TemplatePath

func (mock *ExtensionMock) TemplatePath() string

TemplatePath calls TemplatePathFunc.

func (*ExtensionMock) TemplatePathCalls

func (mock *ExtensionMock) TemplatePathCalls() []struct {
}

TemplatePathCalls gets all the calls that were made to TemplatePath. Check the length with:

len(mockedExtension.TemplatePathCalls())

func (*ExtensionMock) URL

func (mock *ExtensionMock) URL() string

URL calls URLFunc.

func (*ExtensionMock) URLCalls

func (mock *ExtensionMock) URLCalls() []struct {
}

URLCalls gets all the calls that were made to URL. Check the length with:

len(mockedExtension.URLCalls())

func (*ExtensionMock) UpdateAvailable

func (mock *ExtensionMock) UpdateAvailable() bool

UpdateAvailable calls UpdateAvailableFunc.

func (*ExtensionMock) UpdateAvailableCalls

func (mock *ExtensionMock) UpdateAvailableCalls() []struct {
}

UpdateAvailableCalls gets all the calls that were made to UpdateAvailable. Check the length with:

len(mockedExtension.UpdateAvailableCalls())

func (*ExtensionMock) ViewPath

func (mock *ExtensionMock) ViewPath() string

ViewPath calls ViewPathFunc.

func (*ExtensionMock) ViewPathCalls

func (mock *ExtensionMock) ViewPathCalls() []struct {
}

ViewPathCalls gets all the calls that were made to ViewPath. Check the length with:

len(mockedExtension.ViewPathCalls())

type InstallOptions added in v2.57.0

type InstallOptions struct {
	// Name set by the user (--name). It takes precedence over the name declared in
	// extension.yaml and the repository or folder name
	Name string

	// Pin is the release tag or commit to install (remote installs only)
	Pin string

	// CheckName is called with the resolved name (without the c8y- prefix) before the
	// extension is moved into place. The install fails if it returns an error
	CheckName func(name string) error
}

InstallOptions are the options of an extension install

type InstalledSessionProvider added in v2.57.0

type InstalledSessionProvider struct {
	Extension Extension
	Provider  SessionProvider
}

InstalledSessionProvider is a session provider of an installed extension

func ListSessionProviders added in v2.57.0

func ListSessionProviders(exts []Extension, warn func(ext Extension, msg string)) []InstalledSessionProvider

ListSessionProviders returns the session providers of the given extensions, sorted by their qualified reference. warn is called for each ignored provider (it can be nil)

func ResolveSessionProvider added in v2.57.0

func ResolveSessionProvider(providers []InstalledSessionProvider, ref string) (*InstalledSessionProvider, error)

ResolveSessionProvider finds a session provider by its reference, either <provider> (if only one extension provides a provider with that name) or <extension>/<provider>

func (InstalledSessionProvider) Ref added in v2.57.0

Ref returns the qualified reference of the provider: <extension>/<provider>

type Kind added in v2.57.0

type Kind string

Kind is how an extension was installed

const (
	KindGit    Kind = "git"
	KindLocal  Kind = "local"
	KindBinary Kind = "binary"
	// KindSystem is an extension in a system-wide extensions folder, installed by a package manager
	KindSystem Kind = "system"
)

type Manifest added in v2.57.0

type Manifest struct {
	Version string `json:"version,omitempty" yaml:"version,omitempty"`

	// Name is the extension name (without the c8y- prefix), which is used when the extension is
	// installed, unless the user passes --name. See NormalizeName
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// Binary declares an executable provided by the extension
	Binary *BinarySpec `json:"binary,omitempty" yaml:"binary,omitempty"`

	// Commands declares commands which are provided by the binary
	Commands []BinaryCommand `json:"commands,omitempty" yaml:"commands,omitempty"`

	// SessionProviders declares session providers which are provided by the binary
	SessionProviders []SessionProvider `json:"sessionProviders,omitempty" yaml:"sessionProviders,omitempty"`
}

Manifest is the extension manifest file (extension.yaml)

func (*Manifest) ValidSessionProviders added in v2.57.0

func (m *Manifest) ValidSessionProviders() ([]SessionProvider, []string)

ValidSessionProviders returns the usable session providers of the manifest, and warnings for providers which are ignored: all providers if no binary is declared, providers with an invalid name or format, and duplicate names (the first one is used)

type SessionProvider added in v2.57.0

type SessionProvider struct {
	// Name of the provider
	Name string `json:"name" yaml:"name"`

	// Description shown in the completion
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Exec are the arguments passed to the binary before the provider flags
	Exec []string `json:"exec,omitempty" yaml:"exec,omitempty"`

	// Secrets are the names of environment variables which the provider needs
	Secrets []string `json:"secrets,omitempty" yaml:"secrets,omitempty"`

	// Format of the provider output: json, dotenv or auto (default)
	Format string `json:"format,omitempty" yaml:"format,omitempty"`
}

SessionProvider is a session provider which is run by "c8y sessions login" to select a session

func (*SessionProvider) OutputFormat added in v2.57.0

func (p *SessionProvider) OutputFormat() string

OutputFormat returns the declared output format, or an empty string for automatic detection

type Template

type Template interface {
	Path() string
	Name() string
}

type View

type View interface {
	Path() string
	Name() string
}

Directories

Path Synopsis
Package cmdtree builds the command tree of an extension from multiple command sources (e.g.
Package cmdtree builds the command tree of an extension from multiple command sources (e.g.

Jump to

Keyboard shortcuts

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