SshMachineLocation extends AbstractMachineLocation implements MachineLocation, PortSupplier, WithMutexes, Closeable, CanResolveOnBoxDir { public int execCommands(String summaryForLogging, List<String> commands) { return execCommands(MutableMap.<String,Object>of(), summaryForLogging, commands, MutableMap.<String,Object>of()); } SshMachineLocation();  SshMachineLocation(Map<?,?> properties); @Override void init(); @Override SshMachineLocation configure(Map<?,?> properties); @Override void close(); @Override InetAddress getAddress(); @Override String getHostname(); @Override Set<String> getPublicAddresses(); @Override Set<String> getPrivateAddresses(); HostAndPort getSshHostAndPort(); String getUser(); int getPort(); int execCommands(String summaryForLogging, List<String> commands); int execCommands(Map<String,?> props, String summaryForLogging, List<String> commands); int execCommands(String summaryForLogging, List<String> commands, Map<String,?> env); int execCommands(Map<String,?> props, String summaryForLogging, List<String> commands, Map<String,?> env); int execScript(String summaryForLogging, List<String> commands); int execScript(Map<String,?> props, String summaryForLogging, List<String> commands); int execScript(String summaryForLogging, List<String> commands, Map<String,?> env); int execScript(Map<String,?> props, String summaryForLogging, List<String> commands, Map<String,?> env); int copyTo(File src, File destination); int copyTo(Map<String,?> props, File src, File destination); int copyTo(File src, String destination); int copyTo(Map<String,?> props, File src, String destination); int copyTo(Reader src, String destination); int copyTo(Map<String,?> props, Reader src, String destination); int copyTo(InputStream src, String destination); int copyTo(InputStream src, long filesize, String destination); int copyTo(final Map<String,?> props, final InputStream src, final long filesize, final String destination); int copyTo(final Map<String,?> props, final InputStream src, final String destination); int copyFrom(String remote, String local); int copyFrom(final Map<String,?> props, final String remote, final String local); int installTo(String url, String destPath); int installTo(Map<String,?> props, String url, String destPath); int installTo(ResourceUtils loader, String url, String destPath); int installTo(ResourceUtils utils, Map<String,?> props, String url, String destPath); @Override String toString(); @Override String toVerboseString(); @Override boolean obtainSpecificPort(int portNumber); @Override int obtainPort(PortRange range); @Override void releasePort(int portNumber); boolean isSshable(); KeyPair findKeyPair(); String findPassword(); @Override @Deprecated void acquireMutex(String mutexId, String description); @Override @Deprecated boolean tryAcquireMutex(String mutexId, String description); @Override @Deprecated void releaseMutex(String mutexId); @Override @Deprecated boolean hasMutex(String mutexId); @Override String resolveOnBoxDirFor(Entity entity, String unresolvedPath); static final ConfigKey<String> SSH_TOOL_CLASS; static final String SSH_TOOL_CLASS_PROPERTIES_PREFIX; static final ConfigKey<Duration> SSH_CACHE_EXPIRY_DURATION; @SuppressWarnings("serial")
    static final ConfigKey<Iterable<String>> PRIVATE_ADDRESSES; @SuppressWarnings("serial")
    static final ConfigKey<Map<Integer, String>> TCP_PORT_MAPPINGS; static final ConfigKey<String> SSH_HOST; static final ConfigKey<Integer> SSH_PORT; static final ConfigKey<String> SSH_EXECUTABLE; static final ConfigKey<String> SCP_EXECUTABLE; static final ConfigKey<String> PASSWORD; static final ConfigKey<String> PRIVATE_KEY_FILE; static final ConfigKey<String> PRIVATE_KEY_DATA; static final ConfigKey<String> PRIVATE_KEY_PASSPHRASE; static final ConfigKey<String> SCRIPT_DIR; static final ConfigKey<Map<String,Object>> SSH_ENV_MAP; static final ConfigKey<Boolean> ALLOCATE_PTY; static final ConfigKey<OutputStream> STDOUT; static final ConfigKey<OutputStream> STDERR; static final ConfigKey<Boolean> NO_STDOUT_LOGGING; static final ConfigKey<Boolean> NO_STDERR_LOGGING; static final ConfigKey<String> LOG_PREFIX; static final ConfigKey<String> LOCAL_TEMP_DIR; static final ConfigKey<Boolean> CLOSE_CONNECTION; static final ConfigKey<String> UNIQUE_ID; static final Set<ConfigKey<?>> REUSABLE_SSH_PROPS; static final Set<HasConfigKey<?>> ALL_SSH_CONFIG_KEYS; static final Set<String> ALL_SSH_CONFIG_KEY_NAMES; @Beta
    static final Set<ConfigKey<?>> SSH_CONFIG_GIVEN_TO_PROPS; }
@Test public void testDoesNotLogPasswordsInEnvironmentVariables() { List<String> loggerNames = ImmutableList.of( SshMachineLocation.class.getName(), BrooklynLogging.SSH_IO, SshjTool.class.getName()); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.or( EventPredicates.containsMessage("DB_PASSWORD"), EventPredicates.containsMessage("mypassword")); try (LogWatcher watcher = new LogWatcher(loggerNames, logLevel, filter)) { host.execCommands("mySummary", ImmutableList.of("true"), ImmutableMap.of("DB_PASSWORD", "mypassword")); watcher.assertHasEventEventually(); Optional<ILoggingEvent> eventWithPasswd = Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage("mypassword")); assertFalse(eventWithPasswd.isPresent(), "event="+eventWithPasswd); } }
@Test public void testLogsStdoutAndStderr() { RecordingSshTool.setCustomResponse(".*mycommand.*", new CustomResponse(0, "mystdout1\nmystdout2", "mystderr1\nmystderr2")); List<String> loggerNames = ImmutableList.of( SshMachineLocation.class.getName(), BrooklynLogging.SSH_IO, SshjTool.class.getName()); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.alwaysTrue(); try (LogWatcher watcher = new LogWatcher(loggerNames, logLevel, filter)) { host.execCommands("mySummary", ImmutableList.of("mycommand")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stdout] mystdout1")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stdout] mystdout2")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stderr] mystderr1")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stderr] mystderr2")); } }
@Test public void testTurningOffLoggingStdoutAndStderr() { RecordingSshTool.setCustomResponse(".*mycommand.*", new CustomResponse(0, "mystdout1\nmystdout2", "mystderr1\nmystderr2")); List<String> loggerNames = ImmutableList.of( SshMachineLocation.class.getName(), BrooklynLogging.SSH_IO, SshjTool.class.getName()); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.alwaysTrue(); try (LogWatcher watcher = new LogWatcher(loggerNames, logLevel, filter)) { host.execCommands( ImmutableMap.of(SshMachineLocation.NO_STDOUT_LOGGING.getName(), true, SshMachineLocation.NO_STDERR_LOGGING.getName(), true), "mySummary", ImmutableList.of("mycommand")); assertFalse(Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage(":stdout]")).isPresent()); assertFalse(Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage(":stderr]")).isPresent()); } }