From 48e9f6b7bba3c34d724efc76a497965396830835 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 28 Jan 2011 16:49:37 -0800 Subject: [PATCH] Issue 452: removed need to base64 --- sandbox-apis/byon/README.txt | 15 +++++++++++---- .../byon/functions/NodeToNodeMetadata.java | 11 ++++------- .../org/jclouds/byon/functions/NodesFromYaml.java | 6 +++--- .../byon/functions/NodeToNodeMetadataTest.java | 9 ++++----- .../jclouds/byon/functions/NodesFromYamlTest.java | 11 +++++++---- sandbox-apis/byon/src/test/resources/test1.yaml | 9 +++++++-- .../byon/src/test/resources/test_with_url.yaml | 2 +- sandbox-apis/byon/src/test/resources/testkey.txt | 6 +++++- 8 files changed, 42 insertions(+), 27 deletions(-) diff --git a/sandbox-apis/byon/README.txt b/sandbox-apis/byon/README.txt index 2eeda5bf07..f066da6fa6 100644 --- a/sandbox-apis/byon/README.txt +++ b/sandbox-apis/byon/README.txt @@ -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! diff --git a/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java b/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java index 1c9ca1b8c5..c51b6d9f2e 100644 --- a/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java +++ b/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodeToNodeMetadata.java @@ -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 { 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. of(from.getHostname())); @@ -91,8 +89,7 @@ public class NodeToNodeMetadata implements Function { 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 { } if (from.getSudoPassword() != null) - builder.adminPassword(new String(CryptoStreams.base64(from.getSudoPassword()), Charsets.UTF_8)); + builder.adminPassword(from.getSudoPassword()); return builder.build(); } } diff --git a/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYaml.java b/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYaml.java index 40a63e6012..fd6d15843b 100644 --- a/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYaml.java +++ b/sandbox-apis/byon/src/main/java/org/jclouds/byon/functions/NodesFromYaml.java @@ -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 * * * @author Kelvin Kakugawa diff --git a/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java b/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java index d70a248f96..f4fb3d828a 100644 --- a/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java +++ b/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodeToNodeMetadataTest.java @@ -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))); } } diff --git a/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodesFromYamlTest.java b/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodesFromYamlTest.java index ab0095b09e..614e67acee 100644 --- a/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodesFromYamlTest.java +++ b/sandbox-apis/byon/src/test/java/org/jclouds/byon/functions/NodesFromYamlTest.java @@ -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 { diff --git a/sandbox-apis/byon/src/test/resources/test1.yaml b/sandbox-apis/byon/src/test/resources/test1.yaml index 52082bc4d3..2711c5989b 100644 --- a/sandbox-apis/byon/src/test/resources/test1.yaml +++ b/sandbox-apis/byon/src/test/resources/test1.yaml @@ -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 diff --git a/sandbox-apis/byon/src/test/resources/test_with_url.yaml b/sandbox-apis/byon/src/test/resources/test_with_url.yaml index b41f08b790..4819f1ffa8 100644 --- a/sandbox-apis/byon/src/test/resources/test_with_url.yaml +++ b/sandbox-apis/byon/src/test/resources/test_with_url.yaml @@ -12,4 +12,4 @@ nodes: - vanilla username: myUser credential_url: classpath:///testkey.txt - sudo_password: c3Vkbw== + sudo_password: happy bear diff --git a/sandbox-apis/byon/src/test/resources/testkey.txt b/sandbox-apis/byon/src/test/resources/testkey.txt index adebd2d619..4402ea1f8c 100644 --- a/sandbox-apis/byon/src/test/resources/testkey.txt +++ b/sandbox-apis/byon/src/test/resources/testkey.txt @@ -1 +1,5 @@ -fancyfoot \ No newline at end of file +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAuzaE6azgUxwESX1rCGdJ5xpdrc1XC311bOGZBCE8NA+CpFh2 +u01Vfv68NC4u6LFgdXSY1vQt6hiA5TNqQk0TyVfFAunbXgTekF6XqDPQUf1nq9aZ +lMvo4vlaLDKBkhG5HJE/pIa0iB+RMZLS0GhxsIWerEDmYdHKM25o +-----END RSA PRIVATE KEY----- \ No newline at end of file