Skip to content

Commit e626049

Browse files
committed
Don't use CliConnection at all, just call NAME:
ssh - SSH to an application container instance USAGE: cf ssh APP_NAME [--process PROCESS] [-i INDEX] [-c COMMAND]... [-L [BIND_ADDRESS:]LOCAL_PORT:REMOTE_HOST:REMOTE_PORT]... [--skip-remote-execution] [--disable-pseudo-tty | --force-pseudo-tty | --request-pseudo-tty] [--skip-host-validation] OPTIONS: --app-instance-index, -i App process instance index (Default: 0) --command, -c Command to run --disable-pseudo-tty, -T Disable pseudo-tty allocation --force-pseudo-tty Force pseudo-tty allocation -L Local port forward specification --process App process name (Default: web) --request-pseudo-tty, -t Request pseudo-tty allocation --skip-host-validation, -k Skip host key validation. Not recommended! --skip-remote-execution, -N Do not execute a remote command ENVIRONMENT: all_proxy= Specify a proxy server to enable proxying for all requests SEE ALSO: allow-space-ssh, enable-ssh, space-ssh-allowed, ssh-code, ssh-enabled directly
1 parent 69de30c commit e626049

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ create GitHub issues for security-related doubts or problems.
431431

432432
### Snapshot
433433

434+
- Don't use CliConnection at all, just call `cf ssh` directly
435+
436+
### 4.0.1
437+
434438
- Fix thread-dump command
435439

436440
### 4.0.0

cf_cli_java_plugin.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"errors"
1313
"fmt"
1414
"os"
15+
"os/exec"
1516
"strconv"
1617
"strings"
1718

@@ -253,7 +254,7 @@ func (c *JavaPlugin) DoRun(cliConnection plugin.CliConnection, args []string) (s
253254
if errors.As(err, &invalidUsageErr) {
254255
fmt.Println()
255256
fmt.Println()
256-
_, err := cliConnection.CliCommand("help", "java")
257+
err := exec.Command("cf", "help", "java").Run()
257258
if err != nil {
258259
ui.Failed("Failed to show help")
259260
}
@@ -596,7 +597,7 @@ fi`,
596597
},
597598
}
598599

599-
func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string) (string, error) {
600+
func (c *JavaPlugin) execute(_ plugin.CliConnection, args []string) (string, error) {
600601
if len(args) == 0 {
601602
return "", &InvalidUsageError{message: "No command provided"}
602603
}
@@ -807,15 +808,23 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
807808
fullCommand = append(fullCommand, remoteCommand)
808809
c.logVerbosef("Executing command: %v", fullCommand)
809810

810-
output, err := cliConnection.CliCommand(fullCommand...)
811+
cmdArgs := append([]string{"cf"}, fullCommand...)
812+
c.logVerbosef("Executing command: %v", cmdArgs)
813+
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
814+
outputBytes, err := cmd.CombinedOutput()
815+
output := string(outputBytes)
811816
if err != nil {
812817
if err.Error() == "unexpected EOF" {
813818
return "", fmt.Errorf("Command failed")
814819
}
815820
if len(output) == 0 {
816821
return "", fmt.Errorf("Command execution failed: %w", err)
817822
}
818-
return "", fmt.Errorf("Command execution failed: %w\nOutput: %s", err, strings.Join(output, "\n"))
823+
return "", fmt.Errorf("Command execution failed: %w\nOutput: %s", err, output)
824+
}
825+
// Print output to stdout for user visibility
826+
if len(output) > 0 {
827+
fmt.Print(output)
819828
}
820829

821830
if command.GenerateFiles {
@@ -845,7 +854,7 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
845854

846855
if noDownload {
847856
fmt.Println("No download requested, skipping file download")
848-
return strings.Join(output, "\n"), nil
857+
return output, nil
849858
}
850859

851860
localFileFullPath := localDir + "/" + applicationName + "-" + command.FileNamePart + "-" + utils.GenerateUUID() + command.FileExtension
@@ -917,7 +926,7 @@ func (c *JavaPlugin) execute(cliConnection plugin.CliConnection, args []string)
917926
}
918927
// We keep this around to make the compiler happy, but commandExecutor.Execute will cause an os.Exit
919928
c.logVerbosef("Command execution completed successfully")
920-
return strings.Join(output, "\n"), err
929+
return output, err
921930
}
922931

923932
// GetMetadata must be implemented as part of the plugin interface

0 commit comments

Comments
 (0)