Skip to content

Commit

Permalink
Update version to v1.4.128 and commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 26, 2024
1 parent 525b89b commit e858700
Show file tree
Hide file tree
Showing 16 changed files with 609 additions and 621 deletions.
28 changes: 13 additions & 15 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Cli(version string) (err error) {

var registry *core.PluginRegistry
if registry, err = core.NewPluginRegistry(fabricDb); err != nil {
return
return
}

// if the setup flag is set, run the setup function
Expand Down Expand Up @@ -140,22 +140,20 @@ func Cli(version string) (err error) {
}
}

if currentFlags.ListExtensions {
err = registry.TemplateExtensions.ListExtensions()
return
}

if currentFlags.AddExtension != "" {
err = registry.TemplateExtensions.RegisterExtension(currentFlags.AddExtension)
return
}

if currentFlags.RemoveExtension != "" {
err = registry.TemplateExtensions.RemoveExtension(currentFlags.RemoveExtension)
return
}
if currentFlags.ListExtensions {
err = registry.TemplateExtensions.ListExtensions()
return
}

if currentFlags.AddExtension != "" {
err = registry.TemplateExtensions.RegisterExtension(currentFlags.AddExtension)
return
}

if currentFlags.RemoveExtension != "" {
err = registry.TemplateExtensions.RemoveExtension(currentFlags.RemoveExtension)
return
}

// if the interactive flag is set, run the interactive function
// if currentFlags.Interactive {
Expand Down
5 changes: 2 additions & 3 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ type Flags struct {
Config string `long:"config" description:"Path to YAML config file"`
Version bool `long:"version" description:"Print current version"`
ListExtensions bool `long:"listextensions" description:"List all registered extensions"`
AddExtension string `long:"addextension" description:"Register a new extension from config file path"`
RemoveExtension string `long:"rmextension" description:"Remove a registered extension by name"`

AddExtension string `long:"addextension" description:"Register a new extension from config file path"`
RemoveExtension string `long:"rmextension" description:"Remove a registered extension by name"`
}

var debug = false
Expand Down
18 changes: 9 additions & 9 deletions core/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry, err error) {
Language: lang.NewLanguage(),
Jina: jina.NewClient(),
}

var homedir string
if homedir, err = os.UserHomeDir(); err != nil {
return
Expand All @@ -62,14 +62,14 @@ func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry, err error) {
type PluginRegistry struct {
Db *fsdb.Db

VendorManager *ai.VendorsManager
VendorsAll *ai.VendorsManager
Defaults *tools.Defaults
PatternsLoader *tools.PatternsLoader
YouTube *youtube.YouTube
Language *lang.Language
Jina *jina.Client
TemplateExtensions *template.ExtensionManager
VendorManager *ai.VendorsManager
VendorsAll *ai.VendorsManager
Defaults *tools.Defaults
PatternsLoader *tools.PatternsLoader
YouTube *youtube.YouTube
Language *lang.Language
Jina *jina.Client
TemplateExtensions *template.ExtensionManager
}

func (o *PluginRegistry) SaveEnvFile() (err error) {
Expand Down
2 changes: 1 addition & 1 deletion core/plugin_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestSaveEnvFile(t *testing.T) {
db := fsdb.NewDb(os.TempDir())
registry, err := NewPluginRegistry(db)
if err != nil {
t.Fatalf("NewPluginRegistry() error = %v", err)
t.Fatalf("NewPluginRegistry() error = %v", err)
}

err = registry.SaveEnvFile()
Expand Down
2 changes: 1 addition & 1 deletion pkgs/fabric/version.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"1.4.127"
"1.4.128"
78 changes: 39 additions & 39 deletions plugins/template/extension_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
// ExtensionExecutor handles the secure execution of extensions
// It uses the registry to verify extensions before running them
type ExtensionExecutor struct {
registry *ExtensionRegistry
registry *ExtensionRegistry
}

// NewExtensionExecutor creates a new executor instance
// It requires a registry to verify extensions
func NewExtensionExecutor(registry *ExtensionRegistry) *ExtensionExecutor {
return &ExtensionExecutor{
registry: registry,
}
return &ExtensionExecutor{
registry: registry,
}
}

// Execute runs an extension with the given operation and value string
Expand All @@ -34,19 +34,19 @@ func (e *ExtensionExecutor) Execute(name, operation, value string) (string, erro
// Get and verify extension from registry
ext, err := e.registry.GetExtension(name)
if err != nil {
return "", fmt.Errorf("failed to get extension: %w", err)
return "", fmt.Errorf("failed to get extension: %w", err)
}

// Format the command using our template system
cmdStr, err := e.formatCommand(ext, operation, value)
if err != nil {
return "", fmt.Errorf("failed to format command: %w", err)
return "", fmt.Errorf("failed to format command: %w", err)
}

// Split the command string into command and arguments
cmdParts := strings.Fields(cmdStr)
if len(cmdParts) < 1 {
return "", fmt.Errorf("empty command after formatting")
return "", fmt.Errorf("empty command after formatting")
}

// Create command with the Executable and formatted arguments
Expand All @@ -55,13 +55,13 @@ func (e *ExtensionExecutor) Execute(name, operation, value string) (string, erro

// Set up environment if specified
if len(ext.Env) > 0 {
cmd.Env = append(os.Environ(), ext.Env...)
cmd.Env = append(os.Environ(), ext.Env...)
}

// Execute based on output method
outputMethod := ext.GetOutputMethod()
if outputMethod == "file" {
return e.executeWithFile(cmd, ext)
return e.executeWithFile(cmd, ext)
}
return e.executeStdout(cmd, ext)
}
Expand All @@ -72,7 +72,7 @@ func (e *ExtensionExecutor) formatCommand(ext *ExtensionDefinition, operation st
// Get operation config
opConfig, exists := ext.Operations[operation]
if !exists {
return "", fmt.Errorf("operation %s not found for extension %s", operation, ext.Name)
return "", fmt.Errorf("operation %s not found for extension %s", operation, ext.Name)
}

vars := make(map[string]string)
Expand All @@ -83,35 +83,35 @@ func (e *ExtensionExecutor) formatCommand(ext *ExtensionDefinition, operation st
// Split on pipe for numbered variables
values := strings.Split(value, "|")
for i, val := range values {
vars[fmt.Sprintf("%d", i+1)] = val
vars[fmt.Sprintf("%d", i+1)] = val
}

return ApplyTemplate(opConfig.CmdTemplate, vars, "")
}

// executeStdout runs the command and captures its stdout
func (e *ExtensionExecutor) executeStdout(cmd *exec.Cmd, ext *ExtensionDefinition) (string, error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

//debug output
fmt.Printf("Executing command: %s\n", cmd.String())
//debug output
fmt.Printf("Executing command: %s\n", cmd.String())

if err := cmd.Run(); err != nil {
return "", fmt.Errorf("execution failed: %w\nstderr: %s", err, stderr.String())
}
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("execution failed: %w\nstderr: %s", err, stderr.String())
}

return stdout.String(), nil
return stdout.String(), nil
}

// executeWithFile runs the command and handles file-based output
func (e *ExtensionExecutor) executeWithFile(cmd *exec.Cmd, ext *ExtensionDefinition) (string, error) {
// Parse timeout - this is now a first-class field
timeout, err := time.ParseDuration(ext.Timeout)
if err != nil {
return "", fmt.Errorf("invalid timeout format: %w", err)
return "", fmt.Errorf("invalid timeout format: %w", err)
}

// Create context with timeout
Expand All @@ -122,51 +122,51 @@ func (e *ExtensionExecutor) executeWithFile(cmd *exec.Cmd, ext *ExtensionDefinit

fileConfig := ext.GetFileConfig()
if fileConfig == nil {
return "", fmt.Errorf("no file configuration found")
return "", fmt.Errorf("no file configuration found")
}

// Handle path from stdout case
if pathFromStdout, ok := fileConfig["path_from_stdout"].(bool); ok && pathFromStdout {
return e.handlePathFromStdout(cmd, ext)
return e.handlePathFromStdout(cmd, ext)
}

// Handle fixed file case
workDir, _ := fileConfig["work_dir"].(string)
outputFile, _ := fileConfig["output_file"].(string)

if outputFile == "" {
return "", fmt.Errorf("no output file specified in configuration")
return "", fmt.Errorf("no output file specified in configuration")
}

// Set working directory if specified
if workDir != "" {
cmd.Dir = workDir
cmd.Dir = workDir
}

var stderr bytes.Buffer
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("execution timed out after %v", timeout)
}
return "", fmt.Errorf("execution failed: %w\nerr: %s", err, stderr.String())
if ctx.Err() == context.DeadlineExceeded {
return "", fmt.Errorf("execution timed out after %v", timeout)
}
return "", fmt.Errorf("execution failed: %w\nerr: %s", err, stderr.String())
}

// Construct full file path
outputPath := outputFile
if workDir != "" {
outputPath = filepath.Join(workDir, outputFile)
outputPath = filepath.Join(workDir, outputFile)
}

content, err := os.ReadFile(outputPath)
if err != nil {
return "", fmt.Errorf("failed to read output file: %w", err)
return "", fmt.Errorf("failed to read output file: %w", err)
}

// Handle cleanup if enabled
if ext.IsCleanupEnabled() {
defer os.Remove(outputPath)
defer os.Remove(outputPath)
}

return string(content), nil
Expand All @@ -179,18 +179,18 @@ func (e *ExtensionExecutor) handlePathFromStdout(cmd *exec.Cmd, ext *ExtensionDe
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return "", fmt.Errorf("failed to get output path: %w\nerr: %s", err, stderr.String())
return "", fmt.Errorf("failed to get output path: %w\nerr: %s", err, stderr.String())
}

outputPath := strings.TrimSpace(stdout.String())
content, err := os.ReadFile(outputPath)
if err != nil {
return "", fmt.Errorf("failed to read output file: %w", err)
return "", fmt.Errorf("failed to read output file: %w", err)
}

if ext.IsCleanupEnabled() {
defer os.Remove(outputPath)
defer os.Remove(outputPath)
}

return string(content), nil
}
}
6 changes: 3 additions & 3 deletions plugins/template/extension_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ config:
"cleanup": "true",
}

err := createExtension("basic-test", "write",
err := createExtension("basic-test", "write",
"{{executable}} write {{1}} "+outputFile, config)
if err != nil {
t.Fatalf("Failed to create extension: %v", err)
Expand Down Expand Up @@ -261,7 +261,7 @@ config:
// Test cleanup behavior
t.Run("CleanupBehavior", func(t *testing.T) {
outputFile := filepath.Join(tmpDir, "cleanup-test.txt")

// Test with cleanup enabled
config := map[string]interface{}{
"output_file": `"cleanup-test.txt"`,
Expand Down Expand Up @@ -357,4 +357,4 @@ config:
t.Error("Expected error from missing output_file, got nil")
}
})
}
}
Loading

0 comments on commit e858700

Please sign in to comment.