@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().getOptionalPassword ().get(), 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 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().getOptionalPassword ().get(), 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().getOptionalPassword().get(), initFile, action); } else { command = "sudo " + initFile + " " + action; } 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().getOptionalPassword().get(), initFile, action); } else { command = "sudo " + initFile + " " + action; } 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; }
public RunScriptOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { checkNotNull(overridingCredentials, "overridingCredentials"); this.loginUser = overridingCredentials.getUser(); this.loginPassword = overridingCredentials.getOptionalPassword(); this.loginPrivateKey = overridingCredentials.getOptionalPrivateKey(); this.authenticateSudo = overridingCredentials.shouldAuthenticateSudo() ? true : null; return this; }
public RunScriptOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { checkNotNull(overridingCredentials, "overridingCredentials"); this.loginUser = overridingCredentials.getUser(); this.loginPassword = overridingCredentials.getOptionalPassword(); this.loginPrivateKey = overridingCredentials.getOptionalPrivateKey(); this.authenticateSudo = overridingCredentials.shouldAuthenticateSudo() ? true : null; return this; }
@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; }
public RunScriptOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { checkNotNull(overridingCredentials, "overridingCredentials"); this.loginUser = overridingCredentials.getUser(); this.loginPassword = overridingCredentials.getOptionalPassword(); this.loginPrivateKey = overridingCredentials.getOptionalPrivateKey(); this.authenticateSudo = overridingCredentials.shouldAuthenticateSudo() ? true : null; return this; }
public RunScriptOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { checkNotNull(overridingCredentials, "overridingCredentials"); this.loginUser = overridingCredentials.getUser(); this.loginPassword = overridingCredentials.getOptionalPassword(); this.loginPrivateKey = overridingCredentials.getOptionalPrivateKey(); this.authenticateSudo = overridingCredentials.shouldAuthenticateSudo() ? true : null; return this; }
@Override public InputStream apply(Credentials from) { checkNotNull(from, "inputCredentials"); if (from instanceof LoginCredentials) { LoginCredentials login = LoginCredentials.class.cast(from); JsonLoginCredentials val = new JsonLoginCredentials(); val.user = login.getUser(); val.password = login.getPassword(); val.privateKey = login.getPrivateKey(); if (login.shouldAuthenticateSudo()) val.authenticateSudo = login.shouldAuthenticateSudo(); return Strings2.toInputStream(json.toJson(val)); } return Strings2.toInputStream(json.toJson(from)); } }
@Override public InputStream apply(Credentials from) { checkNotNull(from, "inputCredentials"); if (from instanceof LoginCredentials) { LoginCredentials login = LoginCredentials.class.cast(from); JsonLoginCredentials val = new JsonLoginCredentials(); val.user = login.getUser(); val.password = login.getPassword(); val.privateKey = login.getPrivateKey(); if (login.shouldAuthenticateSudo()) val.authenticateSudo = login.shouldAuthenticateSudo(); return Strings2.toInputStream(json.toJson(val)); } return Strings2.toInputStream(json.toJson(from)); } }
@Override public InputStream apply(Credentials from) { checkNotNull(from, "inputCredentials"); if (from instanceof LoginCredentials) { LoginCredentials login = LoginCredentials.class.cast(from); JsonLoginCredentials val = new JsonLoginCredentials(); val.user = login.getUser(); val.password = login.getPassword(); val.privateKey = login.getPrivateKey(); if (login.shouldAuthenticateSudo()) val.authenticateSudo = login.shouldAuthenticateSudo(); return Strings2.toInputStream(json.toJson(val)); } return Strings2.toInputStream(json.toJson(from)); } }
public LoginCredentials apply(Template template, LoginCredentials fromNode) { LoginCredentials creds = fromNode; LoginCredentials credsFromParameters = credentialsFromImageOrTemplateOptions.apply(template); if (credsFromParameters != null) { Builder builder = LoginCredentials.builder(creds); if (credsFromParameters.getUser() != null) builder.user(credsFromParameters.getUser()); if (credsFromParameters.getOptionalPassword().isPresent()) builder.password(credsFromParameters.getOptionalPassword().get()); if (credsFromParameters.getOptionalPrivateKey().isPresent()) builder.privateKey(credsFromParameters.getOptionalPrivateKey().get()); if (credsFromParameters.shouldAuthenticateSudo()) builder.authenticateSudo(true); creds = builder.build(); } return creds; }
@Override public LoginCredentials apply(@Nullable org.jclouds.domain.LoginCredentials input) { if (input == null) { return null; } return LoginCredentials.builder().username(input.getUser()).password(input.getPassword()) .privateKey(input.getPrivateKey()).authenticateSudo(input.shouldAuthenticateSudo()) .build(); } }
public void testCredentialsToByteSourceConversion() throws Exception { Function<Credentials, ByteSource> toBytesFunc = getCredentialsToByteStoreFunction(createInjector()); Function<ByteSource, Credentials> fromBytesFunc = getByteStoreToCredentialsFunction(createInjector()); LoginCredentials creds = LoginCredentials.builder().user("myuser").password("mypass").authenticateSudo(true).build(); ByteSource bytes = toBytesFunc.apply(creds); LoginCredentials deserializedCreds = (LoginCredentials) fromBytesFunc.apply(bytes); String json = bytes.asCharSource(Charsets.UTF_8).read(); assertEquals(json, "{\"user\":\"myuser\",\"password\":\"mypass\",\"authenticateSudo\":true}"); assertEquals(deserializedCreds.identity, creds.identity); assertEquals(deserializedCreds.credential, creds.credential); assertEquals(deserializedCreds.getUser(), creds.getUser()); assertEquals(deserializedCreds.getOptionalPassword(), creds.getOptionalPassword()); assertEquals(deserializedCreds.getOptionalPrivateKey(), creds.getOptionalPrivateKey()); assertEquals(deserializedCreds.shouldAuthenticateSudo(), creds.shouldAuthenticateSudo()); }
public LoginCredentials apply(Template template, LoginCredentials fromNode) { LoginCredentials creds = fromNode; LoginCredentials credsFromParameters = credentialsFromImageOrTemplateOptions.apply(template); if (credsFromParameters != null) { Builder builder = LoginCredentials.builder(creds); if (credsFromParameters.getUser() != null) builder.user(credsFromParameters.getUser()); if (credsFromParameters.getPassword() != null) builder.password(credsFromParameters.getPassword()); if (credsFromParameters.getPrivateKey() != null) builder.privateKey(credsFromParameters.getPrivateKey()); if (credsFromParameters.shouldAuthenticateSudo()) builder.authenticateSudo(true); creds = builder.build(); } return creds; }
public LoginCredentials apply(Template template, LoginCredentials fromNode) { LoginCredentials creds = fromNode; LoginCredentials credsFromParameters = credentialsFromImageOrTemplateOptions.apply(template); if (credsFromParameters != null) { Builder builder = LoginCredentials.builder(creds); if (credsFromParameters.getUser() != null) builder.user(credsFromParameters.getUser()); if (credsFromParameters.getPassword() != null) builder.password(credsFromParameters.getPassword()); if (credsFromParameters.getPrivateKey() != null) builder.privateKey(credsFromParameters.getPrivateKey()); if (credsFromParameters.shouldAuthenticateSudo()) builder.authenticateSudo(true); creds = builder.build(); } return creds; }