executor

package
v0.0.0-...-db2243d Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package executor provides secure script execution with Azure context and Key Vault integration. It supports multiple shells (bash, sh, zsh, pwsh, powershell, cmd) and handles environment variable resolution including Azure Key Vault secret references.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Shell specifies the shell to use for execution.
	// If empty, shell is auto-detected from script extension or shebang.
	// Valid values: bash, sh, zsh, pwsh, powershell, cmd
	Shell string

	// Interactive enables interactive mode, connecting stdin to the script.
	Interactive bool

	// StopOnKeyVaultError causes azd exec to fail-fast when any Key Vault reference fails to resolve.
	// Default is false (continue resolving other references and run with unresolved values left as-is).
	StopOnKeyVaultError bool

	// Args are additional arguments to pass to the script.
	Args []string
}

Config holds the configuration for script execution. All fields are optional and have sensible defaults.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the Config has valid values.

type ExecutionError

type ExecutionError struct {
	ExitCode int
	Shell    string
	IsInline bool
}

ExecutionError indicates that script execution failed with an exit code.

func (*ExecutionError) Error

func (e *ExecutionError) Error() string

type Executor

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

Executor executes scripts with azd context.

func New

func New(config Config) (*Executor, error)

New creates a new script executor with the given configuration. Returns a configured Executor ready to execute scripts, or an error if the configuration is invalid (e.g., unknown shell name).

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, scriptPath string) error

Execute runs a script file with azd context. The script path is validated for existence and security. Returns an error if:

  • scriptPath is empty
  • scriptPath does not exist or is not a regular file
  • scriptPath is a directory
  • scriptPath contains path traversal attempts (..)
  • script execution fails

func (*Executor) ExecuteInline

func (e *Executor) ExecuteInline(ctx context.Context, scriptContent string) error

ExecuteInline runs an inline script command with azd context. The shell is auto-detected based on OS if not specified in config. Returns an error if:

  • scriptContent is empty or only whitespace
  • shell detection fails
  • script execution fails

type InvalidShellError

type InvalidShellError struct {
	Shell string
}

InvalidShellError indicates that an invalid shell was specified.

func (*InvalidShellError) Error

func (e *InvalidShellError) Error() string

type ScriptNotFoundError

type ScriptNotFoundError struct {
	Path string
}

ScriptNotFoundError indicates that a script file could not be found.

func (*ScriptNotFoundError) Error

func (e *ScriptNotFoundError) Error() string

type ValidationError

type ValidationError struct {
	Field  string
	Reason string
}

ValidationError indicates that input validation failed.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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