Skip to content

Conversation

adamfisher
Copy link

@adamfisher adamfisher commented Mar 3, 2025

InvokeCommand Activity for Elsa Workflows

Closes #6305

The InvokeCommand activity provides seamless integration between Elsa workflows and command-line operations through the CliWrap library. This powerful activity allows workflow authors to execute system commands, scripts, and external processes directly from their workflows with comprehensive configuration options and output handling.

Key Features

  • Execute any command-line process with full input/output handling
  • Configure working directories, environment variables, and credentials
  • Set validation criteria for command success including exit codes and output patterns
  • Granular security controls through configurable command allowlists/denylists
  • Comprehensive output capture including stdout, stderr, exit codes, and timing information
  • Error handling with dedicated error path for fault-tolerant workflows

Configuration Options

The activity provides extensive configuration options including:

  • Command specification (as string or CliWrap Command object)
  • Command arguments
  • Working directory
  • Environment variables
  • Execution credentials
  • Timeout configuration
  • Success validation criteria

Security

The implementation includes robust security features through the ICommandValidator interface, allowing administrators to:

  • Restrict which commands can be executed
  • Control whether credential-based execution is permitted
  • Apply granular security policies through custom validator implementations

TODOs

⚠️ These must be addressed before this PR can be merged: ⚠️

  • Verify the necessary pieces of ClipWrap are exposed to support piping. There was some stuff on the Command object that looked interesting like cmd.StandardInputPipe, cmd.StandardErrorPipe, and cmd.StandardOutputPipe that looked interesting and may need to be integrated at the activity level to allow piping of commands from one InvokeCommand activity to the next.
  • Integrate CommandFinder with InvokeCommand to dynamically display an auto-complete dropdown of available CLI commands on the current system while preserving the ability to accept both free-form string commands OR CliWrap Command objects.
  • Complete integration tests in InvokeCommandTests

This change is Reviewable

@adamfisher
Copy link
Author

@sfmskywalker is #2 in the TODOs list even possible with making auto-complete of a dropdown with pre-set values, free-form entry, or specifying a CliWrap Command object via some language syntax all in one field? Looking for an ideal approach but I can also just leave it off the listing of all commands on the OS. That's what the CommandFinder was going to do in this PR.

For tests, would it make sense to start using the WebApplicationFactory from MVC testing namespace? It doesn't seem like a lot of activities have integration tests around them currently so not sure of the best approach 🤔

…to the next and optionally a Port activity that automatically pipes the current command into it.
@adamfisher
Copy link
Author

Note: I requested a review on the CliWrap discussion board to see if they might provide an initial review purely on the CliWrap integration/behavior to see if anything sticks out as something that needs to be address. I figured it might be good to have some feedback from them on general approach so far.

@adamfisher
Copy link
Author

This code has been moved to Elsa integrations as a separate installable package: elsa-workflows/elsa-extensions#37

@adamfisher adamfisher closed this Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Add InvokeCommand Activity
2 participants