[jbosstools-commits] JBoss Tools SVN: r39758 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 22 07:03:13 EDT 2012


Author: adietish
Date: 2012-03-22 07:03:12 -0400 (Thu, 22 Mar 2012)
New Revision: 39758

Modified:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java
Log:
[JBIDE-11322] create SSH2 home directory if not present yet

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-03-22 10:53:56 UTC (rev 39757)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewDomainWizardPageModel.java	2012-03-22 11:03:12 UTC (rev 39758)
@@ -71,14 +71,27 @@
 	}
 
 	public File getLibraPrivateKey() throws OpenShiftException {
+		String ssh2Home = getSSH2Home();
+		File ssh2HomeFile = new File(ssh2Home);
+		if (!FileUtils.canRead(ssh2HomeFile)) {
+			try {
+				ssh2HomeFile.createNewFile();
+			} catch(IOException e) {
+				throw new OpenShiftException("Could not create ssh2 home directory at {0}", ssh2Home);
+			}
+		}
+		
+		return new File(ssh2Home, LIBRA_KEY);
+	}
+
+	private String getSSH2Home() throws OpenShiftException {
 		Preferences preferences = JSchCorePlugin.getPlugin().getPluginPreferences();
 		String ssh2Home = preferences.getString(IConstants.KEY_SSH2HOME);
 		if (ssh2Home == null 
 				|| ssh2Home.trim().length() == 0) {
 			throw new OpenShiftException("Could not determine your ssh2 home directory");
 		}
-		
-		return new File(ssh2Home, LIBRA_KEY);
+		return ssh2Home;
 	}
 
 	public String getNamespace() {
@@ -103,6 +116,7 @@
 			// key already exists
 			return;
 		}
+		createSSHHome(getSSH2Home());
 		File libraPrivateKey = getLibraPrivateKey();
 		SSHKeyPair keyPair = SSHKeyPair.create(passPhrase, libraPrivateKey.getAbsolutePath(), libraPublicKey.getAbsolutePath());
 		setFilePermissions(libraPrivateKey);
@@ -110,6 +124,26 @@
 		setSshKey(keyPair.getPublicKeyPath());
 	}
 	
+	private void createSSHHome(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



More information about the jbosstools-commits mailing list