Documentation
¶
Overview ¶
Package executor provides the command execution framework for Alpamon
Index ¶
- type CommandDispatcher
- func (e *CommandDispatcher) Execute(ctx context.Context, cmd string, args *common.CommandArgs) (int, string, error)
- func (e *CommandDispatcher) HasHandler(cmd string) bool
- func (e *CommandDispatcher) RegisterHandler(h common.Handler) error
- func (e *CommandDispatcher) Shutdown(timeout time.Duration) error
- type CommandOptions
- type Executor
- func (e *Executor) Exec(ctx context.Context, args []string, username, groupname string, ...) (int, string, error)
- func (e *Executor) ExecWithHook(ctx context.Context, args []string, username, groupname string, ...) (int, string, error)
- func (e *Executor) ExecWithStreamingHook(ctx context.Context, args []string, username, groupname string, ...) (int, string, error)
- func (e *Executor) Execute(ctx context.Context, opts CommandOptions) (int, string, error)
- func (e *Executor) Run(ctx context.Context, name string, args ...string) (int, string, error)
- func (e *Executor) RunAsUser(ctx context.Context, username string, name string, args ...string) (int, string, error)
- func (e *Executor) RunWithInput(ctx context.Context, input string, name string, args ...string) (int, string, error)
- func (e *Executor) RunWithTimeout(ctx context.Context, timeout time.Duration, name string, args ...string) (int, string, error)
- type HandlerFactory
- type Registry
- func (r *Registry) Clear()
- func (r *Registry) Get(cmd string) (common.Handler, error)
- func (r *Registry) GetHandler(name string) (common.Handler, error)
- func (r *Registry) IsCommandRegistered(cmd string) bool
- func (r *Registry) List() []string
- func (r *Registry) ListCommands() []string
- func (r *Registry) Register(h common.Handler) error
- func (r *Registry) Unregister(name string) error
- type SystemInfoAdapter
- type SystemInfoCallbacks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandDispatcher ¶
type CommandDispatcher struct {
// contains filtered or unexported fields
}
CommandDispatcher manages command execution through registered handlers
func InitDispatcher ¶
func InitDispatcher( pool *pool.Pool, ctxManager *agent.ContextManager, session *scheduler.Session, wsClient common.WSClient, callbacks SystemInfoCallbacks, ) (*CommandDispatcher, error)
InitDispatcher initializes and configures the command dispatching system with all handlers
func NewCommandDispatcher ¶
func NewCommandDispatcher(pool *pool.Pool, ctxManager *agent.ContextManager) *CommandDispatcher
NewCommandDispatcher creates a new command dispatcher
func (*CommandDispatcher) Execute ¶
func (e *CommandDispatcher) Execute(ctx context.Context, cmd string, args *common.CommandArgs) (int, string, error)
Execute runs a command with the appropriate handler
func (*CommandDispatcher) HasHandler ¶
func (e *CommandDispatcher) HasHandler(cmd string) bool
HasHandler checks if a handler exists for the given command
func (*CommandDispatcher) RegisterHandler ¶
func (e *CommandDispatcher) RegisterHandler(h common.Handler) error
RegisterHandler registers a command handler
type CommandOptions ¶
type CommandOptions struct {
Args []string // Command and arguments
Username string // Username to run as (empty = current user)
Groupname string // Group to run as
Env map[string]string // Environment variables
WorkingDir string // Working directory
Timeout time.Duration // Command timeout
Input string // Input to provide via stdin
// PIDHook, if non-nil, receives the child's pid after Start so the
// shell handler can register it with the PAM tracker before the
// child execs sudo. Panics are recovered and logged.
PIDHook func(pid int)
// ChunkCallback, if non-nil, receives streamed stdout/stderr chunks.
// Sequencing is the caller's responsibility.
ChunkCallback func(content string)
}
CommandOptions defines options for command execution
type Executor ¶
type Executor struct{}
Executor provides system command execution with privilege management
func (*Executor) Exec ¶
func (e *Executor) Exec(ctx context.Context, args []string, username, groupname string, env map[string]string, timeout time.Duration) (int, string, error)
Exec executes a command with all options
func (*Executor) ExecWithHook ¶
func (e *Executor) ExecWithHook(ctx context.Context, args []string, username, groupname string, env map[string]string, timeout time.Duration, pidHook func(pid int)) (int, string, error)
ExecWithHook is like Exec but registers a PIDHook that receives the child's pid immediately after cmd.Start() succeeds. This is used by the shell handler to track the root pid of a deploy shell Command so sudo calls made inside the command can be authorized via command_id.
func (*Executor) ExecWithStreamingHook ¶ added in v2.3.1
func (e *Executor) ExecWithStreamingHook(ctx context.Context, args []string, username, groupname string, env map[string]string, timeout time.Duration, pidHook func(pid int), chunkCallback func(content string)) (int, string, error)
ExecWithStreamingHook combines PIDHook and ChunkCallback. Either may be nil.
func (*Executor) RunAsUser ¶
func (e *Executor) RunAsUser(ctx context.Context, username string, name string, args ...string) (int, string, error)
RunAsUser executes a command as a specific user
type HandlerFactory ¶
type HandlerFactory struct {
// contains filtered or unexported fields
}
HandlerFactory encapsulates handler instantiation and registration
func NewHandlerFactory ¶
func NewHandlerFactory(dispatcher *CommandDispatcher, cmdExec common.CommandExecutor) *HandlerFactory
NewHandlerFactory creates a new handler factory
func (*HandlerFactory) RegisterAll ¶
func (f *HandlerFactory) RegisterAll( pool *pool.Pool, ctxManager *agent.ContextManager, session *scheduler.Session, wsClient common.WSClient, callbacks SystemInfoCallbacks, ) error
RegisterAll registers all handlers with the provided callbacks
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the registration and lookup of command handlers
func (*Registry) GetHandler ¶
GetHandler retrieves a handler by handler name
func (*Registry) IsCommandRegistered ¶
IsCommandRegistered checks if a command is registered
func (*Registry) ListCommands ¶
ListCommands returns all registered commands
func (*Registry) Unregister ¶
Unregister removes a handler from the registry
type SystemInfoAdapter ¶
type SystemInfoAdapter struct {
// contains filtered or unexported fields
}
SystemInfoAdapter implements the common.SystemInfoManager interface for handlers
func NewSystemInfoAdapter ¶
func NewSystemInfoAdapter( session *scheduler.Session, commitFunc func(), syncFunc func(*scheduler.Session, []string), ) *SystemInfoAdapter
NewSystemInfoAdapter creates a new system info adapter with function callbacks
func (*SystemInfoAdapter) CommitSystemInfo ¶
func (a *SystemInfoAdapter) CommitSystemInfo()
CommitSystemInfo implements common.SystemInfoManager
func (*SystemInfoAdapter) SyncSystemInfo ¶
func (a *SystemInfoAdapter) SyncSystemInfo(keys []string)
SyncSystemInfo implements common.SystemInfoManager
type SystemInfoCallbacks ¶
SystemInfoCallbacks contains function callbacks for system info operations