diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-10-01 17:39:29 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-01 19:26:24 -0400 |
commit | 7c0fb95b77f0f91c572e0242c09a88605497a455 (patch) | |
tree | dd387f97194f17d5f26d089cd72e0f81194e73ab /base/java-tools/src/com/netscape/cmstools/tps | |
parent | bcf463c6afb042543fec93759c02211f6d5c0a60 (diff) | |
download | pki-7c0fb95b77f0f91c572e0242c09a88605497a455.tar.gz pki-7c0fb95b77f0f91c572e0242c09a88605497a455.tar.xz pki-7c0fb95b77f0f91c572e0242c09a88605497a455.zip |
Added TPS profile mapping resource.
A new REST service and clients have been added to manage the profile
mappings in the TPS configuration file.
Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/tps')
7 files changed, 544 insertions, 0 deletions
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 new file mode 100644 index 000000000..41270f6f9 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileCLI.java @@ -0,0 +1,40 @@ +// --- 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; + +/** + * @author Endi S. Dewata + */ +public class ProfileCLI extends CLI { + + public ProfileCLI(CLI parent) { + super("profile", "Profile management commands", parent); + + addModule(new ProfileMappingCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + + super.execute(args); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.java new file mode 100644 index 000000000..277fc4efe --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingAddCLI.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.ProfileMappingData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ProfileMappingAddCLI extends CLI { + + public ProfileMappingCLI profileMappingCLI; + + public ProfileMappingAddCLI(ProfileMappingCLI profileMappingCLI) { + super("add", "Add profile mapping", profileMappingCLI); + this.profileMappingCLI = profileMappingCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <ProfileMapping ID> [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "input", true, "Input file containing profile mapping 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"); + + ProfileMappingData profileMappingData; + + 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); + } + + profileMappingData = ProfileMappingData.valueOf(sw.toString()); + } + + profileMappingData = profileMappingCLI.profileMappingClient.addProfileMapping(profileMappingData); + + MainCLI.printMessage("Added profile mapping \"" + profileMappingData.getID() + "\""); + + ProfileMappingCLI.printProfileMappingData(profileMappingData, true); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingCLI.java new file mode 100644 index 000000000..6f7e6c5d9 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingCLI.java @@ -0,0 +1,73 @@ +// --- 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.IOException; +import java.util.Map; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.tps.profile.ProfileMappingClient; +import com.netscape.certsrv.tps.profile.ProfileMappingData; +import com.netscape.cmstools.cli.CLI; + +/** + * @author Endi S. Dewata + */ +public class ProfileMappingCLI extends CLI { + + public ProfileMappingClient profileMappingClient; + + public ProfileMappingCLI(ProfileCLI profileCLI) { + super("mapping", "Profile mapping management commands", profileCLI); + + addModule(new ProfileMappingAddCLI(this)); + addModule(new ProfileMappingFindCLI(this)); + addModule(new ProfileMappingModifyCLI(this)); + addModule(new ProfileMappingRemoveCLI(this)); + addModule(new ProfileMappingShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + profileMappingClient = (ProfileMappingClient)parent.getClient("profile-mapping"); + + super.execute(args); + } + + public static void printProfileMappingData(ProfileMappingData profileMappingData, boolean showProperties) throws IOException { + System.out.println(" Profile Mapping ID: " + profileMappingData.getID()); + if (profileMappingData.getStatus() != null) System.out.println(" Status: " + profileMappingData.getStatus()); + + if (showProperties) { + System.out.println(" Properties:"); + Map<String, String> properties = profileMappingData.getProperties(); + for (String name : properties.keySet()) { + String value = properties.get(name); + System.out.println(" " + name + ": " + value); + } + } + + Link link = profileMappingData.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java new file mode 100644 index 000000000..d96268be7 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.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.ProfileMappingCollection; +import com.netscape.certsrv.tps.profile.ProfileMappingData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ProfileMappingFindCLI extends CLI { + + public ProfileMappingCLI profileMappingCLI; + + public ProfileMappingFindCLI(ProfileMappingCLI profileMappingCLI) { + super("find", "Find profile mappings", profileMappingCLI); + this.profileMappingCLI = profileMappingCLI; + } + + 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); + + ProfileMappingCollection result = profileMappingCLI.profileMappingClient.findProfileMappings(start, size); + Collection<ProfileMappingData> profileMappings = result.getEntries(); + + MainCLI.printMessage(profileMappings.size() + " profile mapping(s) matched"); + + boolean first = true; + + for (ProfileMappingData profileMappingData : profileMappings) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + ProfileMappingCLI.printProfileMappingData(profileMappingData, false); + } + + MainCLI.printMessage("Number of entries returned " + profileMappings.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java new file mode 100644 index 000000000..4561695ff --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingModifyCLI.java @@ -0,0 +1,101 @@ +// --- 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.ProfileMappingData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ProfileMappingModifyCLI extends CLI { + + public ProfileMappingCLI profileMappingCLI; + + public ProfileMappingModifyCLI(ProfileMappingCLI profileMappingCLI) { + super("mod", "Modify profile mapping", profileMappingCLI); + this.profileMappingCLI = profileMappingCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <Profile Mapping ID> [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "status", true, "Status: ENABLED, DISABLED."); + option.setArgName("status"); + options.addOption(option); + + option = new Option(null, "input", true, "Input file containing profile mapping 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 profileMappingID = cmdArgs[0]; + String status = cmd.getOptionValue("status"); + String input = cmd.getOptionValue("input"); + + ProfileMappingData profileMappingData; + + 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); + } + + profileMappingData = ProfileMappingData.valueOf(sw.toString()); + } + + profileMappingData = profileMappingCLI.profileMappingClient.updateProfileMapping(profileMappingID, profileMappingData); + + MainCLI.printMessage("Modified profile mapping \"" + profileMappingID + "\""); + + ProfileMappingCLI.printProfileMappingData(profileMappingData, true); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.java new file mode 100644 index 000000000..f64c12c83 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingRemoveCLI.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 ProfileMappingRemoveCLI extends CLI { + + public ProfileMappingCLI profileMappingCLI; + + public ProfileMappingRemoveCLI(ProfileMappingCLI profileMappingCLI) { + super("del", "Remove profile mapping", profileMappingCLI); + this.profileMappingCLI = profileMappingCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <Profile Mapping ID>", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String profileMappingID = args[0]; + + profileMappingCLI.profileMappingClient.removeProfileMapping(profileMappingID); + + MainCLI.printMessage("Deleted profile mapping \"" + profileMappingID + "\""); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.java new file mode 100644 index 000000000..c715a3edc --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingShowCLI.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.ProfileMappingData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ProfileMappingShowCLI extends CLI { + + public ProfileMappingCLI profileMappingCLI; + + public ProfileMappingShowCLI(ProfileMappingCLI profileMappingCLI) { + super("show", "Show profileMapping", profileMappingCLI); + this.profileMappingCLI = profileMappingCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <Profile Mapping ID>", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "output", true, "Output file to store profile mapping 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 profileMappingID = args[0]; + String output = cmd.getOptionValue("output"); + + ProfileMappingData profileMappingData = profileMappingCLI.profileMappingClient.getProfileMapping(profileMappingID); + + if (output == null) { + MainCLI.printMessage("ProfileMapping \"" + profileMappingID + "\""); + ProfileMappingCLI.printProfileMappingData(profileMappingData, true); + + } else { + try (PrintWriter out = new PrintWriter(new FileWriter(output))) { + out.println(profileMappingData); + } + MainCLI.printMessage("Stored profile mapping \"" + profileMappingID + "\" into " + output); + } + } +} |