executeNonInteractive executa comando capturando saída
(ctx context.Context, shell, shellFlag, command string)
| 134 | |
| 135 | // executeNonInteractive executa comando capturando saída |
| 136 | func (e *CommandExecutor) executeNonInteractive(ctx context.Context, shell, shellFlag, command string) (*ExecutionResult, error) { |
| 137 | start := time.Now() |
| 138 | result := &ExecutionResult{Command: command} |
| 139 | |
| 140 | cmd := exec.CommandContext(ctx, shell, shellFlag, command) //#nosec G204 G702 -- agent shell command, validated upstream by command_validator + policy_manager |
| 141 | var stdout, stderr bytes.Buffer |
| 142 | cmd.Stdout = &stdout |
| 143 | cmd.Stderr = &stderr |
| 144 | cmd.Stdin = os.Stdin |
| 145 | |
| 146 | err := cmd.Run() |
| 147 | result.Duration = time.Since(start) |
| 148 | |
| 149 | result.Output = utils.SanitizeSensitiveText(stdout.String()) |
| 150 | result.Error = utils.SanitizeSensitiveText(stderr.String()) |
| 151 | |
| 152 | if err != nil { |
| 153 | var exitErr *exec.ExitError |
| 154 | if errors.As(err, &exitErr) { |
| 155 | if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { |
| 156 | result.ExitCode = status.ExitStatus() |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | e.logger.Debug("Comando não-interativo executado", |
| 162 | zap.String("command", command), |
| 163 | zap.Int("exit_code", result.ExitCode), |
| 164 | zap.Duration("duration", result.Duration)) |
| 165 | |
| 166 | return result, err |
| 167 | } |
| 168 | |
| 169 | // executeInteractive executa comando interativo |
| 170 | func (e *CommandExecutor) executeInteractive(ctx context.Context, shell, shellFlag, command string) (*ExecutionResult, error) { |
no test coverage detected