use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(SshPairImpl.class, UserImpl.class, AccountImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(SshDao.class).to(JpaSshDao.class);
bind(new TypeLiteral<TckRepository<SshPairImpl>>() {
}).toInstance(new JpaTckRepository<>(SshPairImpl.class));
bind(new TypeLiteral<TckRepository<UserImpl>>() {
}).toInstance(new JpaTckRepository<>(UserImpl.class));
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class KeysInjectorTest method shouldInjectSshKeysWhenThereIsNoPublicWorkspaceKeyButMachineKeys.
/**
* Validate the usecase: There is a workspace sshkeypair (without public key) but there is a machine keypair
* Expect that only the machine keypair is injected (as workspace keypair has no public key).
*/
@Test
public void shouldInjectSshKeysWhenThereIsNoPublicWorkspaceKeyButMachineKeys() throws Exception {
// no machine key pairs
when(sshManager.getPairs(anyString(), eq("machine"))).thenReturn(Arrays.asList(new SshPairImpl(OWNER, "machine", "myPair", "publicKey1", null)));
// workspace keypair without public key
when(sshManager.getPair(anyString(), eq("workspace"), anyString())).thenReturn(new SshPairImpl(OWNER, "workspace", WORKSPACE_ID, null, null));
subscriber.onEvent(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withMachineId(MACHINE_ID).withWorkspaceId(WORKSPACE_ID));
verify(environmentEngine).getMachine(eq(WORKSPACE_ID), eq(MACHINE_ID));
// check calls for machine and workspace ssh pairs
verify(sshManager).getPairs(eq(OWNER), eq("machine"));
verify(sshManager).getPair(eq(OWNER), eq("workspace"), eq(WORKSPACE_ID));
ArgumentCaptor<CreateExecParams> argumentCaptor = ArgumentCaptor.forClass(CreateExecParams.class);
verify(docker).createExec(argumentCaptor.capture());
assertEquals(argumentCaptor.getValue().getCmd(), new String[] { "/bin/bash", "-c", "mkdir ~/.ssh/ -p" + "&& echo 'publicKey1' >> ~/.ssh/authorized_keys" });
verify(docker).startExec(eq(StartExecParams.create(EXEC_ID)), anyObject());
verifyZeroInteractions(docker, environmentEngine, sshManager);
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class KeysInjectorTest method shouldInjectSshKeysWhenThereIsOnlyWorkspaceKey.
/**
* Validate the usecase: There is a workspace sshkeypair but no machine keypair (empty list)
* Expect that the workspace public key is injected.
*/
@Test
public void shouldInjectSshKeysWhenThereIsOnlyWorkspaceKey() throws Exception {
// no machine key pairs
when(sshManager.getPairs(anyString(), eq("machine"))).thenReturn(Collections.emptyList());
// workspace keypair
when(sshManager.getPair(anyString(), eq("workspace"), anyString())).thenReturn(new SshPairImpl(OWNER, "workspace", WORKSPACE_ID, "publicKeyWorkspace", null));
subscriber.onEvent(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withMachineId(MACHINE_ID).withWorkspaceId(WORKSPACE_ID));
verify(environmentEngine).getMachine(eq(WORKSPACE_ID), eq(MACHINE_ID));
// check calls for machine and workspace ssh pairs
verify(sshManager).getPairs(eq(OWNER), eq("machine"));
verify(sshManager).getPair(eq(OWNER), eq("workspace"), eq(WORKSPACE_ID));
ArgumentCaptor<CreateExecParams> argumentCaptor = ArgumentCaptor.forClass(CreateExecParams.class);
verify(docker).createExec(argumentCaptor.capture());
assertEquals(argumentCaptor.getValue().getCmd(), new String[] { "/bin/bash", "-c", "mkdir ~/.ssh/ -p" + "&& echo 'publicKeyWorkspace' >> ~/.ssh/authorized_keys" });
verify(docker).startExec(eq(StartExecParams.create(EXEC_ID)), anyObject());
verifyZeroInteractions(docker, environmentEngine, sshManager);
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshService method generatePair.
@POST
@Path("generate")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = Constants.LINK_REL_GENERATE_PAIR)
@ApiOperation(value = "Generate and stores ssh pair based on the request", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created ssh pair", response = SshPairDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "The ssh pair successfully generated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 409, message = "Conflict error occurred during the ssh pair generation" + "(e.g. The Ssh pair with such name and service already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response generatePair(@ApiParam(value = "The configuration to generate the new ssh pair", required = true) GenerateSshPairRequest request) throws BadRequestException, ServerException, ConflictException {
requiredNotNull(request, "Generate ssh pair request required");
requiredNotNull(request.getService(), "Service name required");
requiredNotNull(request.getName(), "Name required");
final SshPairImpl generatedPair = sshManager.generatePair(getCurrentUserId(), request.getService(), request.getName());
return Response.status(Response.Status.CREATED).entity(asDto(injectLinks(asDto(generatedPair)))).build();
}
use of org.eclipse.che.api.ssh.server.model.impl.SshPairImpl in project che by eclipse.
the class SshService method createPair.
@POST
@Consumes(APPLICATION_JSON)
@GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR)
@ApiOperation(value = "Create a new ssh pair", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created ssh pair")
@ApiResponses({ @ApiResponse(code = 204, message = "The ssh pair successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 409, message = "Conflict error occurred during the ssh pair creation" + "(e.g. The Ssh pair with such name and service already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public void createPair(@ApiParam(value = "The ssh pair to create", required = true) SshPairDto sshPair) throws BadRequestException, ServerException, ConflictException {
requiredNotNull(sshPair, "Ssh pair required");
requiredNotNull(sshPair.getService(), "Service name required");
requiredNotNull(sshPair.getName(), "Name required");
if (sshPair.getPublicKey() == null && sshPair.getPrivateKey() == null) {
throw new BadRequestException("Key content was not provided.");
}
sshManager.createPair(new SshPairImpl(getCurrentUserId(), sshPair));
}
Aggregations