Search in sources :

Example 1 with SshPairDto

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);
}
Also used : Context(com.google.gwt.cell.client.Cell.Context) SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) Column(com.google.gwt.user.cellview.client.Column) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ButtonCell(com.google.gwt.cell.client.ButtonCell) TextCell(com.google.gwt.cell.client.TextCell)

Example 2 with SshPairDto

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()));
            }
        }
    });
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Operation(org.eclipse.che.api.promises.client.Operation) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with SshPairDto

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);
}
Also used : Context(com.google.gwt.cell.client.Cell.Context) SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) Column(com.google.gwt.user.cellview.client.Column) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ButtonCell(com.google.gwt.cell.client.ButtonCell) TextCell(com.google.gwt.cell.client.TextCell)

Example 4 with SshPairDto

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));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with SshPairDto

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());
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) Test(org.junit.Test)

Aggregations

SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ButtonCell (com.google.gwt.cell.client.ButtonCell)2 Context (com.google.gwt.cell.client.Cell.Context)2 TextCell (com.google.gwt.cell.client.TextCell)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)2 Column (com.google.gwt.user.cellview.client.Column)2 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)2 ConfirmDialog (org.eclipse.che.ide.api.dialogs.ConfirmDialog)2 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Machine (org.eclipse.che.api.core.model.machine.Machine)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 SshService (org.eclipse.che.api.ssh.server.SshService)1 ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)1