Documentation
¶
Overview ¶
Package lua provides the Lua runtime for revoco plugins.
This package embeds a sandboxed Lua interpreter using gopher-lua, providing a safe environment for user-created plugins.
Index ¶
- Variables
- func CreateLuaPlugin(dp *plugins.DiscoveredPlugin) (plugins.Plugin, error)
- func LoadPluginFromFile(ctx context.Context, path string) (plugins.Plugin, error)
- type HTTPConfig
- type LuaConnector
- func (c *LuaConnector) AuthType() string
- func (c *LuaConnector) Capabilities() []core.ConnectorCapability
- func (c *LuaConnector) Close() error
- func (c *LuaConnector) ConfigSchema() []core.ConfigOption
- func (c *LuaConnector) Delete(ctx context.Context, item core.DataItem) error
- func (c *LuaConnector) Description() string
- func (c *LuaConnector) FallbackOptions() []core.FallbackOption
- func (c *LuaConnector) ID() string
- func (c *LuaConnector) Initialize(ctx context.Context, cfg core.ConnectorConfig) error
- func (c *LuaConnector) List(ctx context.Context, progress core.ProgressFunc) ([]core.DataItem, error)
- func (c *LuaConnector) Name() string
- func (c *LuaConnector) Plugin() *LuaPlugin
- func (c *LuaConnector) Read(ctx context.Context, item core.DataItem) (io.ReadCloser, error)
- func (c *LuaConnector) ReadTo(ctx context.Context, item core.DataItem, destPath string, mode core.ImportMode) error
- func (c *LuaConnector) RequiresAuth() bool
- func (c *LuaConnector) SupportedDataTypes() []core.DataType
- func (c *LuaConnector) TestConnection(ctx context.Context, cfg core.ConnectorConfig) error
- func (c *LuaConnector) ValidateConfig(cfg core.ConnectorConfig) error
- func (c *LuaConnector) Write(ctx context.Context, item core.DataItem, reader io.Reader) error
- func (c *LuaConnector) WriteBatch(ctx context.Context, items []core.DataItem, ...) error
- func (c *LuaConnector) WriteFrom(ctx context.Context, item core.DataItem, sourcePath string) error
- type LuaConnectorPlugin
- type LuaOutput
- func (o *LuaOutput) CanOutput(item *core.DataItem) bool
- func (o *LuaOutput) ConfigSchema() []svccore.ConfigOption
- func (o *LuaOutput) Description() string
- func (o *LuaOutput) Export(ctx context.Context, item svccore.ProcessedItem) error
- func (o *LuaOutput) ExportBatch(ctx context.Context, items []svccore.ProcessedItem, ...) error
- func (o *LuaOutput) Finalize(ctx context.Context) error
- func (o *LuaOutput) ID() string
- func (o *LuaOutput) Initialize(ctx context.Context, cfg svccore.OutputConfig) error
- func (o *LuaOutput) Name() string
- func (o *LuaOutput) Plugin() *LuaPlugin
- func (o *LuaOutput) Selector() *plugins.Selector
- func (o *LuaOutput) SupportedItemTypes() []string
- type LuaOutputPlugin
- type LuaPlugin
- func (p *LuaPlugin) CallFunction(name string, args ...lua.LValue) ([]lua.LValue, error)
- func (p *LuaPlugin) ConfigToLua(config map[string]any) *lua.LTable
- func (p *LuaPlugin) DataItemToLua(item *core.DataItem) *lua.LTable
- func (p *LuaPlugin) EvaluateCondition(item *core.DataItem, condition string) (bool, error)
- func (p *LuaPlugin) HasFunction(name string) bool
- func (p *LuaPlugin) Info() plugins.PluginInfo
- func (p *LuaPlugin) Load(ctx context.Context) error
- func (p *LuaPlugin) LuaToDataItem(tbl *lua.LTable) *core.DataItem
- func (p *LuaPlugin) Reload(ctx context.Context) error
- func (p *LuaPlugin) Selector() *plugins.Selector
- func (p *LuaPlugin) Unload() error
- type LuaProcessor
- func (p *LuaProcessor) CanProcess(item *core.DataItem) bool
- func (p *LuaProcessor) ConfigSchema() []plugins.ConfigOption
- func (p *LuaProcessor) DefaultSelector() *plugins.Selector
- func (p *LuaProcessor) Description() string
- func (p *LuaProcessor) ID() string
- func (p *LuaProcessor) Name() string
- func (p *LuaProcessor) Plugin() *LuaPlugin
- func (p *LuaProcessor) Process(ctx context.Context, item *core.DataItem, config map[string]any) (*core.DataItem, error)
- func (p *LuaProcessor) ProcessBatch(ctx context.Context, items []*core.DataItem, config map[string]any, ...) ([]*core.DataItem, error)
- type LuaProcessorPlugin
- type PluginManager
- func (pm *PluginManager) AllPlugins() []*LuaPlugin
- func (pm *PluginManager) GetPlugin(path string) (*LuaPlugin, bool)
- func (pm *PluginManager) LoadAndWatch(ctx context.Context, path string) (*LuaPlugin, error)
- func (pm *PluginManager) Start()
- func (pm *PluginManager) Stop() error
- func (pm *PluginManager) UnloadPlugin(path string) error
- type PluginWatcher
- func (pw *PluginWatcher) SetOnError(fn func(err error))
- func (pw *PluginWatcher) SetOnReload(fn func(plugin *LuaPlugin, err error))
- func (pw *PluginWatcher) Start()
- func (pw *PluginWatcher) Stop() error
- func (pw *PluginWatcher) Unwatch(plugin *LuaPlugin)
- func (pw *PluginWatcher) Watch(plugin *LuaPlugin) error
- func (pw *PluginWatcher) WatchedPlugins() []*LuaPlugin
- type Runtime
- type StatePool
- type WatcherConfig
Constants ¶
This section is empty.
Variables ¶
var AllowedBinaries = map[string]bool{ "exiftool": true, "ffmpeg": true, "ffprobe": true, "convert": true, "identify": true, "magick": true, "gpg": true, "openssl": true, }
AllowedBinaries is the list of binaries that plugins can execute. This provides a security boundary.
var AllowedDomains = map[string]bool{ "www.googleapis.com": true, "photoslibrary.googleapis.com": true, "oauth2.googleapis.com": true, "accounts.google.com": true, "api.dropbox.com": true, "content.dropboxapi.com": true, "graph.microsoft.com": true, "api.onedrive.com": true, "api.flickr.com": true, "api.smugmug.com": true, "api.spotify.com": true, "api.music.apple.com": true, "localhost": true, "127.0.0.1": true, }
AllowedDomains is the list of domains that plugins can make HTTP requests to. This provides a security boundary for network access.
Functions ¶
func CreateLuaPlugin ¶
func CreateLuaPlugin(dp *plugins.DiscoveredPlugin) (plugins.Plugin, error)
CreateLuaPlugin creates a Lua plugin from discovered metadata. This is the factory function registered with the plugin loader.
Types ¶
type HTTPConfig ¶
HTTPConfig holds HTTP client configuration for the Lua runtime.
func DefaultHTTPConfig ¶
func DefaultHTTPConfig() HTTPConfig
DefaultHTTPConfig returns the default HTTP configuration.
type LuaConnector ¶
type LuaConnector struct {
// contains filtered or unexported fields
}
LuaConnector adapts a LuaPlugin to the connector interfaces.
func NewLuaConnector ¶
func NewLuaConnector(plugin *LuaPlugin) *LuaConnector
NewLuaConnector creates a connector adapter for a Lua plugin.
func (*LuaConnector) AuthType ¶
func (c *LuaConnector) AuthType() string
func (*LuaConnector) Capabilities ¶
func (c *LuaConnector) Capabilities() []core.ConnectorCapability
func (*LuaConnector) Close ¶
func (c *LuaConnector) Close() error
func (*LuaConnector) ConfigSchema ¶
func (c *LuaConnector) ConfigSchema() []core.ConfigOption
func (*LuaConnector) Description ¶
func (c *LuaConnector) Description() string
func (*LuaConnector) FallbackOptions ¶
func (c *LuaConnector) FallbackOptions() []core.FallbackOption
func (*LuaConnector) ID ¶
func (c *LuaConnector) ID() string
func (*LuaConnector) Initialize ¶
func (c *LuaConnector) Initialize(ctx context.Context, cfg core.ConnectorConfig) error
func (*LuaConnector) List ¶
func (c *LuaConnector) List(ctx context.Context, progress core.ProgressFunc) ([]core.DataItem, error)
func (*LuaConnector) Name ¶
func (c *LuaConnector) Name() string
func (*LuaConnector) Plugin ¶
func (c *LuaConnector) Plugin() *LuaPlugin
Plugin returns the underlying plugin.
func (*LuaConnector) Read ¶
func (c *LuaConnector) Read(ctx context.Context, item core.DataItem) (io.ReadCloser, error)
func (*LuaConnector) ReadTo ¶
func (c *LuaConnector) ReadTo(ctx context.Context, item core.DataItem, destPath string, mode core.ImportMode) error
func (*LuaConnector) RequiresAuth ¶
func (c *LuaConnector) RequiresAuth() bool
func (*LuaConnector) SupportedDataTypes ¶
func (c *LuaConnector) SupportedDataTypes() []core.DataType
func (*LuaConnector) TestConnection ¶
func (c *LuaConnector) TestConnection(ctx context.Context, cfg core.ConnectorConfig) error
func (*LuaConnector) ValidateConfig ¶
func (c *LuaConnector) ValidateConfig(cfg core.ConnectorConfig) error
func (*LuaConnector) WriteBatch ¶
type LuaConnectorPlugin ¶
type LuaConnectorPlugin struct {
*LuaPlugin
// contains filtered or unexported fields
}
Ensure LuaPlugin implements ConnectorPlugin when it's a connector.
func NewLuaConnectorPlugin ¶
func NewLuaConnectorPlugin(plugin *LuaPlugin) *LuaConnectorPlugin
func (*LuaConnectorPlugin) AsConnector ¶
func (p *LuaConnectorPlugin) AsConnector() core.Connector
func (*LuaConnectorPlugin) AsReader ¶
func (p *LuaConnectorPlugin) AsReader() (core.ConnectorReader, bool)
func (*LuaConnectorPlugin) AsTester ¶
func (p *LuaConnectorPlugin) AsTester() (core.ConnectorTester, bool)
func (*LuaConnectorPlugin) AsWriter ¶
func (p *LuaConnectorPlugin) AsWriter() (core.ConnectorWriter, bool)
type LuaOutput ¶
type LuaOutput struct {
// contains filtered or unexported fields
}
LuaOutput adapts a LuaPlugin to the Output interface.
func NewLuaOutput ¶
NewLuaOutput creates an output adapter for a Lua plugin.
func (*LuaOutput) ConfigSchema ¶
func (o *LuaOutput) ConfigSchema() []svccore.ConfigOption
func (*LuaOutput) Description ¶
func (*LuaOutput) ExportBatch ¶
func (o *LuaOutput) ExportBatch(ctx context.Context, items []svccore.ProcessedItem, progress svccore.ProgressFunc) error
ExportBatch sends multiple items to the destination.
func (*LuaOutput) Initialize ¶
Initialize prepares the output for use.
func (*LuaOutput) SupportedItemTypes ¶
SupportedItemTypes returns the item types this output can handle.
type LuaOutputPlugin ¶
type LuaOutputPlugin struct {
*LuaPlugin
// contains filtered or unexported fields
}
Ensure LuaPlugin implements OutputPlugin when it's an output.
func NewLuaOutputPlugin ¶
func NewLuaOutputPlugin(plugin *LuaPlugin) *LuaOutputPlugin
func (*LuaOutputPlugin) AsOutput ¶
func (p *LuaOutputPlugin) AsOutput() svccore.Output
func (*LuaOutputPlugin) Selector ¶
func (p *LuaOutputPlugin) Selector() *plugins.Selector
type LuaPlugin ¶
type LuaPlugin struct {
// contains filtered or unexported fields
}
LuaPlugin represents a loaded Lua plugin.
func (*LuaPlugin) CallFunction ¶
CallFunction calls a Lua function by name.
func (*LuaPlugin) ConfigToLua ¶
ConfigToLua converts a config map to a Lua table.
func (*LuaPlugin) DataItemToLua ¶
DataItemToLua converts a DataItem to a Lua table.
func (*LuaPlugin) EvaluateCondition ¶
EvaluateCondition evaluates a Lua condition expression.
func (*LuaPlugin) HasFunction ¶
HasFunction checks if a function exists in the plugin.
func (*LuaPlugin) Info ¶
func (p *LuaPlugin) Info() plugins.PluginInfo
Info returns the plugin metadata.
func (*LuaPlugin) LuaToDataItem ¶
LuaToDataItem converts a Lua table to a DataItem.
type LuaProcessor ¶
type LuaProcessor struct {
// contains filtered or unexported fields
}
LuaProcessor adapts a LuaPlugin to the Processor interface.
func NewLuaProcessor ¶
func NewLuaProcessor(plugin *LuaPlugin) *LuaProcessor
NewLuaProcessor creates a processor adapter for a Lua plugin.
func (*LuaProcessor) CanProcess ¶
func (p *LuaProcessor) CanProcess(item *core.DataItem) bool
func (*LuaProcessor) ConfigSchema ¶
func (p *LuaProcessor) ConfigSchema() []plugins.ConfigOption
func (*LuaProcessor) DefaultSelector ¶
func (p *LuaProcessor) DefaultSelector() *plugins.Selector
func (*LuaProcessor) Description ¶
func (p *LuaProcessor) Description() string
func (*LuaProcessor) ID ¶
func (p *LuaProcessor) ID() string
func (*LuaProcessor) Name ¶
func (p *LuaProcessor) Name() string
func (*LuaProcessor) Plugin ¶
func (p *LuaProcessor) Plugin() *LuaPlugin
Plugin returns the underlying plugin.
func (*LuaProcessor) ProcessBatch ¶
type LuaProcessorPlugin ¶
type LuaProcessorPlugin struct {
*LuaPlugin
// contains filtered or unexported fields
}
Ensure LuaPlugin implements ProcessorPlugin when it's a processor.
func NewLuaProcessorPlugin ¶
func NewLuaProcessorPlugin(plugin *LuaPlugin) *LuaProcessorPlugin
func (*LuaProcessorPlugin) AsProcessor ¶
func (p *LuaProcessorPlugin) AsProcessor() plugins.Processor
func (*LuaProcessorPlugin) Selector ¶
func (p *LuaProcessorPlugin) Selector() *plugins.Selector
type PluginManager ¶
type PluginManager struct {
*Runtime
// contains filtered or unexported fields
}
PluginManager extends Runtime with hot-reload capabilities.
func NewPluginManager ¶
func NewPluginManager() (*PluginManager, error)
NewPluginManager creates a new plugin manager with hot-reload support.
func (*PluginManager) AllPlugins ¶
func (pm *PluginManager) AllPlugins() []*LuaPlugin
AllPlugins returns all loaded plugins.
func (*PluginManager) GetPlugin ¶
func (pm *PluginManager) GetPlugin(path string) (*LuaPlugin, bool)
GetPlugin returns a loaded plugin by path.
func (*PluginManager) LoadAndWatch ¶
LoadAndWatch loads a plugin and starts watching it for changes.
func (*PluginManager) Start ¶
func (pm *PluginManager) Start()
Start starts the plugin manager's file watcher.
func (*PluginManager) UnloadPlugin ¶
func (pm *PluginManager) UnloadPlugin(path string) error
UnloadPlugin unloads a plugin and stops watching it.
type PluginWatcher ¶
type PluginWatcher struct {
// contains filtered or unexported fields
}
PluginWatcher watches plugin files for changes and triggers reloads.
func NewPluginWatcher ¶
func NewPluginWatcher(runtime *Runtime) (*PluginWatcher, error)
NewPluginWatcher creates a new plugin file watcher.
func (*PluginWatcher) SetOnError ¶
func (pw *PluginWatcher) SetOnError(fn func(err error))
SetOnError sets the callback for watcher errors.
func (*PluginWatcher) SetOnReload ¶
func (pw *PluginWatcher) SetOnReload(fn func(plugin *LuaPlugin, err error))
SetOnReload sets the callback for plugin reload events.
func (*PluginWatcher) Start ¶
func (pw *PluginWatcher) Start()
Start begins processing file system events.
func (*PluginWatcher) Unwatch ¶
func (pw *PluginWatcher) Unwatch(plugin *LuaPlugin)
Unwatch stops watching a plugin file.
func (*PluginWatcher) Watch ¶
func (pw *PluginWatcher) Watch(plugin *LuaPlugin) error
Watch starts watching a plugin file for changes.
func (*PluginWatcher) WatchedPlugins ¶
func (pw *PluginWatcher) WatchedPlugins() []*LuaPlugin
WatchedPlugins returns the list of currently watched plugins.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime manages Lua plugin execution.
func (*Runtime) CreateState ¶
CreateState creates a new sandboxed Lua state.
type StatePool ¶
type StatePool struct {
// contains filtered or unexported fields
}
StatePool manages a pool of Lua states.
func NewStatePool ¶
NewStatePool creates a new state pool.
type WatcherConfig ¶
type WatcherConfig struct {
// DebounceDelay is the delay before reloading after a file change.
// This prevents multiple reloads during rapid saves.
DebounceDelay time.Duration
}
WatcherConfig holds configuration for the plugin watcher.
func DefaultWatcherConfig ¶
func DefaultWatcherConfig() WatcherConfig
DefaultWatcherConfig returns the default watcher configuration.