Issue 695: Implemented create ssh key request.

This commit is contained in:
Jason King 2011-12-13 13:38:57 +00:00
parent 9b0ea8f16f
commit ab01343a42
4 changed files with 60 additions and 0 deletions

View File

@ -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<SSHKey> getSSHKey(@EndpointParam URI uri);
/**
* @see SSHKeyClient#createSSHKey
*/
@POST
@Consumes("application/vnd.tmrk.cloud.admin.sshKey")
@JAXBResponseParser
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Payload("<CreateSshKey name='{name}'><Default>{defaultKey}</Default></CreateSshKey>")
@Produces(MediaType.APPLICATION_XML)
public ListenableFuture<SSHKey> createSSHKey(@EndpointParam URI uri, @PayloadParam("name")String name, @PayloadParam("defaultKey")boolean defaultKey);
}

View File

@ -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);
}

View File

@ -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 = "<CreateSshKey name='myKey'><Default>true</Default></CreateSshKey>";
assertPayloadEquals(httpRequest, xml, "application/xml", false);
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<SSHKeyAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<SSHKeyAsyncClient>>() {

View File

@ -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());
}
}