use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.
the class SshKeyManagerViewImpl method initSshKeyTable.
/** Creates table what contains list of available ssh keys. */
private void initSshKeyTable(final CellTable.Resources res) {
keys = new CellTable<>(20, res);
Column<SshPairDto, String> hostColumn = new Column<SshPairDto, String>(new TextCell()) {
@Override
public String getValue(SshPairDto object) {
return object.getName();
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-title-" + context.getIndex() + "\">");
super.render(context, object, sb);
}
};
hostColumn.setSortable(true);
Column<SshPairDto, String> publicKeyColumn = new Column<SshPairDto, String>(new ButtonCell()) {
@Override
public String getValue(SshPairDto object) {
return "View";
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-key-" + context.getIndex() + "\">");
if (object != null && object.getPublicKey() != null) {
super.render(context, object, sb);
}
}
};
// Creates handler on button clicked
publicKeyColumn.setFieldUpdater(new FieldUpdater<SshPairDto, String>() {
@Override
public void update(int index, SshPairDto object, String value) {
delegate.onViewClicked(object);
}
});
Column<SshPairDto, String> deleteKeyColumn = new Column<SshPairDto, String>(new ButtonCell()) {
@Override
public String getValue(SshPairDto object) {
return "Delete";
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-delete-" + context.getIndex() + "\">");
super.render(context, object, sb);
}
};
// Creates handler on button clicked
deleteKeyColumn.setFieldUpdater(new FieldUpdater<SshPairDto, String>() {
@Override
public void update(int index, SshPairDto object, String value) {
delegate.onDeleteClicked(object);
}
});
keys.addColumn(hostColumn, "Title");
keys.addColumn(publicKeyColumn, "Public Key");
keys.addColumn(deleteKeyColumn, "Delete");
keys.setColumnWidth(hostColumn, 50, Style.Unit.PCT);
keys.setColumnWidth(publicKeyColumn, 30, Style.Unit.PX);
keys.setColumnWidth(deleteKeyColumn, 30, Style.Unit.PX);
// don't show loading indicator
keys.setLoadingIndicator(null);
}
use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.
the class ProcessesPanelPresenter method onPreviewSsh.
@Override
public void onPreviewSsh(String machineId) {
ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
if (machineTreeNode == null) {
return;
}
Machine machine = (Machine) machineTreeNode.getData();
final OutputConsole defaultConsole = commandConsoleFactory.create("SSH");
addCommandOutput(machineId, defaultConsole);
final String machineName = machine.getConfig().getName();
String sshServiceAddress = getSshServerAddress(machine);
final String machineHost;
final String sshPort;
if (sshServiceAddress != null) {
String[] parts = sshServiceAddress.split(":");
machineHost = parts[0];
sshPort = (parts.length == 2) ? parts[1] : SSH_PORT;
} else {
sshPort = SSH_PORT;
machineHost = "";
}
// user
final String userName;
String user = machine.getRuntime().getProperties().get("config.user");
if (isNullOrEmpty(user)) {
userName = "root";
} else {
userName = user;
}
// ssh key
final String workspaceName = appContext.getWorkspace().getConfig().getName();
Promise<SshPairDto> sshPairDtoPromise = sshServiceClient.getPair("workspace", machine.getWorkspaceId());
sshPairDtoPromise.then(new Operation<SshPairDto>() {
@Override
public void apply(SshPairDto sshPairDto) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoPrivateKey(sshPairDto.getPrivateKey())));
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoNoPrivateKey()));
}
}
});
}
use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.
the class SshKeyManagerViewImpl method initSshKeyTable.
/** Creates table what contains list of available ssh keys. */
private void initSshKeyTable(final CellTable.Resources res) {
keys = new CellTable<>(15, res);
Column<SshPairDto, String> hostColumn = new Column<SshPairDto, String>(new TextCell()) {
@Override
public String getValue(SshPairDto object) {
return object.getName();
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-host-" + context.getIndex() + "\">");
super.render(context, object, sb);
}
};
hostColumn.setSortable(true);
Column<SshPairDto, String> publicKeyColumn = new Column<SshPairDto, String>(new ButtonCell()) {
@Override
public String getValue(SshPairDto object) {
return "View";
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-key-" + context.getIndex() + "\">");
if (object != null && object.getPublicKey() != null) {
super.render(context, object, sb);
}
}
};
// Creates handler on button clicked
publicKeyColumn.setFieldUpdater(new FieldUpdater<SshPairDto, String>() {
@Override
public void update(int index, SshPairDto object, String value) {
delegate.onViewClicked(object);
}
});
Column<SshPairDto, String> deleteKeyColumn = new Column<SshPairDto, String>(new ButtonCell()) {
@Override
public String getValue(SshPairDto object) {
return "Delete";
}
@Override
public void render(Context context, SshPairDto object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div id=\"" + UIObject.DEBUG_ID_PREFIX + "-sshKeys-cellTable-delete-" + context.getIndex() + "\">");
super.render(context, object, sb);
}
};
// Creates handler on button clicked
deleteKeyColumn.setFieldUpdater(new FieldUpdater<SshPairDto, String>() {
@Override
public void update(int index, SshPairDto object, String value) {
delegate.onDeleteClicked(object);
}
});
keys.addColumn(hostColumn, "Host");
keys.addColumn(publicKeyColumn, "Public Key");
keys.addColumn(deleteKeyColumn, "Delete");
keys.setColumnWidth(hostColumn, 50, Style.Unit.PCT);
keys.setColumnWidth(publicKeyColumn, 30, Style.Unit.PX);
keys.setColumnWidth(deleteKeyColumn, 30, Style.Unit.PX);
// don't show loading indicator
keys.setLoadingIndicator(null);
}
use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.
the class SshKeyManagerPresenterTest method testShouldRefreshKeysAfterSuccessfulGenerateKey.
@Test
public void testShouldRefreshKeysAfterSuccessfulGenerateKey() throws OperationException {
List<SshPairDto> sshPairDtoArray = new ArrayList<>();
when(dialogFactory.createInputDialog(anyString(), anyString(), (InputCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(inputDialog);
presenter.onGenerateClicked();
verify(dialogFactory).createInputDialog(anyString(), anyString(), inputCallbackCaptor.capture(), cancelCallbackCaptor.capture());
InputCallback inputCallback = inputCallbackCaptor.getValue();
inputCallback.accepted(GITHUB_HOST);
verify(sshPairDTOPromise).then(operationSshPairDTOCapture.capture());
operationSshPairDTOCapture.getValue().apply(null);
verify(sshPairDTOsPromise).then(operationSshPairDTOsCapture.capture());
operationSshPairDTOsCapture.getValue().apply(sshPairDtoArray);
verify(service).generatePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
verify(service).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
verify(view).setPairs(eq(sshPairDtoArray));
}
use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.
the class SshKeyManagerPresenterTest method testFailedRefreshKeysAfterSuccessfulDeleteKey.
@Test
public void testFailedRefreshKeysAfterSuccessfulDeleteKey() throws OperationException {
when(sshPairDto.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
when(sshPairDto.getName()).thenReturn(GITHUB_HOST);
SafeHtml safeHtml = mock(SafeHtml.class);
ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
List<SshPairDto> sshPairDtoArray = new ArrayList<>();
when(constant.deleteSshKeyQuestion(anyString())).thenReturn(safeHtml);
when(safeHtml.asString()).thenReturn("");
when(dialogFactory.createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(confirmDialog);
presenter.onDeleteClicked(sshPairDto);
verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), (CancelCallback) anyObject());
ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue();
confirmCallback.accepted();
verify(voidPromise).then(operationVoidCapture.capture());
operationVoidCapture.getValue().apply(null);
verify(sshPairDTOsPromise).catchError(operationErrorCapture.capture());
operationErrorCapture.getValue().apply(JsPromiseError.create(""));
verify(confirmDialog).show();
verify(service).deletePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
verify(service).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
verify(view, never()).setPairs(eq(sshPairDtoArray));
verify(notificationManager).notify(anyString(), any(StatusNotification.Status.class), (DisplayMode) anyObject());
}
Aggregations