@VisibleForTesting public String execAsRoot(String command) { if (node.getCredentials().identity.equals("root")) { } else if (node.getCredentials().shouldAuthenticateSudo()) { command = String.format("sudo -S sh <<'%s'\n%s\n%s%s\n", MARKER, node.getCredentials().getPassword(), command, MARKER); } else { command = String.format("sudo sh <<'%s'\n%s%s\n", MARKER, command, MARKER); } return command; }
@VisibleForTesting public String execAsRoot(String command) { if (node.getCredentials().identity.equals("root")) { } else if (node.getCredentials().shouldAuthenticateSudo()) { command = String.format("sudo -S sh <<'%s'\n%s\n%s%s\n", MARKER, node.getCredentials().getPassword(), command, MARKER); } else { command = String.format("sudo sh <<'%s'\n%s%s\n", MARKER, command, MARKER); } return command; }
@VisibleForTesting String execScriptAsRoot(String action) { String command; if (node.getCredentials().identity.equals("root")) { command = initFile + " " + action; } else if (node.getCredentials().shouldAuthenticateSudo()) { command = String.format("echo '%s'|sudo -S %s %s", node.getCredentials().getPassword(), initFile, action); } else { command = "sudo " + initFile + " " + action; } return command; }
@Override public NodeMetadata apply(NodeMetadata input) { input = super.apply(input); if (input.getCredentials() != null) credentialStore.put("node#" + input.getId(), input.getCredentials()); return input; }
@Override public NodeMetadata apply(NodeMetadata input) { input = super.apply(input); if (input.getCredentials() != null) credentialStore.put("node#" + input.getId(), input.getCredentials()); return input; }
@Override public NodeMetadata apply(NodeMetadata input) { input = super.apply(input); if (input.getCredentials() != null) credentialStore.put("node#" + input.getId(), input.getCredentials()); return input; }
public NodeWithInitialCredentials(NodeMetadata node) { super(node, node.getId(), node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
@Override public SshClient apply(NodeMetadata node) { checkState(sshFactory != null, "ssh requested, but no SshModule configured"); checkNotNull(node.getCredentials(), "no credentials found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkArgument(node.getCredentials().credential != null || sshFactory.isAgentAvailable(), "no credential or ssh agent found for %s on node %s", node .getCredentials().identity, node.getId()); HostAndPort socket = openSocketFinder.findOpenSocketOnNode(node, node.getLoginPort(), timeoutMs, TimeUnit.MILLISECONDS); return sshFactory.create(socket, node.getCredentials()); } }
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
@Override public Instance apply(NodeMetadata node) { return new Instance(node.getCredentials(), roles, Iterables.get(node.getPublicAddresses().size() > 0 ? node.getPublicAddresses() : node.getPrivateAddresses(), 0), Iterables.get(node.getPrivateAddresses().size() > 0 ? node.getPrivateAddresses() : node.getPublicAddresses(), 0), node.getId(), node); } }));
@Override public NodeMetadata apply(NodeMetadata input) { if (statement == null) return input; Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement); if (credentials != null) { LoginCredentials creds = LoginCredentials.fromCredentials(credentials); input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(creds).build(); credentialStore.put("node#" + input.getId(), input.getCredentials()); } return input; }
@Override public NodeMetadata apply(NodeMetadata input) { if (statement == null) return input; Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement); if (credentials != null) { LoginCredentials creds = LoginCredentials.fromCredentials(credentials); input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(creds).build(); credentialStore.put("node#" + input.getId(), input.getCredentials()); } return input; }
@BeforeMethod(groups = { "unit" }) public void init() { sshClient = createMock(SshClient.class); sshFactory = new Function<NodeMetadata, SshClient>() { @Override public SshClient apply(@Nullable NodeMetadata nodeMetadata) { return sshClient; } }; node = createMock(NodeMetadata.class); expect(node.getCredentials()).andReturn(LoginCredentials.builder().user("tester").password("notalot").build()).atLeastOnce(); replay(node); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) { return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId()).location( node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tags(node.getTags()).group( node.getGroup()).hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem( node.getOperatingSystem()).status(node.getStatus()).backendStatus(node.getBackendStatus()).loginPort( node.getLoginPort()).publicAddresses(node.getPublicAddresses()).privateAddresses( node.getPrivateAddresses()).credentials(node.getCredentials()).hostname(node.getHostname()); }