diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java index cd8280f6f2..6fcb5dc17e 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java @@ -27,6 +27,9 @@ import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys; import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; import java.net.URI; /** @@ -60,4 +63,15 @@ public interface SSHKeyAsyncClient { @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) public ListenableFuture getSSHKey(@EndpointParam URI uri); + + /** + * @see SSHKeyClient#createSSHKey + */ + @POST + @Consumes("application/vnd.tmrk.cloud.admin.sshKey") + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Payload("{defaultKey}") + @Produces(MediaType.APPLICATION_XML) + public ListenableFuture createSSHKey(@EndpointParam URI uri, @PayloadParam("name")String name, @PayloadParam("defaultKey")boolean defaultKey); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java index f524e6be47..a75147159a 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java @@ -55,5 +55,24 @@ public interface SSHKeyClient { * @return the SSHKey */ public SSHKey getSSHKey(URI uri); + + /** + * The createSSHKey call creates a new SSH key. + * If successful, the call returns information regarding the SSH key that was created. + * The name is required. + * Note: The name may not be that of another SSH key and may not exceed fifty characters. + * For the first key being created for an organization default should be true. + * To make the key the default, use true + * + * In the returned SSHKey: + * FingerPrint is the SSH key fingerprint, which is a 16 byte hash of the private key. + * PrivateKey is the actual private key, which has been encoded by base64. + * @param uri the uri of the createSshKey action based upon the organisation + * e.g. /cloudapi/ecloud/admin/sshkeys/organizations/{id}/action/createsshkey + * @param name the desired name of the key + * @param defaultKey to make the key the default one + * @return the ssh key + */ + public SSHKey createSSHKey(URI uri, String name, boolean defaultKey); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java index 99565cd295..8bbbe90cd5 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java @@ -68,6 +68,22 @@ public class SSHKeyAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClie checkFilters(httpRequest); } + public void testCreateSSHKey() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException { + Method method = SSHKeyAsyncClient.class.getMethod("createSSHKey", URI.class,String.class,boolean.class); + HttpRequest httpRequest = processor.createRequest(method, new URI("/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"),"myKey",true); + + assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, + "Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n"); + String xml = "true"; + assertPayloadEquals(httpRequest, xml, "application/xml", false); + + assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + } + @Override protected TypeLiteral> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java index 71d4b79fa6..fc06df6c28 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java @@ -25,6 +25,8 @@ import org.testng.annotations.Test; import java.net.URI; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; /** @@ -55,4 +57,13 @@ public class SSHKeyClientLiveTest extends BaseTerremarkEnterpriseCloudClientLive assertNotNull(sshKey); assertNotNull(sshKey.getFingerPrint()); } + + public void testCreateSSHKey() { + SSHKey sshKey = client.createSSHKey(URI.create("/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey"),"mylivetestkey",false); + assertNotNull(sshKey); + assertEquals(sshKey.getName(),"mylivetestkey"); + assertFalse(sshKey.isDefaultKey()); + assertFalse(sshKey.getFingerPrint().isEmpty()); + assertFalse(sshKey.getPrivateKey().isEmpty()); + } } \ No newline at end of file