diff options
author | Ade Lee <alee@redhat.com> | 2015-10-01 12:12:38 -0400 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2015-10-02 13:12:24 -0400 |
commit | a401b768197cbecf14d4e9fb268b51056dfa2510 (patch) | |
tree | 40cd0d6d09a65156cf0a0de780a585dfd287318b /base/java-tools/src/com/netscape | |
parent | e9784003ebcfb310ff59a455e9af94d62f9502b4 (diff) | |
download | pki-a401b768197cbecf14d4e9fb268b51056dfa2510.tar.gz pki-a401b768197cbecf14d4e9fb268b51056dfa2510.tar.xz pki-a401b768197cbecf14d4e9fb268b51056dfa2510.zip |
Added Java client and CLI support for Feature resource.
Diffstat (limited to 'base/java-tools/src/com/netscape')
4 files changed, 223 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java index 5c41f00c2..39dd2a2ce 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java @@ -22,6 +22,7 @@ import com.netscape.certsrv.ca.CAClient; import com.netscape.certsrv.client.Client; import com.netscape.cmstools.authority.AuthorityCLI; import com.netscape.cmstools.cert.CertCLI; +import com.netscape.cmstools.feature.FeatureCLI; import com.netscape.cmstools.group.GroupCLI; import com.netscape.cmstools.profile.ProfileCLI; import com.netscape.cmstools.selftests.SelfTestCLI; @@ -40,6 +41,7 @@ public class CACLI extends SubsystemCLI { addModule(new AuthorityCLI(this)); addModule(new CertCLI(this)); + addModule(new FeatureCLI(this)); addModule(new GroupCLI(this)); addModule(new KRAConnectorCLI(this)); addModule(new ProfileCLI(this)); diff --git a/base/java-tools/src/com/netscape/cmstools/feature/FeatureCLI.java b/base/java-tools/src/com/netscape/cmstools/feature/FeatureCLI.java new file mode 100644 index 000000000..41c01df8e --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/feature/FeatureCLI.java @@ -0,0 +1,63 @@ +// --- 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) 2015 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmstools.feature; + +import com.netscape.certsrv.system.Feature; +import com.netscape.certsrv.system.FeatureClient; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +public class FeatureCLI extends CLI { + + public FeatureClient featureClient; + + public FeatureCLI(CLI parent) { + super("feature", "Feature management commands", parent); + + addModule(new FeatureFindCLI(this)); + addModule(new FeatureShowCLI(this)); + } + + public String getFullName() { + if (parent instanceof MainCLI) { + // do not include MainCLI's name + return name; + } else { + return parent.getFullName() + "-" + name; + } + } + + public void execute(String[] args) throws Exception { + client = parent.getClient(); + featureClient = new FeatureClient(client, "ca"); + super.execute(args); + } + + protected static void printFeature(Feature data) { + System.out.println(" ID: " + data.getId()); + String desc = data.getDescription(); + if (desc != null) + System.out.println(" Description: " + desc); + String version = data.getVersion(); + if (version != null) + System.out.println(" Version: " + version); + System.out.println(" Enabled: " + data.isEnabled()); + } + +} + diff --git a/base/java-tools/src/com/netscape/cmstools/feature/FeatureFindCLI.java b/base/java-tools/src/com/netscape/cmstools/feature/FeatureFindCLI.java new file mode 100644 index 000000000..5bc77071a --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/feature/FeatureFindCLI.java @@ -0,0 +1,79 @@ +// --- 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) 2015 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmstools.feature; + +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.ParseException; + +import com.netscape.certsrv.system.Feature; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +public class FeatureFindCLI extends CLI { + + public FeatureCLI featureCLI; + + public FeatureFindCLI(FeatureCLI featureCLI) { + super("find", "Find features", featureCLI); + this.featureCLI = featureCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName(), options); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + @SuppressWarnings("unused") + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + } catch (ParseException e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + List<Feature> features = featureCLI.featureClient.listFeatures(); + + MainCLI.printMessage(features.size() + " entries matched"); + if (features.size() == 0) return; + + boolean first = true; + for (Feature feature : features) { + if (first) + first = false; + else + System.out.println(); + FeatureCLI.printFeature(feature); + } + + MainCLI.printMessage("Number of entries returned " + features.size()); + } + +} diff --git a/base/java-tools/src/com/netscape/cmstools/feature/FeatureShowCLI.java b/base/java-tools/src/com/netscape/cmstools/feature/FeatureShowCLI.java new file mode 100644 index 000000000..59cfb67eb --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/feature/FeatureShowCLI.java @@ -0,0 +1,79 @@ +// --- 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) 2015 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.cmstools.feature; + +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.ParseException; + +import com.netscape.certsrv.system.Feature; +import com.netscape.cmstools.cli.CLI; + +public class FeatureShowCLI extends CLI { + + public FeatureCLI featureCLI; + + public FeatureShowCLI(FeatureCLI featureCLI) { + super("show", "Show features", featureCLI); + this.featureCLI = featureCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <ID>", options); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + } catch (ParseException e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length > 1) { + System.err.println("Error: too many arguments."); + printHelp(); + System.exit(-1); + } + + if (cmdArgs.length == 0) { + System.err.println("Error: No ID specified."); + printHelp(); + System.exit(-1); + } + + String featureID = cmdArgs[0]; + + Feature data = featureCLI.featureClient.getFeature(featureID); + FeatureCLI.printFeature(data); + } + +} |