summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java11
-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.java1
-rw-r--r--src/com.gluster.storage.management.gui/icons/tango/32x32/export-keys.pngbin0 -> 1194 bytes
-rw-r--r--src/com.gluster.storage.management.gui/icons/tango/32x32/import-keys.pngbin0 -> 1998 bytes
-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.java98
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/SshUtil.java4
10 files changed, 285 insertions, 4 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..c083d298 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
@@ -32,6 +32,7 @@ import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.representation.Form;
import com.sun.jersey.client.urlconnection.HTTPSProperties;
+import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.core.util.MultivaluedMapImpl;
@@ -135,6 +136,7 @@ public abstract class AbstractClient {
return res.queryParams(queryParams).header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.APPLICATION_XML)
.get(responseClass);
} catch (Exception e1) {
+ e1.printStackTrace();
throw createGlusterException(e1);
}
}
@@ -160,7 +162,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 +187,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..15c70146
--- /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;
+
+public class KeysClient extends AbstractClient {
+ // Resource path: /glustermg/1.0/keys
+ private static final String RESOURCE_NAME = "keys";
+
+ public KeysClient() {
+ super();
+ }
+
+ public KeysClient(String clusterName) {
+ super(clusterName);
+ }
+
+ @Override
+ public String getResourcePath() {
+ return RESOURCE_NAME;
+ }
+
+ 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..f9ab7e2f 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";
diff --git a/src/com.gluster.storage.management.gui/icons/tango/32x32/export-keys.png b/src/com.gluster.storage.management.gui/icons/tango/32x32/export-keys.png
new file mode 100644
index 00000000..16d47578
--- /dev/null
+++ b/src/com.gluster.storage.management.gui/icons/tango/32x32/export-keys.png
Binary files differ
diff --git a/src/com.gluster.storage.management.gui/icons/tango/32x32/import-keys.png b/src/com.gluster.storage.management.gui/icons/tango/32x32/import-keys.png
new file mode 100644
index 00000000..d7f0d0c3
--- /dev/null
+++ b/src/com.gluster.storage.management.gui/icons/tango/32x32/import-keys.png
Binary files differ
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..169d41b0
--- /dev/null
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/KeysResource.java
@@ -0,0 +1,98 @@
+/**
+ * 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;
+ }
+
+
+
+
+ public static void main(String[] args) {
+ KeysResource key = new KeysResource();
+ // key.exportSshkeys();
+ System.out.println(System.getProperty("java.io.tmpdir"));
+ }
+}
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