Documentation
¶
Overview ¶
Package template provides datetime operations for the template system
Package template provides URL fetching operations for the template system. Security Note: This plugin makes outbound HTTP requests. Use with caution and consider implementing URL allowlists in production.
Package template provides file system operations for the template system. Security Note: This plugin provides access to the local filesystem. Consider carefully which paths to allow access to in production.
Package template provides system information operations for the template system.
Package template provides text transformation operations for the template system.
utils.go in template package for now
Index ¶
- Constants
- Variables
- func ApplyTemplate(content string, variables map[string]string, input string) (string, error)
- func ComputeHash(path string) (string, error)
- func ComputeStringHash(s string) string
- func ExpandPath(path string) (string, error)
- type DateTimePlugin
- type ExtensionDefinition
- type ExtensionExecutor
- type ExtensionManager
- type ExtensionRegistry
- func (r *ExtensionRegistry) GetExtension(name string) (*ExtensionDefinition, error)
- func (r *ExtensionRegistry) ListExtensions() ([]*ExtensionDefinition, error)
- func (r *ExtensionRegistry) Register(configPath string) error
- func (r *ExtensionRegistry) Remove(name string) error
- func (r *ExtensionRegistry) Verify(name string) error
- type FetchPlugin
- type FilePlugin
- type OperationConfig
- type RegistryEntry
- type SysPlugin
- type TextPlugin
Constants ¶
const ( // MaxContentSize limits response size to 1MB to prevent memory issues MaxContentSize = 1024 * 1024 // UserAgent identifies the client in HTTP requests UserAgent = "Fabric-Fetch/1.0" )
const MaxFileSize = 1 * 1024 * 1024
MaxFileSize defines the maximum file size that can be read (1MB)
Variables ¶
var (
Debug = false // Debug flag
)
Functions ¶
func ApplyTemplate ¶
func ComputeHash ¶ added in v1.4.128
ComputeHash computes SHA-256 hash of a file at given path. Returns the hex-encoded hash string or an error if the operation fails.
func ComputeStringHash ¶ added in v1.4.128
ComputeStringHash returns hex-encoded SHA-256 hash of the given string
func ExpandPath ¶ added in v1.4.128
ExpandPath expands the ~ to user's home directory and returns absolute path It also checks if the path exists Returns expanded absolute path or error if: - cannot determine user home directory - cannot convert to absolute path - path doesn't exist
Types ¶
type DateTimePlugin ¶
type DateTimePlugin struct{}
DateTimePlugin handles time and date operations
func (*DateTimePlugin) Apply ¶
func (p *DateTimePlugin) Apply(operation string, value string) (string, error)
Apply executes datetime operations with the following formats: Time: now (RFC3339), time (HH:MM:SS), unix (timestamp) Hour: startofhour, endofhour Date: today (YYYY-MM-DD), full (Monday, January 2, 2006) Period: startofweek, endofweek, startofmonth, endofmonth Relative: rel:-1h, rel:-2d, rel:1w, rel:3m, rel:1y
type ExtensionDefinition ¶ added in v1.4.128
type ExtensionDefinition struct { // Global properties Name string `yaml:"name"` Executable string `yaml:"executable"` Type string `yaml:"type"` Timeout string `yaml:"timeout"` Description string `yaml:"description"` Version string `yaml:"version"` Env []string `yaml:"env"` // Operation-specific commands Operations map[string]OperationConfig `yaml:"operations"` // Additional config Config map[string]interface{} `yaml:"config"` }
ExtensionDefinition represents a single extension configuration
func (*ExtensionDefinition) GetFileConfig ¶ added in v1.4.128
func (e *ExtensionDefinition) GetFileConfig() map[string]interface{}
func (*ExtensionDefinition) GetOutputMethod ¶ added in v1.4.128
func (e *ExtensionDefinition) GetOutputMethod() string
Helper methods for Config access
func (*ExtensionDefinition) IsCleanupEnabled ¶ added in v1.4.128
func (e *ExtensionDefinition) IsCleanupEnabled() bool
type ExtensionExecutor ¶ added in v1.4.128
type ExtensionExecutor struct {
// contains filtered or unexported fields
}
ExtensionExecutor handles the secure execution of extensions It uses the registry to verify extensions before running them
func NewExtensionExecutor ¶ added in v1.4.128
func NewExtensionExecutor(registry *ExtensionRegistry) *ExtensionExecutor
NewExtensionExecutor creates a new executor instance It requires a registry to verify extensions
func (*ExtensionExecutor) Execute ¶ added in v1.4.128
func (e *ExtensionExecutor) Execute(name, operation, value string) (string, error)
Execute runs an extension with the given operation and value string name: the registered name of the extension operation: the operation to perform value: the input value(s) for the operation In extension_executor.go
type ExtensionManager ¶ added in v1.4.128
type ExtensionManager struct {
// contains filtered or unexported fields
}
ExtensionManager handles the high-level operations of the extension system
func NewExtensionManager ¶ added in v1.4.128
func NewExtensionManager(configDir string) *ExtensionManager
NewExtensionManager creates a new extension manager instance
func (*ExtensionManager) ListExtensions ¶ added in v1.4.128
func (em *ExtensionManager) ListExtensions() error
ListExtensions handles the listextensions flag action
func (*ExtensionManager) ProcessExtension ¶ added in v1.4.128
func (em *ExtensionManager) ProcessExtension(name, operation, value string) (string, error)
ProcessExtension handles template processing for extension directives
func (*ExtensionManager) RegisterExtension ¶ added in v1.4.128
func (em *ExtensionManager) RegisterExtension(configPath string) error
RegisterExtension handles the addextension flag action
func (*ExtensionManager) RemoveExtension ¶ added in v1.4.128
func (em *ExtensionManager) RemoveExtension(name string) error
RemoveExtension handles the rmextension flag action
type ExtensionRegistry ¶ added in v1.4.128
type ExtensionRegistry struct {
// contains filtered or unexported fields
}
func NewExtensionRegistry ¶ added in v1.4.128
func NewExtensionRegistry(configDir string) *ExtensionRegistry
func (*ExtensionRegistry) GetExtension ¶ added in v1.4.128
func (r *ExtensionRegistry) GetExtension(name string) (*ExtensionDefinition, error)
func (*ExtensionRegistry) ListExtensions ¶ added in v1.4.128
func (r *ExtensionRegistry) ListExtensions() ([]*ExtensionDefinition, error)
func (*ExtensionRegistry) Register ¶ added in v1.4.128
func (r *ExtensionRegistry) Register(configPath string) error
func (*ExtensionRegistry) Remove ¶ added in v1.4.128
func (r *ExtensionRegistry) Remove(name string) error
func (*ExtensionRegistry) Verify ¶ added in v1.4.128
func (r *ExtensionRegistry) Verify(name string) error
type FetchPlugin ¶
type FetchPlugin struct{}
FetchPlugin provides HTTP fetching capabilities with safety constraints: - Only text content types allowed - Size limited to MaxContentSize - UTF-8 validation - Null byte checking
type FilePlugin ¶
type FilePlugin struct{}
FilePlugin provides filesystem operations with safety constraints: - No directory traversal - Size limits - Path sanitization
func (*FilePlugin) Apply ¶
func (p *FilePlugin) Apply(operation string, value string) (string, error)
Apply executes file operations:
- read:PATH - Read entire file content
- tail:PATH|N - Read last N lines
- exists:PATH - Check if file exists
- size:PATH - Get file size in bytes
- modified:PATH - Get last modified time
type OperationConfig ¶ added in v1.4.128
type OperationConfig struct {
CmdTemplate string `yaml:"cmd_template"`
}
type RegistryEntry ¶ added in v1.4.128
type RegistryEntry struct { ConfigPath string `yaml:"config_path"` ConfigHash string `yaml:"config_hash"` ExecutableHash string `yaml:"executable_hash"` }
RegistryEntry represents a registered extension
type SysPlugin ¶
type SysPlugin struct{}
SysPlugin provides access to system-level information. Security Note: This plugin provides access to system information and environment variables. Be cautious with exposed variables in templates.
func (*SysPlugin) Apply ¶
Apply executes system operations with the following options:
- hostname: System hostname
- user: Current username
- os: Operating system (linux, darwin, windows)
- arch: System architecture (amd64, arm64, etc)
- env:VALUE: Environment variable lookup
- pwd: Current working directory
- home: User's home directory