lua

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 24 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

func LoadPluginFromFile

func LoadPluginFromFile(ctx context.Context, path string) (plugins.Plugin, error)

LoadPluginFromFile loads a Lua plugin directly from a file path. This is a convenience function for testing and direct loading.

Types

type HTTPConfig

type HTTPConfig struct {
	Timeout       time.Duration
	MaxBodySize   int64
	AllowInsecure bool
}

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) Delete

func (c *LuaConnector) Delete(ctx context.Context, item core.DataItem) error

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) Write

func (c *LuaConnector) Write(ctx context.Context, item core.DataItem, reader io.Reader) error

func (*LuaConnector) WriteBatch

func (c *LuaConnector) WriteBatch(ctx context.Context, items []core.DataItem, getReader func(core.DataItem) (io.Reader, error), progress core.ProgressFunc) error

func (*LuaConnector) WriteFrom

func (c *LuaConnector) WriteFrom(ctx context.Context, item core.DataItem, sourcePath string) error

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

func NewLuaOutput(plugin *LuaPlugin) *LuaOutput

NewLuaOutput creates an output adapter for a Lua plugin.

func (*LuaOutput) CanOutput

func (o *LuaOutput) CanOutput(item *core.DataItem) bool

func (*LuaOutput) ConfigSchema

func (o *LuaOutput) ConfigSchema() []svccore.ConfigOption

func (*LuaOutput) Description

func (o *LuaOutput) Description() string

func (*LuaOutput) Export

func (o *LuaOutput) Export(ctx context.Context, item svccore.ProcessedItem) error

Export sends a single item to the destination.

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) Finalize

func (o *LuaOutput) Finalize(ctx context.Context) error

Finalize completes the export process.

func (*LuaOutput) ID

func (o *LuaOutput) ID() string

func (*LuaOutput) Initialize

func (o *LuaOutput) Initialize(ctx context.Context, cfg svccore.OutputConfig) error

Initialize prepares the output for use.

func (*LuaOutput) Name

func (o *LuaOutput) Name() string

func (*LuaOutput) Plugin

func (o *LuaOutput) Plugin() *LuaPlugin

Plugin returns the underlying plugin.

func (*LuaOutput) Selector

func (o *LuaOutput) Selector() *plugins.Selector

func (*LuaOutput) SupportedItemTypes

func (o *LuaOutput) SupportedItemTypes() []string

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

func (p *LuaPlugin) CallFunction(name string, args ...lua.LValue) ([]lua.LValue, error)

CallFunction calls a Lua function by name.

func (*LuaPlugin) ConfigToLua

func (p *LuaPlugin) ConfigToLua(config map[string]any) *lua.LTable

ConfigToLua converts a config map to a Lua table.

func (*LuaPlugin) DataItemToLua

func (p *LuaPlugin) DataItemToLua(item *core.DataItem) *lua.LTable

DataItemToLua converts a DataItem to a Lua table.

func (*LuaPlugin) EvaluateCondition

func (p *LuaPlugin) EvaluateCondition(item *core.DataItem, condition string) (bool, error)

EvaluateCondition evaluates a Lua condition expression.

func (*LuaPlugin) HasFunction

func (p *LuaPlugin) HasFunction(name string) bool

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) Load

func (p *LuaPlugin) Load(ctx context.Context) error

Load initializes the plugin.

func (*LuaPlugin) LuaToDataItem

func (p *LuaPlugin) LuaToDataItem(tbl *lua.LTable) *core.DataItem

LuaToDataItem converts a Lua table to a DataItem.

func (*LuaPlugin) Reload

func (p *LuaPlugin) Reload(ctx context.Context) error

Reload reloads the plugin.

func (*LuaPlugin) Selector

func (p *LuaPlugin) Selector() *plugins.Selector

Selector returns the default selector for this plugin.

func (*LuaPlugin) Unload

func (p *LuaPlugin) Unload() error

Unload releases resources held by the plugin.

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) Process

func (p *LuaProcessor) Process(ctx context.Context, item *core.DataItem, config map[string]any) (*core.DataItem, error)

func (*LuaProcessor) ProcessBatch

func (p *LuaProcessor) ProcessBatch(ctx context.Context, items []*core.DataItem, config map[string]any, progress plugins.ProgressFunc) ([]*core.DataItem, error)

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

func (pm *PluginManager) LoadAndWatch(ctx context.Context, path string) (*LuaPlugin, error)

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) Stop

func (pm *PluginManager) Stop() error

Stop stops the plugin manager.

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) Stop

func (pw *PluginWatcher) Stop() error

Stop stops the watcher.

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 GetRuntime

func GetRuntime() *Runtime

Runtime returns the global Lua runtime.

func NewRuntime

func NewRuntime() *Runtime

NewRuntime creates a new Lua runtime.

func (*Runtime) CreateState

func (r *Runtime) CreateState() *lua.LState

CreateState creates a new sandboxed Lua state.

func (*Runtime) LoadPlugin

func (r *Runtime) LoadPlugin(ctx context.Context, path string) (*LuaPlugin, error)

LoadPlugin loads a Lua plugin from a file.

type StatePool

type StatePool struct {
	// contains filtered or unexported fields
}

StatePool manages a pool of Lua states.

func NewStatePool

func NewStatePool(max int, create func() *lua.LState) *StatePool

NewStatePool creates a new state pool.

func (*StatePool) Get

func (p *StatePool) Get() *lua.LState

Get retrieves a state from the pool or creates a new one.

func (*StatePool) Put

func (p *StatePool) Put(L *lua.LState)

Put returns a state to the pool.

func (*StatePool) Shutdown

func (p *StatePool) Shutdown()

Shutdown closes all states in the 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.

Jump to

Keyboard shortcuts

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