Documentation
¶
Index ¶
- Constants
- Variables
- func MergeEnv(base []string, set map[string]string, unset map[string]bool) []string
- func NormalizeName(name string) (string, error)
- func SessionProviderCompletions(providers []InstalledSessionProvider) []string
- func Variables(ext Extension, fallbackBin string) map[string]string
- type Alias
- type AliasMock
- func (mock *AliasMock) GetCommand() string
- func (mock *AliasMock) GetCommandCalls() []struct{}
- func (mock *AliasMock) GetDescription() string
- func (mock *AliasMock) GetDescriptionCalls() []struct{}
- func (mock *AliasMock) GetName() string
- func (mock *AliasMock) GetNameCalls() []struct{}
- func (mock *AliasMock) IsShell() bool
- func (mock *AliasMock) IsShellCalls() []struct{}
- type BinaryCommand
- type BinarySpec
- type Command
- type ExecOptions
- type ExtTemplateType
- type Extension
- type ExtensionManager
- type ExtensionManagerMock
- func (mock *ExtensionManagerMock) Create(name string, tmplType ExtTemplateType) error
- func (mock *ExtensionManagerMock) CreateCalls() []struct{ ... }
- func (mock *ExtensionManagerMock) EnableDryRunMode()
- func (mock *ExtensionManagerMock) EnableDryRunModeCalls() []struct{}
- func (mock *ExtensionManagerMock) Execute(opts ExecOptions) error
- func (mock *ExtensionManagerMock) ExecuteCalls() []struct{ ... }
- func (mock *ExtensionManagerMock) Install(repo ghrepo.Interface, opts InstallOptions) (string, error)
- func (mock *ExtensionManagerMock) InstallCalls() []struct{ ... }
- func (mock *ExtensionManagerMock) InstallLocal(dir string, opts InstallOptions) (string, error)
- func (mock *ExtensionManagerMock) InstallLocalCalls() []struct{ ... }
- func (mock *ExtensionManagerMock) List() []Extension
- func (mock *ExtensionManagerMock) ListCalls() []struct{}
- func (mock *ExtensionManagerMock) Remove(name string) error
- func (mock *ExtensionManagerMock) RemoveCalls() []struct{ ... }
- func (mock *ExtensionManagerMock) Upgrade(name string, force bool) error
- func (mock *ExtensionManagerMock) UpgradeCalls() []struct{ ... }
- type ExtensionMock
- func (mock *ExtensionMock) Aliases() ([]Alias, error)
- func (mock *ExtensionMock) AliasesCalls() []struct{}
- func (mock *ExtensionMock) Commands() ([]Command, error)
- func (mock *ExtensionMock) CommandsCalls() []struct{}
- func (mock *ExtensionMock) CurrentVersion() string
- func (mock *ExtensionMock) CurrentVersionCalls() []struct{}
- func (mock *ExtensionMock) Executable() string
- func (mock *ExtensionMock) ExecutableCalls() []struct{}
- func (mock *ExtensionMock) IsBinary() bool
- func (mock *ExtensionMock) IsBinaryCalls() []struct{}
- func (mock *ExtensionMock) IsLocal() bool
- func (mock *ExtensionMock) IsLocalCalls() []struct{}
- func (mock *ExtensionMock) IsPinned() bool
- func (mock *ExtensionMock) IsPinnedCalls() []struct{}
- func (mock *ExtensionMock) Kind() Kind
- func (mock *ExtensionMock) KindCalls() []struct{}
- func (mock *ExtensionMock) Manifest() (*Manifest, error)
- func (mock *ExtensionMock) ManifestCalls() []struct{}
- func (mock *ExtensionMock) Name() string
- func (mock *ExtensionMock) NameCalls() []struct{}
- func (mock *ExtensionMock) Path() string
- func (mock *ExtensionMock) PathCalls() []struct{}
- func (mock *ExtensionMock) TemplatePath() string
- func (mock *ExtensionMock) TemplatePathCalls() []struct{}
- func (mock *ExtensionMock) URL() string
- func (mock *ExtensionMock) URLCalls() []struct{}
- func (mock *ExtensionMock) UpdateAvailable() bool
- func (mock *ExtensionMock) UpdateAvailableCalls() []struct{}
- func (mock *ExtensionMock) ViewPath() string
- func (mock *ExtensionMock) ViewPathCalls() []struct{}
- type InstallOptions
- type InstalledSessionProvider
- type Kind
- type Manifest
- type ProviderSession
- type SessionProvider
- type Template
- type View
Constants ¶
const ( ProviderFormatAuto = "auto" ProviderFormatJSON = "json" ProviderFormatDotenv = "dotenv" )
Session provider output formats
const ( CompletionNone = "none" CompletionCobra = "cobra" )
Binary completion modes
const ( OutputRaw = "raw" OutputJSON = "json" )
Binary command output modes
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" // EnvNullInput is "true" when the extension should not read stdin, e.g. to detect piped // input (set by --nullInput/-n). c8y commands don't use it, so the pipes within a script // still work, but it is inherited by the extension commands which the extension runs EnvNullInput = "C8Y_EXTENSION_NULL_INPUT" )
const CommandAnnotation = "c8y.extension"
CommandAnnotation is the annotation which marks the root command of an extension. Its value is the extension name
const FileSessionProvider = "file"
FileSessionProvider is a reserved session provider name, which refers to the session files in the session home folder (the same name as the "file" session provider type), e.g. in "c8y mcp serve --sessionProvider file"
const NameFormat = "^[a-z0-9][a-z0-9-]*$"
NameFormat is the format of a normalized extension name
const NamePrefix = "c8y-"
NamePrefix is the prefix of the extension folders. It's not part of the extension name
Variables ¶
var ErrAmbiguousSessionProvider = errors.New("ambiguous session provider")
ErrAmbiguousSessionProvider is returned when a short provider name is provided by more than one extension
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
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
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
Types ¶
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 ¶
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 ¶
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) 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) 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 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) 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) 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) 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
func (p InstalledSessionProvider) Ref() string
Ref returns the qualified reference of the provider: <extension>/<provider>
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 ProviderSession ¶ added in v2.58.0
type ProviderSession struct {
// SessionURI identifies the session within the provider, e.g. "bitwarden://<item-id>". It is
// passed to the provider's select command
SessionURI string `json:"sessionUri"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Host string `json:"host"`
Tenant string `json:"tenant,omitempty"`
Username string `json:"username,omitempty"`
Mode string `json:"mode,omitempty"`
LoginType string `json:"loginType,omitempty"`
// Group is an optional grouping shown to the user, e.g. the folder of the vault
Group string `json:"group,omitempty"`
}
ProviderSession is a session listed by a session provider (see SessionProvider.List). It does not contain any secrets: secret properties in the provider's output are ignored
func ParseProviderSessions ¶ added in v2.58.0
func ParseProviderSessions(data []byte) ([]ProviderSession, []string, error)
ParseProviderSessions parses the output of a provider's list command: a json array of sessions. Sessions without a sessionUri or host are skipped, and returned as warnings
func (ProviderSession) DisplayName ¶ added in v2.58.0
func (s ProviderSession) DisplayName() string
DisplayName returns the name shown to the user
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"`
// List are the arguments which make the binary print the provider's sessions as a json
// array, without secrets and without user interaction. It is used to show the sessions in
// other pickers, e.g. the browser session picker of "c8y mcp serve". Requires Select
List []string `json:"list,omitempty" yaml:"list,omitempty"`
// Select are the arguments which make the binary print one session, given by its
// sessionUri (which is appended to the arguments), without user interaction. Requires List
Select []string `json:"select,omitempty" yaml:"select,omitempty"`
}
SessionProvider is a session provider which is run by "c8y sessions login" to select a session
func (*SessionProvider) CanList ¶ added in v2.58.0
func (p *SessionProvider) CanList() bool
CanList returns true if the provider can list its sessions and select one by its sessionUri without user interaction
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