summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-07-15 16:53:42 +0530
committerTim <timothyasir@gluster.com>2011-07-15 16:53:42 +0530
commite95fd9dc82ec09878464ac8629d5c1c88c3c76cf (patch)
treea72e5efd546db603e893aff10da7cc5412cd95bd /src
parent5c791f92f77aa65fd0c744b5660336ef300248b2 (diff)
parent691f4b7519a7758de9316766d9963d68cdd50924 (diff)
Merge remote branch 'upstream/master'
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java14
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java49
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java2
-rw-r--r--src/com.gluster.storage.management.gui/plugin.xml32
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ExportSshKeysAction.java77
-rw-r--r--src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ImportSshKeysAction.java17
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java89
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java4
8 files changed, 279 insertions, 5 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
index 8898cf92..92037741 100644
--- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java
@@ -22,6 +22,8 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import org.apache.log4j.Logger;
+
import com.gluster.storage.management.client.utils.ClientUtil;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.sun.jersey.api.client.Client;
@@ -38,7 +40,7 @@ import com.sun.jersey.core.util.MultivaluedMapImpl;
public abstract class AbstractClient {
private static final String HTTP_HEADER_AUTH = "Authorization";
protected static final MultivaluedMap<String, String> NO_PARAMS = new MultivaluedMapImpl();
-
+ private static final Logger logger = Logger.getLogger(AbstractClient.class);
protected String clusterName;
protected WebResource resource;
private String securityToken;
@@ -135,6 +137,7 @@ public abstract class AbstractClient {
return res.queryParams(queryParams).header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.APPLICATION_XML)
.get(responseClass);
} catch (Exception e1) {
+ logger.error("Error in fetching response", e1);
throw createGlusterException(e1);
}
}
@@ -160,7 +163,7 @@ public abstract class AbstractClient {
return new GlusterRuntimeException("Couldn't connect to Gluster Management Gateway!");
}
- return new GlusterRuntimeException("Exception in REST communication!", e);
+ return new GlusterRuntimeException("Exception in REST communication! [" + e.getMessage() + "]", e);
}
}
@@ -185,6 +188,13 @@ public abstract class AbstractClient {
throw new GlusterRuntimeException("Error while downloading resource [" + res.getURI().getPath() + "]", e);
}
}
+
+
+/* public void uploadResource(WebResource res, FormDataMultiPart form) {
+ ClientResponse response = res.header(HTTP_HEADER_AUTH, authHeader).type(MediaType.MULTIPART_FORM_DATA)
+ .accept(MediaType.TEXT_PLAIN).header(name, value)post(form);
+ }
+*/
/**
* Fetches the default resource (the one returned by {@link AbstractClient#getResourcePath()}) by dispatching a GET
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java
new file mode 100644
index 00000000..dfadd67c
--- /dev/null
+++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java
@@ -0,0 +1,49 @@
+/**
+ * KeysClient.java
+ *
+ * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ * This file is part of Gluster Management Console.
+ *
+ * Gluster Management Console is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gluster Management Console is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+package com.gluster.storage.management.client;
+
+import java.io.File;
+
+import com.gluster.storage.management.core.constants.RESTConstants;
+
+public class KeysClient extends AbstractClient {
+
+ public KeysClient() {
+ super();
+ }
+
+ public KeysClient(String clusterName) {
+ super(clusterName);
+ }
+
+ @Override
+ public String getResourcePath() {
+ return RESTConstants.RESOURCE_KEYS;
+ }
+
+ public void exportSshKeys(String filePath) {
+ downloadResource(resource, filePath);
+ }
+
+ public void importSshKeys(File keysFile) {
+
+ }
+}
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
index 9450ac48..455ecc11 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java
@@ -28,6 +28,7 @@ public class RESTConstants {
public static final String RESOURCE_PATH_USERS = "/users";
public static final String RESOURCE_PATH_CLUSTERS = "/clusters";
public static final String RESOURCE_PATH_DISCOVERED_SERVERS = "/discoveredservers";
+ public static final String RESOURCE_PATH_KEYS = "/keys";
// REST Resource names
public static final String RESOURCE_VOLUMES = "volumes";
@@ -40,6 +41,7 @@ public class RESTConstants {
public static final String RESOURCE_ALERTS = "alerts";
public static final String RESOURCE_SERVERS = "servers";
public static final String RESOURCE_TASKS = "tasks";
+ public static final String RESOURCE_KEYS = "keys";
public static final String TASK_START = "start";
public static final String TASK_PAUSE = "pause";
diff --git a/src/com.gluster.storage.management.gui/plugin.xml b/src/com.gluster.storage.management.gui/plugin.xml
index e410b4b8..4f2ad2af 100644
--- a/src/com.gluster.storage.management.gui/plugin.xml
+++ b/src/com.gluster.storage.management.gui/plugin.xml
@@ -988,7 +988,7 @@
class="com.gluster.storage.management.gui.actions.ChangePasswordAction"
definitionId="com.gluster.storage.management.gui.commands.ChangePassword"
icon="icons/tango/32x32/change-password.png"
- id="com.gluster.storage.management.gui.actions.AddServerAction"
+ id="com.gluster.storage.management.gui.actions.ChangePasswordAction"
label="&amp;Change Password"
menubarPath="com.gluster.storage.management.gui.menu.edit/edit"
mode="FORCE_TEXT"
@@ -998,6 +998,36 @@
style="push"
tooltip="Change password">
</action>
+ <action
+ allowLabelUpdate="false"
+ class="com.gluster.storage.management.gui.actions.ExportSshKeysAction"
+ definitionId="com.gluster.storage.management.gui.commands.ExportSshKeys"
+ icon="icons/tango/32x32/export-keys.png"
+ id="com.gluster.storage.management.gui.actions.ExportSshKeysAction"
+ label="&amp;Export Keys"
+ menubarPath="com.gluster.storage.management.gui.menu.edit/edit"
+ mode="FORCE_TEXT"
+ pulldown="false"
+ retarget="false"
+ state="false"
+ style="push"
+ tooltip="Export SSH keys">
+ </action>
+ <action
+ allowLabelUpdate="false"
+ class="com.gluster.storage.management.gui.actions.ImportSshKeysAction"
+ definitionId="com.gluster.storage.management.gui.commands.ImportSshKeys"
+ icon="icons/tango/32x32/import-keys.png"
+ id="com.gluster.storage.management.gui.actions.ImportSshKeysAction"
+ label="&amp;Import Keys"
+ menubarPath="com.gluster.storage.management.gui.menu.edit/edit"
+ mode="FORCE_TEXT"
+ pulldown="false"
+ retarget="false"
+ state="false"
+ style="push"
+ tooltip="Import SSH keys">
+ </action>
<menu
id="com.gluster.storage.management.gui.menu.edit"
label="&amp;Edit"
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ExportSshKeysAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ExportSshKeysAction.java
new file mode 100644
index 00000000..86f44d8e
--- /dev/null
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ExportSshKeysAction.java
@@ -0,0 +1,77 @@
+/**
+ * ExportSshKeysAction.java
+ *
+ * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ * This file is part of Gluster Management Console.
+ *
+ * Gluster Management Console is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gluster Management Console is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+package com.gluster.storage.management.gui.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+
+import com.gluster.storage.management.client.KeysClient;
+
+/**
+ * @author root
+ *
+ */
+public class ExportSshKeysAction extends AbstractActionDelegate {
+
+ @Override
+ protected void performAction(IAction action) {
+ final KeysClient client = new KeysClient();
+ final Runnable exportKeysThread = new Runnable() {
+
+ @Override
+ public void run() {
+ FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
+ dialog.setFilterNames(new String[] {"Tar (*.tar)"});
+ dialog.setFilterExtensions(new String[] {"*.tar"});
+ String filePath = dialog.open();
+
+ if(filePath == null) {
+ return;
+ }
+
+ String title = "Export SSH Keys";
+ try {
+ client.exportSshKeys(filePath);
+ showInfoDialog(title, "SSH keys exported successfully to [" + filePath + "]");
+ } catch(Exception e) {
+ showErrorDialog(title, e.getMessage());
+ }
+ }
+ };
+
+ BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
+
+ @Override
+ public void run() {
+ Display.getDefault().asyncExec(exportKeysThread);
+ }
+ });
+ }
+
+
+ @Override
+ public void dispose() {
+ }
+
+}
diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ImportSshKeysAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ImportSshKeysAction.java
new file mode 100644
index 00000000..8cedc920
--- /dev/null
+++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ImportSshKeysAction.java
@@ -0,0 +1,17 @@
+package com.gluster.storage.management.gui.actions;
+
+import org.eclipse.jface.action.IAction;
+
+public class ImportSshKeysAction extends AbstractActionDelegate {
+
+
+ @Override
+ protected void performAction(IAction action) {
+
+ }
+
+ @Override
+ public void dispose() {
+ }
+
+}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
new file mode 100644
index 00000000..a589c2a2
--- /dev/null
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
@@ -0,0 +1,89 @@
+/**
+ * KeysResource.java
+ *
+ * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ * This file is part of Gluster Management Console.
+ *
+ * Gluster Management Console is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gluster Management Console is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+package com.gluster.storage.management.server.resources.v1_0;
+
+import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_KEYS;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
+import com.gluster.storage.management.core.utils.FileUtil;
+import com.gluster.storage.management.core.utils.ProcessUtil;
+import com.gluster.storage.management.server.utils.SshUtil;
+
+@Path(RESOURCE_PATH_KEYS)
+public class KeysResource extends AbstractResource {
+
+
+ @GET
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ public Response exportSshkeys() {
+ try {
+ StreamingOutput output = new StreamingOutput() {
+
+ @Override
+ public void write(OutputStream output) throws IOException, WebApplicationException {
+ try {
+ File archiveFile = new File(createSskKeyZipFile());
+ output.write(FileUtil.readFileAsByteArray(archiveFile));
+ archiveFile.delete();
+ } catch (Exception e) {
+ output.write(("Exception while archiving SSH Key files : " + e.getMessage()).getBytes());
+ }
+ }
+ };
+ return streamingOutputResponse(output);
+ } catch (Exception e) {
+ return errorResponse("Exporting SSH keys failed! [" + e.getMessage() + "]");
+ }
+ }
+
+ public String createSskKeyZipFile() {
+ String targetDir = System.getProperty("java.io.tmpdir");
+ String zipFile = targetDir + "ssh-keys.tar";
+ String sourcePemFile = SshUtil.PEM_FILE.getAbsolutePath();
+ String sourcePubKeyFile = SshUtil.PUBLIC_KEY_FILE.getAbsolutePath();
+ String targetPemFile = targetDir + File.separator + SshUtil.PEM_FILE.getName();
+ String targetPubKeyFile = targetDir + File.separator + SshUtil.PUBLIC_KEY_FILE.getName();
+ ProcessUtil processUtil = new ProcessUtil();
+
+ // Copy keys to temp folder
+ processUtil.executeCommand("cp", sourcePemFile, targetPemFile);
+ processUtil.executeCommand("cp", sourcePubKeyFile, targetPubKeyFile);
+
+ // To zip the key files
+ processUtil.executeCommand("tar", "cvf", zipFile, "-C", "/tmp", SshUtil.PEM_FILE.getName(), SshUtil.PUBLIC_KEY_FILE.getName());
+
+ // To remove the copied key files
+ processUtil.executeCommand("rm", "-f", targetPubKeyFile, targetPubKeyFile);
+
+ return zipFile;
+ }
+}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
index 4f0b04cf..4771a230 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java
@@ -53,8 +53,8 @@ public class SshUtil {
private static final String SSH_AUTHORIZED_KEYS_FILE = "authorized_keys";
private static final String SSH_AUTHORIZED_KEYS_PATH = SSH_AUTHORIZED_KEYS_DIR + SSH_AUTHORIZED_KEYS_FILE;
private LRUCache<String, Connection> sshConnCache = new LRUCache<String, Connection>(10);
- private static final File PEM_FILE = new File(CoreConstants.USER_HOME + File.separator + ".ssh/id_rsa");
- private static final File PUBLIC_KEY_FILE = new File(CoreConstants.USER_HOME + File.separator + ".ssh/id_rsa.pub");
+ public static final File PEM_FILE = new File(CoreConstants.USER_HOME + File.separator + ".ssh/id_rsa");
+ public static final File PUBLIC_KEY_FILE = new File(CoreConstants.USER_HOME + File.separator + ".ssh/id_rsa.pub");
private static final String SCRIPT_DISABLE_SSH_PASSWORD_AUTH = "disable-ssh-password-auth.sh";
// TODO: Make user name configurable