Issue 452: removed need to base64

This commit is contained in:
Adrian Cole 2011-01-28 16:49:37 -08:00
parent f0a4a23265
commit 48e9f6b7bb
8 changed files with 42 additions and 27 deletions

View File

@ -54,9 +54,11 @@ Here are the properties:
* tags - optional; list of arbitrary tags.
* note this list is not yet in jclouds NodeMetadata
* username - primary login user to the os. ex. ubuntu, vcloud, root
* sudo_password - optional; base 64 encoded sudo password (ex. input to sudo -S)
* sudo_password - optional; sudo password (ex. input to sudo -S)
* if not set and an sudo command is attempted, it will attempt
without a password
one of:
* credential - base 64 encoded RSA private key or password
* credential - RSA private key or password
* credential_url - location of plain-text RSA private key or password.
ex. file:///home/me/.ssh/id_rsa
classpath:///id_rsa
@ -76,5 +78,10 @@ nodes:
tags:
- vanilla
username: myUser
credential: ZmFuY3lmb290
sudo_password: c3Vkbw==
credential: |
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAuzaE6azgUxwESX1rCGdJ5xpdrc1XC311bOGZBCE8NA+CpFh2
u01Vfv68NC4u6LFgdXSY1vQt6hiA5TNqQk0TyVfFAunbXgTekF6XqDPQUf1nq9aZ
lMvo4vlaLDKBkhG5HJE/pIa0iB+RMZLS0GhxsIWerEDmYdHKM25o
-----END RSA PRIVATE KEY-----
sudo_password: go panthers!

View File

@ -36,13 +36,11 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.util.Strings2;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
@ -76,8 +74,8 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
builder.tag(from.getGroup());
// TODO add tags!
builder.operatingSystem(new OperatingSystemBuilder().arch(from.getOsArch()).family(
OsFamily.fromValue(from.getOsFamily())).description(from.getOsDescription()).version(
from.getOsVersion()).build());
OsFamily.fromValue(from.getOsFamily())).description(from.getOsDescription())
.version(from.getOsVersion()).build());
builder.state(NodeState.RUNNING);
builder.publicAddresses(ImmutableSet.<String> of(from.getHostname()));
@ -91,8 +89,7 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
logger.error(e, "URI could not be read: %s", from.getCredentialUrl());
}
} else if (from.getCredential() != null) {
creds = new Credentials(from.getUsername(), new String(CryptoStreams.base64(from.getCredential()),
Charsets.UTF_8));
creds = new Credentials(from.getUsername(), from.getCredential());
}
if (creds != null)
builder.credentials(creds);
@ -100,7 +97,7 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
}
if (from.getSudoPassword() != null)
builder.adminPassword(new String(CryptoStreams.base64(from.getSudoPassword()), Charsets.UTF_8));
builder.adminPassword(from.getSudoPassword());
return builder.build();
}
}

View File

@ -53,10 +53,10 @@ import com.google.common.collect.Maps;
* tags:
* - vanilla
* username: kelvin
* credential: password_or_rsa_in_base64
* credential: password_or_rsa
* or
* credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa.pub; file://path/to/id_rsa
* sudo_password: password_in_base64
* credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa; file://path/to/id_rsa
* sudo_password: password
* </pre>
*
* @author Kelvin Kakugawa

View File

@ -50,10 +50,9 @@ public class NodeToNodeMetadataTest {
public static final NodeMetadata TEST1 = new NodeMetadataBuilder().ids("cluster-1").tag("hadoop").name("cluster-1")
.location(location).state(NodeState.RUNNING).operatingSystem(
new OperatingSystemBuilder().description("redhat").family(OsFamily.RHEL)
.arch("x86").version("5.3").build()).publicAddresses(
ImmutableSet.of("cluster-1.mydomain.com")).credentials(new Credentials("myUser", "fancyfoot"))
.adminPassword("sudo").build();
new OperatingSystemBuilder().description("redhat").family(OsFamily.RHEL).arch("x86")
.version("5.3").build()).publicAddresses(ImmutableSet.of("cluster-1.mydomain.com"))
.credentials(new Credentials("myUser", NodesFromYamlTest.key)).adminPassword("happy bear").build();
@Test
public void testNodesParse() throws Exception {
@ -64,7 +63,7 @@ public class NodeToNodeMetadataTest {
new SupplyFromProviderURIOrNodesProperty(URI.create("test")), credentialStore);
assertEquals(parser.apply(NodesFromYamlTest.TEST1), TEST1);
assertEquals(credentialStore, ImmutableMap.of("node#cluster-1", new Credentials("myUser", "fancyfoot")));
assertEquals(credentialStore, ImmutableMap.of("node#cluster-1", new Credentials("myUser", NodesFromYamlTest.key)));
}
}

View File

@ -24,7 +24,6 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.byon.Node;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
@ -36,11 +35,15 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole
*/
public class NodesFromYamlTest {
public static final String key = new StringBuilder().append("-----BEGIN RSA PRIVATE KEY-----\n").append(
"MIIEowIBAAKCAQEAuzaE6azgUxwESX1rCGdJ5xpdrc1XC311bOGZBCE8NA+CpFh2\n").append(
"u01Vfv68NC4u6LFgdXSY1vQt6hiA5TNqQk0TyVfFAunbXgTekF6XqDPQUf1nq9aZ\n").append(
"lMvo4vlaLDKBkhG5HJE/pIa0iB+RMZLS0GhxsIWerEDmYdHKM25o\n").append("-----END RSA PRIVATE KEY-----\n")
.toString();
public static final Node TEST1 = new Node("cluster-1", "cluster-1", "accounting analytics cluster",
"cluster-1.mydomain.com", "x86", "rhel", "redhat", "5.3", "hadoop", ImmutableList
.of("vanilla"), "myUser", CryptoStreams.base64("fancyfoot".getBytes()), null, CryptoStreams
.base64("sudo".getBytes()));
"cluster-1.mydomain.com", "x86", "rhel", "redhat", "5.3", "hadoop", ImmutableList.of("vanilla"), "myUser",
key, null, "happy bear");
@Test
public void testNodesParse() throws Exception {

View File

@ -11,5 +11,10 @@ nodes:
tags:
- vanilla
username: myUser
credential: ZmFuY3lmb290
sudo_password: c3Vkbw==
credential: |
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAuzaE6azgUxwESX1rCGdJ5xpdrc1XC311bOGZBCE8NA+CpFh2
u01Vfv68NC4u6LFgdXSY1vQt6hiA5TNqQk0TyVfFAunbXgTekF6XqDPQUf1nq9aZ
lMvo4vlaLDKBkhG5HJE/pIa0iB+RMZLS0GhxsIWerEDmYdHKM25o
-----END RSA PRIVATE KEY-----
sudo_password: happy bear

View File

@ -12,4 +12,4 @@ nodes:
- vanilla
username: myUser
credential_url: classpath:///testkey.txt
sudo_password: c3Vkbw==
sudo_password: happy bear

View File

@ -1 +1,5 @@
fancyfoot
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAuzaE6azgUxwESX1rCGdJ5xpdrc1XC311bOGZBCE8NA+CpFh2
u01Vfv68NC4u6LFgdXSY1vQt6hiA5TNqQk0TyVfFAunbXgTekF6XqDPQUf1nq9aZ
lMvo4vlaLDKBkhG5HJE/pIa0iB+RMZLS0GhxsIWerEDmYdHKM25o
-----END RSA PRIVATE KEY-----