summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-10-24 09:17:37 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-11-04 11:37:06 -0500
commit89d871642969572a0a64f2fa9d9455e0753fcf1c (patch)
tree2da14ad12a4a3388a3233bb5ce22a4f96af84171 /base/java-tools/src/com/netscape/cmstools/tps
parent481ee45823a6dd1d3d151f407eb78e142e7149fa (diff)
downloadpki-89d871642969572a0a64f2fa9d9455e0753fcf1c.tar.gz
pki-89d871642969572a0a64f2fa9d9455e0753fcf1c.tar.xz
pki-89d871642969572a0a64f2fa9d9455e0753fcf1c.zip
Added TPS profile resource.
A new REST service and clients have been added to manage the profiles in the TPS configuration file. Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/tps')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java96
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java35
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java94
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java112
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java53
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java87
6 files changed, 477 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java
new file mode 100644
index 000000000..d44ddc08e
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileAddCLI.java
@@ -0,0 +1,96 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.profile;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.profile.ProfileData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ProfileAddCLI extends CLI {
+
+ public ProfileCLI profileCLI;
+
+ public ProfileAddCLI(ProfileCLI profileCLI) {
+ super("add", "Add profile", profileCLI);
+ this.profileCLI = profileCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "input", true, "Input file containing profile properties.");
+ option.setArgName("file");
+ option.setRequired(true);
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String input = cmd.getOptionValue("input");
+
+ ProfileData profileData;
+
+ try (BufferedReader in = new BufferedReader(new FileReader(input));
+ StringWriter sw = new StringWriter();
+ PrintWriter out = new PrintWriter(sw, true)) {
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+
+ profileData = ProfileData.valueOf(sw.toString());
+ }
+
+ profileData = profileCLI.profileClient.addProfile(profileData);
+
+ MainCLI.printMessage("Added profile \"" + profileData.getID() + "\"");
+
+ ProfileCLI.printProfileData(profileData, true);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java
index 41270f6f9..8b02f2e57 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java
@@ -18,6 +18,13 @@
package com.netscape.cmstools.tps.profile;
+import java.io.IOException;
+import java.util.Map;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.tps.profile.ProfileClient;
+import com.netscape.certsrv.tps.profile.ProfileData;
import com.netscape.cmstools.cli.CLI;
/**
@@ -25,16 +32,44 @@ import com.netscape.cmstools.cli.CLI;
*/
public class ProfileCLI extends CLI {
+ public ProfileClient profileClient;
+
public ProfileCLI(CLI parent) {
super("profile", "Profile management commands", parent);
+ addModule(new ProfileAddCLI(this));
+ addModule(new ProfileFindCLI(this));
+ addModule(new ProfileModifyCLI(this));
+ addModule(new ProfileRemoveCLI(this));
+ addModule(new ProfileShowCLI(this));
+
addModule(new ProfileMappingCLI(this));
}
public void execute(String[] args) throws Exception {
client = parent.getClient();
+ profileClient = (ProfileClient)parent.getClient("profile");
super.execute(args);
}
+
+ public static void printProfileData(ProfileData profileData, boolean showProperties) throws IOException {
+ System.out.println(" Profile ID: " + profileData.getID());
+ if (profileData.getStatus() != null) System.out.println(" Status: " + profileData.getStatus());
+
+ if (showProperties) {
+ System.out.println(" Properties:");
+ Map<String, String> properties = profileData.getProperties();
+ for (String name : properties.keySet()) {
+ String value = properties.get(name);
+ System.out.println(" " + name + ": " + value);
+ }
+ }
+
+ Link link = profileData.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
new file mode 100644
index 000000000..9f822f6ba
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
@@ -0,0 +1,94 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.profile;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.profile.ProfileCollection;
+import com.netscape.certsrv.tps.profile.ProfileData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ProfileFindCLI extends CLI {
+
+ public ProfileCLI profileCLI;
+
+ public ProfileFindCLI(ProfileCLI profileCLI) {
+ super("find", "Find profiles", profileCLI);
+ this.profileCLI = profileCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ ProfileCollection result = profileCLI.profileClient.findProfiles(start, size);
+ Collection<ProfileData> profiles = result.getEntries();
+
+ MainCLI.printMessage(profiles.size() + " profile(s) matched");
+
+ boolean first = true;
+
+ for (ProfileData profileData : profiles) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ ProfileCLI.printProfileData(profileData, false);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + profiles.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java
new file mode 100644
index 000000000..b4db03706
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileModifyCLI.java
@@ -0,0 +1,112 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.profile;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.profile.ProfileData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ProfileModifyCLI extends CLI {
+
+ public ProfileCLI profileCLI;
+
+ public ProfileModifyCLI(ProfileCLI profileCLI) {
+ super("mod", "Modify profile", profileCLI);
+ this.profileCLI = profileCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "input", true, "Input file containing profile properties.");
+ option.setArgName("file");
+ options.addOption(option);
+
+ option = new Option(null, "action", true, "Action: approve, reject, enable, disable.");
+ option.setArgName("action");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String profileID = cmdArgs[0];
+ String input = cmd.getOptionValue("input");
+ String action = cmd.getOptionValue("action");
+
+ ProfileData profileData;
+
+ if (input == null && action == null || input != null && action != null) {
+ System.err.println("Error: Either input file or action should be specified");
+ printHelp();
+ System.exit(1);
+ return;
+
+ } else if (input != null) {
+ try (BufferedReader in = new BufferedReader(new FileReader(input));
+ StringWriter sw = new StringWriter();
+ PrintWriter out = new PrintWriter(sw, true)) {
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+
+ profileData = ProfileData.valueOf(sw.toString());
+ }
+
+ profileData = profileCLI.profileClient.updateProfile(profileID, profileData);
+
+ } else { // action != null
+ profileData = profileCLI.profileClient.changeProfileStatus(profileID, action);
+ }
+
+ MainCLI.printMessage("Modified profile \"" + profileID + "\"");
+
+ ProfileCLI.printProfileData(profileData, true);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java
new file mode 100644
index 000000000..20913103f
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileRemoveCLI.java
@@ -0,0 +1,53 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.profile;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ProfileRemoveCLI extends CLI {
+
+ public ProfileCLI profileCLI;
+
+ public ProfileRemoveCLI(ProfileCLI profileCLI) {
+ super("del", "Remove profile", profileCLI);
+ this.profileCLI = profileCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String profileID = args[0];
+
+ profileCLI.profileClient.removeProfile(profileID);
+
+ MainCLI.printMessage("Deleted profile \"" + profileID + "\"");
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java
new file mode 100644
index 000000000..7c4c2fa1e
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileShowCLI.java
@@ -0,0 +1,87 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.profile;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.profile.ProfileData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ProfileShowCLI extends CLI {
+
+ public ProfileCLI profileCLI;
+
+ public ProfileShowCLI(ProfileCLI profileCLI) {
+ super("show", "Show profile", profileCLI);
+ this.profileCLI = profileCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "output", true, "Output file to store profile properties.");
+ option.setArgName("file");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String profileID = args[0];
+ String output = cmd.getOptionValue("output");
+
+ ProfileData profileData = profileCLI.profileClient.getProfile(profileID);
+
+ if (output == null) {
+ MainCLI.printMessage("Profile \"" + profileID + "\"");
+ ProfileCLI.printProfileData(profileData, true);
+
+ } else {
+ try (PrintWriter out = new PrintWriter(new FileWriter(output))) {
+ out.println(profileData);
+ }
+ MainCLI.printMessage("Stored profile \"" + profileID + "\" into " + output);
+ }
+ }
+}