You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/08/30 10:58:59 UTC

[brooklyn-server] 02/04: Remove 'temp' from SSH and SCP CLI key file env var

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 6a0deed352225619bac7ed91def34cfbe8af6a06
Author: Mykola Mandra <my...@cloudsoft.io>
AuthorDate: Tue Aug 30 11:34:31 2022 +0100

    Remove 'temp' from SSH and SCP CLI key file env var
    
    Signed-off-by: Mykola Mandra <my...@cloudsoft.io>
---
 .../apache/brooklyn/util/core/internal/ssh/cli/SshCliTool.java | 10 +++++-----
 .../util/core/internal/ssh/cli/SshCliToolIntegrationTest.java  |  8 ++++----
 core/src/test/resources/scp-executable.sh                      |  2 +-
 core/src/test/resources/ssh-executable.sh                      |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliTool.java b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliTool.java
index ab1adf4c01..6ef753775d 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliTool.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliTool.java
@@ -221,7 +221,7 @@ public class SshCliTool extends SshAbstractTool implements SshTool {
         try {
 
             final String scpPassword = Strings.isEmpty(password) ? "" : password;
-            final File scpTempKeyFile = Objects.isNull(privateKeyFile) ? tempKeyFile : null;
+            final File scpKeyFile = Objects.isNull(privateKeyFile) ? tempKeyFile : null;
 
             List<String> cmd = Lists.newArrayList();
             cmd.add(getOptionalVal(props, PROP_SCP_EXECUTABLE, scpExecutable));
@@ -229,9 +229,9 @@ public class SshCliTool extends SshAbstractTool implements SshTool {
             // set batch mode
             cmd.add("-B");
 
-            if (Objects.nonNull(scpTempKeyFile)) {
+            if (Objects.nonNull(scpKeyFile)) {
                 cmd.add("-i");
-                cmd.add(scpTempKeyFile.getAbsolutePath());
+                cmd.add(scpKeyFile.getAbsolutePath());
             }
 
             if (!strictHostKeyChecking) {
@@ -248,7 +248,7 @@ public class SshCliTool extends SshAbstractTool implements SshTool {
             cmd.add(to);
 
             Map<String, String> env = MutableMap.of();
-            env.put("SCP_TEMP_KEY_FILE", Objects.isNull(scpTempKeyFile) ? "" : scpTempKeyFile.getAbsolutePath());
+            env.put("SCP_KEY_FILE", Objects.isNull(scpKeyFile) ? "" : scpKeyFile.getAbsolutePath());
             env.put("SCP_PASSWORD", scpPassword);
             env.put("SCP_FROM", from);
             env.put("SCP_TO", to);
@@ -327,7 +327,7 @@ public class SshCliTool extends SshAbstractTool implements SshTool {
             env.put("SSH_USER", sshUser);
             env.put("SSH_PASSWORD", sshPassword);
             env.put("SSH_COMMAND_BODY", command);
-            env.put("SSH_TEMP_KEY_FILE", Objects.isNull(sshKeyFile) ? "" : sshKeyFile.getAbsolutePath());
+            env.put("SSH_KEY_FILE", Objects.isNull(sshKeyFile) ? "" : sshKeyFile.getAbsolutePath());
 
             if (LOG.isTraceEnabled()) LOG.trace("Executing command: {}; with env: {}", cmd, env);
             int result = execProcess(props, cmd, env);
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliToolIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliToolIntegrationTest.java
index 26998f5526..8b94005ec5 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliToolIntegrationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/cli/SshCliToolIntegrationTest.java
@@ -152,8 +152,8 @@ public class SshCliToolIntegrationTest extends SshToolAbstractIntegrationTest {
             assertTrue(stdout.contains("SSH_HOST=localhost"), "no SSH_HOST in stdout: " + out);
             assertTrue(stdout.contains("SSH_PASSWORD=testPassword"), "no SSH_PASSWORD in stdout: " + out);
             assertTrue(stdout.contains("SSH_COMMAND_BODY=/tmp/brooklyn-"), "no SSH_COMMAND_BODY in stdout: " + out);
-            assertTrue(stdout.contains("SSH_TEMP_KEY_FILE=/tmp/sshcopy-"), "no SSH_TEMP_KEY_FILE in stdout: " + out);
-            assertTrue(stdout.contains("myKeyData"), "no SSH_TEMP_KEY_FILE content in stdout: " + out);
+            assertTrue(stdout.contains("SSH_KEY_FILE=/tmp/sshcopy-"), "no SSH_KEY_FILE in stdout: " + out);
+            assertTrue(stdout.contains("myKeyData"), "no SSH_KEY_FILE content in stdout: " + out);
 
         } catch (SshException e) {
             if (!e.toString().contains("failed to connect")) throw e;
@@ -194,8 +194,8 @@ public class SshCliToolIntegrationTest extends SshToolAbstractIntegrationTest {
             // Look for the rest of env vars to confirm we got them passed to scpExecutable.
             assertTrue(copiedFileContent.contains("echo hello world!"), "no command in the remote file: " + out);
             assertTrue(copiedFileContent.contains("SCP_PASSWORD=testPassword"), "no SCP_PASSWORD in the remote file: " + out);
-//            assertTrue(copiedFileContent.contains("SCP_TEMP_KEY_FILE="), "no SCP_TEMP_KEY_FILE in the remote file: " + out);
-//            assertTrue(copiedFileContent.contains("myKeyData"), "no SSH_TEMP_KEY_FILE content in stdout: " + out);
+//            assertTrue(copiedFileContent.contains("SCP_KEY_FILE="), "no SCP_KEY_FILE in the remote file: " + out);
+//            assertTrue(copiedFileContent.contains("myKeyData"), "no SSH_KEY_FILE content in stdout: " + out);
 
         } catch (SshException e) {
             if (!e.toString().contains("failed to connect")) throw e;
diff --git a/core/src/test/resources/scp-executable.sh b/core/src/test/resources/scp-executable.sh
index 22cb6fa6b4..eb431494d2 100644
--- a/core/src/test/resources/scp-executable.sh
+++ b/core/src/test/resources/scp-executable.sh
@@ -19,7 +19,7 @@
 #
 
 chmod +w $SCP_FROM
-echo SCP_TEMP_KEY_FILE=$SCP_TEMP_KEY_FILE >> $SCP_FROM
+echo SCP_KEY_FILE=$SCP_KEY_FILE >> $SCP_FROM
 echo SCP_PASSWORD=$SCP_PASSWORD >> $SCP_FROM
 echo SCP_FROM=$SCP_FROM >> $SCP_FROM
 echo SCP_TO=$SCP_TO >> $SCP_FROM
diff --git a/core/src/test/resources/ssh-executable.sh b/core/src/test/resources/ssh-executable.sh
index c13dea0809..1c9f571a41 100644
--- a/core/src/test/resources/ssh-executable.sh
+++ b/core/src/test/resources/ssh-executable.sh
@@ -22,7 +22,7 @@ echo SSH_USER=$SSH_USER
 echo SSH_HOST=$SSH_HOST
 echo SSH_PASSWORD=$SSH_PASSWORD
 echo SSH_COMMAND_BODY=$SSH_COMMAND_BODY
-echo SSH_TEMP_KEY_FILE=$SSH_TEMP_KEY_FILE
+echo SSH_KEY_FILE=$SSH_KEY_FILE
 
 # print contents of the key file
-cat $SSH_TEMP_KEY_FILE
\ No newline at end of file
+cat $SSH_KEY_FILE
\ No newline at end of file