[jbosstools-commits] JBoss Tools SVN: r43863 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard: ssh and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 20 10:31:02 EDT 2012
Author: adietish
Date: 2012-09-20 10:31:02 -0400 (Thu, 20 Sep 2012)
New Revision: 43863
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
Log:
[JBIDE-11912] removed SSH keys portion from NewDomainWizard, added link to ssh keys management wizard
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPage.java 2012-09-20 14:31:02 UTC (rev 43863)
@@ -10,65 +10,39 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.io.File;
-import java.io.FileNotFoundException;
-
-import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.jboss.tools.common.ui.databinding.MandatoryStringValidator;
+import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.common.ui.databinding.ParametrizableWizardPageSupport;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
-import org.jboss.tools.common.ui.ssh.SshPrivateKeysPreferences;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
-import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
-import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
-import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+import org.jboss.tools.openshift.express.internal.ui.wizard.ssh.ManageSSHKeysWizard;
-import com.openshift.client.OpenShiftException;
-
/**
* @author André Dietisheim
*/
public class NewDomainWizardPage extends AbstractOpenShiftWizardPage {
- private static final String FILTEREXPRESSION_PUBLIC_SSH_KEY = "*.pub";
- private static final String FILTERNAME_PUBLIC_SSH_KEY = "Public ssh key file (*.pub)";
-
private NewDomainWizardPageModel pageModel;
public NewDomainWizardPage(NewDomainWizardPageModel pageModel, IWizard wizard) {
@@ -95,156 +69,32 @@
final IObservableValue namespaceModelObservable = BeanProperties.value(
NewDomainWizardPageModel.PROPERTY_DOMAIN_ID).observe(pageModel);
ValueBindingBuilder.bind(namespaceTextObservable).to(namespaceModelObservable).in(dbc);
-
- Label sshKeyLabel = new Label(container, SWT.NONE);
- sshKeyLabel.setText("SSH Public Key");
- GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).applyTo(sshKeyLabel);
- Text sshKeyText = new Text(container, SWT.READ_ONLY | SWT.BORDER);
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sshKeyText);
- Binding sshKeyTextBinding = dbc.bindValue(
- WidgetProperties.text(SWT.Modify).observe(sshKeyText),
- BeanProperties.value(NewDomainWizardPageModel.PROPERTY_SSHKEY).observe(pageModel),
- new UpdateValueStrategy().setAfterGetValidator(new MandatoryStringValidator(
- "You have to select a ssh public key")),
- new UpdateValueStrategy().setAfterGetValidator(new SSHKeyValidator()));
- ControlDecorationSupport.create(sshKeyTextBinding, SWT.TOP | SWT.LEFT);
- try {
- pageModel.initSshKey();
- } catch (OpenShiftException ex) {
- IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could check your ssh keys", ex);
- OpenShiftUIActivator.log(status);
- ErrorDialog.openError(getShell(),
- "Error checking your ssh keys",
- "Could not check your ssh keys", status);
- }
- Button browseButton = new Button(container, SWT.PUSH);
- browseButton.setText("Browse...");
- GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(browseButton);
- browseButton.addSelectionListener(onBrowse());
-
- Button createButton = new Button(container, SWT.PUSH);
- createButton.setText("New");
- GridDataFactory.fillDefaults()
- .align(SWT.LEFT, SWT.CENTER).hint(100, SWT.DEFAULT).applyTo(createButton);
- createButton.addSelectionListener(onNew());
-
new Label(container, SWT.NONE); // spacer
Link sshPrefsLink = new Link(container, SWT.NONE);
- sshPrefsLink
- .setText("Please make sure that your private key for the public key is listed in the <a>SSH2 Preferences</a>");
+ sshPrefsLink.setText(
+ "Please make sure that you have SSH keys added to your OpenShift account.\n" +
+ "You may check them in the <a>SSH2 keys wizard</a>");
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.CENTER).applyTo(sshPrefsLink);
- sshPrefsLink.addSelectionListener(onSshPrefs());
+ sshPrefsLink.addSelectionListener(onManageSSHKeys());
}
- private SelectionListener onNew() {
+ private SelectionAdapter onManageSSHKeys() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
-
- try {
- if (pageModel.publicKeyExists()) {
- MessageDialog.openInformation(getShell(),
- "Libra Key already present",
- "You already have a key at \"" + pageModel.getPublicKey() + "\". Please move it or use it.");
- return;
- }
-
- InputDialog dialog = new PassphraseDialog(getShell());
- if (Dialog.OK == dialog.open()) {
- try {
- String passPhrase = dialog.getValue();
- pageModel.createLibraKeyPair(passPhrase);
- } catch (FileNotFoundException ex) {
- IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not read the ssh key folder", ex);
- OpenShiftUIActivator.log(status);
- ErrorDialog.openError(getShell(),
- "Error creating a new ssh key pair",
- "Could not create a new ssh key pair", status);
- }
- }
- } catch (OpenShiftException ex) {
- IStatus status = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not create an ssh key pair", ex);
- OpenShiftUIActivator.log(status);
- ErrorDialog.openError(getShell(),
- "Error creating a new ssh key pair",
- "Could not create a new ssh key pair", status);
- }
+ WizardUtils.openWizardDialog(new ManageSSHKeysWizard(pageModel.getUser()), getShell());
}
};
}
- private SelectionListener onBrowse() {
- return new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- FileDialog dialog = new FileDialog(shell);
- try {
- dialog.setFilterPath(SshPrivateKeysPreferences.getSshKeyDirectory());
- } catch (FileNotFoundException ex) {
- // ignore
- }
- dialog.setFilterNames(new String[] { FILTERNAME_PUBLIC_SSH_KEY });
- dialog.setFilterExtensions(new String[] { FILTEREXPRESSION_PUBLIC_SSH_KEY });
- String sshKeyPath = dialog.open();
- if (sshKeyPath != null) {
- pageModel.setSshKey(sshKeyPath);
- }
- }
- };
- }
-
- private SelectionAdapter onSshPrefs() {
- return new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- SshPrivateKeysPreferences.openPreferencesPage(getShell());
- // refresh warning about key
- // (since user may have changed SSH2 prefs)
- getDatabindingContext().updateTargets();
- }
- };
- }
-
@Override
protected void setupWizardPageSupport(DataBindingContext dbc) {
ParametrizableWizardPageSupport.create(IStatus.ERROR | IStatus.CANCEL, this, dbc);
}
- private class SSHKeyValidator implements IValidator {
-
- @Override
- public IStatus validate(Object value) {
- if (!(value instanceof String)
- || StringUtils.isEmpty((String) value)
- || !FileUtils.canRead((String) value)) {
- return ValidationStatus.error("You have to provide a valid ssh public key");
- }
- if (pageModel.hasConfiguredFixedPrivateKeys()) {
- return ValidationStatus.warning(
- NLS.bind("Your SSH config ({0}) contains fixed keys for OpenShift servers. " +
- "This can override any Eclipse specific SSH key preferences.", new SSHUserConfig(SSHUtils.getSSH2Home()).getFile()));
- } else if (!SSHUtils.publicKeyMatchesPrivateKeyInPreferences(new File((String) value))) {
- return ValidationStatus.warning(
- NLS.bind("Could not find the private portion for your public key in the preferences. "
- + "Make sure it is listed in the ssh2 preferences.", value));
- }
- return ValidationStatus.ok();
- }
-
- }
-
private class NamespaceValidator extends MultiValidator {
private final ISWTObservableValue domainNameObservable;
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2012-09-20 13:52:33 UTC (rev 43862)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java 2012-09-20 14:31:02 UTC (rev 43863)
@@ -10,199 +10,38 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jsch.internal.core.IConstants;
-import org.eclipse.jsch.internal.core.JSchCorePlugin;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.core.console.UserDelegate;
-import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
-import org.jboss.tools.openshift.express.internal.ui.utils.SSHUserConfig;
-import org.jboss.tools.openshift.express.internal.ui.utils.SSHUtils;
import com.openshift.client.IDomain;
-import com.openshift.client.IOpenShiftSSHKey;
-import com.openshift.client.ISSHPublicKey;
import com.openshift.client.OpenShiftException;
-import com.openshift.client.SSHKeyPair;
-import com.openshift.client.SSHPublicKey;
/**
* @author André Dietisheim
*/
public class NewDomainWizardPageModel extends ObservableUIPojo {
- public static final String ID_RSA_FILENAME = "id_rsa";
- public static final String LIBRA_ID_RSA_FILENAME = "libra_id_rsa";
- private static final String PUBLIC_KEY_SUFFIX = ".pub";
- private static final String KEYS_SEPARATOR = ",";
-
- private static final String SSHKEY_DEFAULT_NAME = "jbosstools"; //$NON-NLS-1$
-
public static final String PROPERTY_DOMAIN_ID = "domainId";
public static final String PROPERTY_SSHKEY = "sshKey";
private String domainId;
private IDomain domain;
- private String sshKey;
private UserDelegate user;
public NewDomainWizardPageModel(UserDelegate user) {
this.user = user;
}
-
- public void initSshKey() throws OpenShiftException {
- if (!publicKeyExists()) {
- return;
- }
- File libraPublicKey = getPublicKey();
- setSshKey(libraPublicKey.getAbsolutePath());
- }
-
- /**
- * Returns the file of the libra public key. It is not checking if the file exists.
- *
- * @return the libra public key
- * @throws OpenShiftException
- */
- public File getPublicKey() throws OpenShiftException {
- File libraPrivateKey = getPrivateKey();
- return new File(libraPrivateKey.getParent(), getPublicKeyPath(libraPrivateKey.getName()));
- }
-
- private String getPublicKeyPath(String privateKeyPath) {
- return privateKeyPath + PUBLIC_KEY_SUFFIX;
- }
-
- public File getPrivateKey() throws OpenShiftException {
- String ssh2Home = checkedGetSSH2Home();
- ensureSSHHomeExists(ssh2Home);
- if (hasConfiguredFixedPrivateKeys()) {
- return new File(ssh2Home, LIBRA_ID_RSA_FILENAME);
- } else {
- return new File(ssh2Home, ID_RSA_FILENAME);
- }
- }
-
- private String checkedGetSSH2Home() throws OpenShiftException {
- String ssh2Home = SSHUtils.getSSH2Home();
- if (ssh2Home == null
- || ssh2Home.trim().length() == 0) {
- throw new OpenShiftException("Could not determine your ssh2 home directory");
- }
- return ssh2Home;
- }
-
- public boolean hasConfiguredFixedPrivateKeys() {
- try {
- SSHUserConfig sshUserConfig = new SSHUserConfig(checkedGetSSH2Home());
- return sshUserConfig.hasLibraIdentifyFile();
- } catch (OpenShiftException e) {
- return false;
- }
- }
-
-
public String getDomainId() {
return this.domainId;
}
public void createDomain() throws OpenShiftException, IOException {
user.createDomain(domainId);
- ISSHPublicKey sshKey = loadSshKey();
- IOpenShiftSSHKey sshKeyResource = user.getSSHKeyByPublicKey(sshKey.getPublicKey());
- if (sshKeyResource == null) {
- user.putSSHKey(getTimestampKeyname(), sshKey);
- }
}
-
- private String getTimestampKeyname() {
- return new StringBuilder(
- SSHKEY_DEFAULT_NAME)
- .append(new SimpleDateFormat("yyyyMMddhmS").format(new Date()))
- .toString();
- }
-
- public String getSshKey() {
- return sshKey;
- }
-
- public boolean publicKeyExists() throws OpenShiftException {
- return FileUtils.canRead(getPublicKey());
- }
-
- public void createLibraKeyPair(String passPhrase) throws FileNotFoundException, OpenShiftException {
- File libraPublicKey = getPublicKey();
- if (libraPublicKey.canRead()) {
- // key already exists
- return;
- }
- ensureSSHHomeExists(checkedGetSSH2Home());
- File libraPrivateKey = getPrivateKey();
- SSHKeyPair keyPair = SSHKeyPair.create(passPhrase, libraPrivateKey.getAbsolutePath(), libraPublicKey.getAbsolutePath());
- setFilePermissions(libraPrivateKey);
- addToPrivateKeysPreferences(keyPair);
- setSshKey(keyPair.getPublicKeyPath());
- }
-
- private void ensureSSHHomeExists(String ssh2Home)
- throws OpenShiftException {
- File ssh2HomeFile = new File(ssh2Home);
- if (FileUtils.canRead(ssh2HomeFile)) {
- if (!FileUtils.isDirectory(ssh2HomeFile)) {
- throw new OpenShiftException(
- ssh2Home + " is a file instead of a directory. This prevents creation and usage of ssh keys");
- }
- return;
- }
-
- try {
- if(!ssh2HomeFile.mkdirs()) {
- throw new OpenShiftException("Could not create ssh2 home directory at {0}", ssh2Home);
- }
- } catch(SecurityException e) {
- throw new OpenShiftException(e, "Could not create ssh2 home directory at {0}", ssh2Home);
- }
- }
-
- private void setFilePermissions(File file) {
- // set f permission to correspond to 'chmod 0600' read/write only for user
- // First clear all permissions for both user and others
- file.setReadable(false, false);
- file.setWritable(false, false);
- // Enable only readable for user
- file.setReadable(true, true);
- file.setWritable(true, true);
- }
-
- private void addToPrivateKeysPreferences(SSHKeyPair keyPair) {
- Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
- String privateKeys = preferences.getString(IConstants.KEY_PRIVATEKEY);
- if (privateKeys != null
- && privateKeys.trim().length() > 0) {
- privateKeys = privateKeys + "," + keyPair.getPrivateKeyPath();
- } else {
- privateKeys = keyPair.getPrivateKeyPath();
- }
- preferences.setValue(IConstants.KEY_PRIVATEKEY, privateKeys);
- JSchCorePlugin.getPlugin().setNeedToLoadKeys(true);
- JSchCorePlugin.getPlugin().savePluginPreferences();
- }
- public void setSshKey(String sshKey) {
- firePropertyChange(PROPERTY_SSHKEY, this.sshKey, this.sshKey = sshKey);
- }
-
- private ISSHPublicKey loadSshKey() throws IOException, OpenShiftException {
- return new SSHPublicKey(new File(sshKey));
- }
-
public void setDomainId(String domainId) {
firePropertyChange(PROPERTY_DOMAIN_ID, this.domainId, this.domainId = domainId);
}
@@ -215,4 +54,7 @@
return domain;
}
+ public UserDelegate getUser() {
+ return user;
+ }
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java 2012-09-20 13:52:33 UTC (rev 43862)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ssh/AddSSHKeyWizardPage.java 2012-09-20 14:31:02 UTC (rev 43863)
@@ -48,6 +48,9 @@
*/
public class AddSSHKeyWizardPage extends AbstractOpenShiftWizardPage {
+ private static final String FILTEREXPRESSION_PUBLIC_SSH_KEY = "*.pub";
+ private static final String FILTERNAME_PUBLIC_SSH_KEY = "Public ssh key file (*.pub)";
+
private AddSSHKeyWizardPageModel pageModel;
public AddSSHKeyWizardPage(UserDelegate user, IWizard wizard) {
@@ -128,6 +131,8 @@
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
dialog.setFilterPath(SSHUtils.getSSH2Home());
+ dialog.setFilterExtensions(new String[] {FILTEREXPRESSION_PUBLIC_SSH_KEY });
+ dialog.setFilterNames(new String[]{FILTERNAME_PUBLIC_SSH_KEY});
String filePath = null;
if ((filePath = dialog.open()) != null) {
pageModel.setPublicKeyPath(filePath);
More information about the jbosstools-commits
mailing list