Updated Branches: refs/heads/master 0e4107c00 -> db4031a46
PROVISIONR-1. Allow user to configure the ssh key pair used by the shell commands Ioannis Canellos via Andrei Savu Project: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/commit/db4031a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/tree/db4031a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-provisionr/diff/db4031a4 Branch: refs/heads/master Commit: db4031a4627d1e7bb8110baa608228920fea4ec9 Parents: 0e4107c Author: Andrei Savu <[email protected]> Authored: Tue Apr 9 12:59:51 2013 +0300 Committer: Andrei Savu <[email protected]> Committed: Tue Apr 9 12:59:51 2013 +0300 ---------------------------------------------------------------------- .../apache/provisionr/commands/CreateCommand.java | 35 ++++++++++++-- .../provisionr/commands/CreateImageCommand.java | 5 +- .../provisionr/commands/CreatePoolCommand.java | 5 +- .../main/resources/OSGI-INF/blueprint/context.xml | 15 ++++++- .../provisionr/commands/CreatePoolCommandTest.java | 11 +++- 5 files changed, 58 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/db4031a4/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java index d18239d..d2f9f66 100644 --- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java +++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateCommand.java @@ -42,13 +42,25 @@ public abstract class CreateCommand extends OsgiCommandSupport { "If not specified, defaults to 600 seconds.") protected int bootstrapTimeout = 600; + @Option(name = "--public-key-path", description = "Path to the public key. " + + "The default value can be overridden in org.apache.provisionr.core") + private String publicKeyPath; + + @Option(name = "--private-key-path", description = "Path to the private key. " + + "The default value can be overridden in org.apache.provisionr.core") + private String privateKeyPath; + protected final List<Provisionr> services; protected final List<PoolTemplate> templates; - public CreateCommand(List<Provisionr> services, List<PoolTemplate> templates) { + public CreateCommand(List<Provisionr> services, List<PoolTemplate> templates, + String publicKeyPath, String privateKeyPath) { this.services = checkNotNull(services, "services is null"); this.templates = checkNotNull(templates, "templates is null"); + + this.publicKeyPath = checkNotNull(publicKeyPath, "publicKeyPath is null"); + this.privateKeyPath = checkNotNull(privateKeyPath, "privateKeyPath is null"); } @VisibleForTesting @@ -67,12 +79,25 @@ public abstract class CreateCommand extends OsgiCommandSupport { } @VisibleForTesting - AdminAccess collectCurrentUserCredentialsForAdminAccess() { - String userHome = System.getProperty("user.home"); + void setBootstrapTimeout(int bootstrapTimeout) { + this.bootstrapTimeout = bootstrapTimeout; + } + @VisibleForTesting + void setPublicKeyPath(String publicKeyPath) { + this.publicKeyPath = checkNotNull(publicKeyPath, "publicKeyPath is null"); + } + + @VisibleForTesting + void setPrivateKeyPath(String privateKeyPath) { + this.privateKeyPath = checkNotNull(privateKeyPath, "privateKeyPath is null"); + } + + @VisibleForTesting + AdminAccess collectCurrentUserCredentialsForAdminAccess() { try { - String publicKey = Files.toString(new File(userHome, ".ssh/id_rsa.pub"), Charsets.UTF_8); - String privateKey = Files.toString(new File(userHome, ".ssh/id_rsa"), Charsets.UTF_8); + String publicKey = Files.toString(new File(publicKeyPath), Charsets.UTF_8); + String privateKey = Files.toString(new File(privateKeyPath), Charsets.UTF_8); return AdminAccess.builder().username(System.getProperty("user.name")) .publicKey(publicKey).privateKey(privateKey).createAdminAccess(); http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/db4031a4/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java index 2702a70..38e7f96 100644 --- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java +++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreateImageCommand.java @@ -16,8 +16,9 @@ public class CreateImageCommand extends CreateCommand { // TODO: remove this and use a provided parameter private static final String HARDWARE_TYPE = "t1.micro"; - public CreateImageCommand(List<Provisionr> services, List<PoolTemplate> templates) { - super(services, templates); + public CreateImageCommand(List<Provisionr> services, List<PoolTemplate> templates, + String publicKeyPath, String privateKeyPath) { + super(services, templates, publicKeyPath, privateKeyPath); } @Override http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/db4031a4/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java index 2d9439e..f2d84ea 100644 --- a/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java +++ b/karaf/commands/src/main/java/org/apache/provisionr/commands/CreatePoolCommand.java @@ -74,8 +74,9 @@ public class CreatePoolCommand extends CreateCommand { "or not. If creating the machines from an existent image, software might already be installed.") private boolean cachedImage = false; - public CreatePoolCommand(List<Provisionr> services, List<PoolTemplate> templates) { - super(services, templates); + public CreatePoolCommand(List<Provisionr> services, List<PoolTemplate> templates, + String publicKeyPath, String privateKeyPath) { + super(services, templates, publicKeyPath, privateKeyPath); } @Override http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/db4031a4/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml b/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml index b26cbbe..5a1c0e3 100644 --- a/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml +++ b/karaf/commands/src/main/resources/OSGI-INF/blueprint/context.xml @@ -17,7 +17,18 @@ <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.0.0" - > + xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" + xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"> + + <!-- Allow usage of System properties, especially the karaf.base property --> + <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/> + + <cm:property-placeholder persistent-id="org.apache.provisionr.core" update-strategy="reload"> + <cm:default-properties> + <cm:property name="privateKeyPath" value="$[user.home]/.ssh/id_rsa"/> + <cm:property name="publicKeyPath" value="$[user.home]/.ssh/id_rsa.pub"/> + </cm:default-properties> + </cm:property-placeholder> <reference-list id="provisionrServices" interface="org.apache.provisionr.api.Provisionr" availability="optional" activation="eager"/> @@ -47,6 +58,8 @@ <shell:action class="org.apache.provisionr.commands.CreatePoolCommand"> <shell:argument ref="provisionrServices"/> <shell:argument ref="templates"/> + <shell:argument value="${publicKeyPath}"/> + <shell:argument value="${privateKeyPath}"/> </shell:action> </shell:command> <shell:command name="provisionr/destroy"> http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/db4031a4/karaf/commands/src/test/java/org/apache/provisionr/commands/CreatePoolCommandTest.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/test/java/org/apache/provisionr/commands/CreatePoolCommandTest.java b/karaf/commands/src/test/java/org/apache/provisionr/commands/CreatePoolCommandTest.java index d48487e..1bef856 100644 --- a/karaf/commands/src/test/java/org/apache/provisionr/commands/CreatePoolCommandTest.java +++ b/karaf/commands/src/test/java/org/apache/provisionr/commands/CreatePoolCommandTest.java @@ -50,6 +50,9 @@ public class CreatePoolCommandTest { public static final String TEST_PROVISIONR_ID = "amazon"; public static final String TEST_BUSINESS_KEY = "j-123"; + public static final String PATH_TO_PUBLIC_KEY = System.getProperty("user.home") + "/.ssh/id_rsa.pub"; + public static final String PATH_TO_PRIVATE_KEY = System.getProperty("user.home") + "/.ssh/id_rsa"; + @Rule public ExpectedException exception = ExpectedException.none(); @@ -60,7 +63,8 @@ public class CreatePoolCommandTest { final List<Provisionr> services = ImmutableList.of(service); final List<PoolTemplate> templates = ImmutableList.of(); - CreatePoolCommand command = new CreatePoolCommand(services, templates) { + CreatePoolCommand command = new CreatePoolCommand(services, templates, + PATH_TO_PUBLIC_KEY, PATH_TO_PRIVATE_KEY) { @Override protected Pool createPoolFromArgumentsAndServiceDefaults(Provisionr service) { return pool; @@ -79,7 +83,7 @@ public class CreatePoolCommandTest { @Test(expected = NoSuchElementException.class) public void testProvisioningServiceNotFound() throws Exception { CreatePoolCommand command = new CreatePoolCommand(Collections.<Provisionr>emptyList(), - Collections.<PoolTemplate>emptyList()); + Collections.<PoolTemplate>emptyList(), PATH_TO_PUBLIC_KEY, PATH_TO_PRIVATE_KEY); command.setId("dummy"); CommandSession session = mock(CommandSession.class); @@ -193,7 +197,8 @@ public class CreatePoolCommandTest { private CreatePoolCommand newPoolCommandWithMockedAdminAccess(PoolTemplate template) { List<PoolTemplate> templates = template != null ? ImmutableList.<PoolTemplate>of(template) : ImmutableList.<PoolTemplate>of(); - return new CreatePoolCommand(Collections.<Provisionr>emptyList(), templates) { + return new CreatePoolCommand(Collections.<Provisionr>emptyList(), templates, + PATH_TO_PUBLIC_KEY, PATH_TO_PRIVATE_KEY) { @Override protected AdminAccess collectCurrentUserCredentialsForAdminAccess() { return mock(AdminAccess.class);
