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 | |
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')
8 files changed, 284 insertions, 8 deletions
diff --git a/base/common/src/com/netscape/certsrv/ca/CAClient.java b/base/common/src/com/netscape/certsrv/ca/CAClient.java index 1fbd2a0b2..bb131ecb1 100644 --- a/base/common/src/com/netscape/certsrv/ca/CAClient.java +++ b/base/common/src/com/netscape/certsrv/ca/CAClient.java @@ -19,14 +19,15 @@ package com.netscape.certsrv.ca; import java.net.URISyntaxException; +import com.netscape.certsrv.authority.AuthorityClient; import com.netscape.certsrv.cert.CertClient; import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.client.SubsystemClient; import com.netscape.certsrv.group.GroupClient; import com.netscape.certsrv.profile.ProfileClient; import com.netscape.certsrv.selftests.SelfTestClient; +import com.netscape.certsrv.system.FeatureClient; import com.netscape.certsrv.user.UserClient; -import com.netscape.certsrv.authority.AuthorityClient; public class CAClient extends SubsystemClient { @@ -38,6 +39,7 @@ public class CAClient extends SubsystemClient { public void init() throws URISyntaxException { addClient(new AuthorityClient(client, name)); addClient(new CertClient(client, name)); + addClient(new FeatureClient(client, name)); addClient(new GroupClient(client, name)); addClient(new ProfileClient(client, name)); addClient(new SelfTestClient(client, name)); diff --git a/base/common/src/com/netscape/certsrv/system/Feature.java b/base/common/src/com/netscape/certsrv/system/Feature.java index 59b88d2f6..c995a2e6d 100644 --- a/base/common/src/com/netscape/certsrv/system/Feature.java +++ b/base/common/src/com/netscape/certsrv/system/Feature.java @@ -56,12 +56,12 @@ public class Feature { } @XmlAttribute(name="enabled") - public boolean getEnabled() { + public boolean isEnabled() { return enabled; } - public void setEnabled(String enabled) { - this.enabled = enabled.equalsIgnoreCase("true"); + public void setEnabled(boolean enabled) { + this.enabled = enabled; } @XmlAttribute(name="version") @@ -138,7 +138,7 @@ public class Feature { public static void main(String args[]) throws Exception { Feature before = new Feature(); before.setId("authority"); - before.setEnabled("true"); + before.setEnabled(true); before.setDescription("Subordinate CA Feature"); before.setVersion("1.0"); diff --git a/base/common/src/com/netscape/certsrv/system/FeatureClient.java b/base/common/src/com/netscape/certsrv/system/FeatureClient.java new file mode 100644 index 000000000..c5c9a1642 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/system/FeatureClient.java @@ -0,0 +1,51 @@ +//--- 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.certsrv.system; + +import java.net.URISyntaxException; +import java.util.List; + +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; + +import com.netscape.certsrv.client.Client; +import com.netscape.certsrv.client.PKIClient; + +/** +* @author Ade Lee <alee@redhat.com> +*/ +public class FeatureClient extends Client { + + public FeatureResource featureClient; + + public FeatureClient(PKIClient client, String subsystem) throws URISyntaxException { + super(client, subsystem, "feature"); + featureClient = createProxy(FeatureResource.class); + } + + public List<Feature> listFeatures() { + Response response = featureClient.listFeatures(); + GenericType<List<Feature>> type = new GenericType<List<Feature>>() {}; + return client.getEntity(response, type); + } + + public Feature getFeature(String featureID) { + Response response = featureClient.getFeature(featureID); + return client.getEntity(response, Feature.class); + } +}
\ No newline at end of file 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); + } + +} diff --git a/base/server/cms/src/org/dogtagpki/server/rest/FeatureService.java b/base/server/cms/src/org/dogtagpki/server/rest/FeatureService.java index 0361d6b0a..df0ea5344 100644 --- a/base/server/cms/src/org/dogtagpki/server/rest/FeatureService.java +++ b/base/server/cms/src/org/dogtagpki/server/rest/FeatureService.java @@ -55,9 +55,9 @@ public class FeatureService extends PKIService implements FeatureResource { props = cs.getSubStore(tag).getProperties(); Feature feature = new Feature(); feature.setId(tag); - feature.setEnabled(props.getOrDefault("enabled", "false")); - feature.setDescription(props.getOrDefault("description", "")); - feature.setVersion(props.getOrDefault("version", "")); + feature.setEnabled(Boolean.parseBoolean(props.get("enabled"))); + feature.setDescription(props.get("description")); + feature.setVersion(props.get("version")); return feature; } catch (EBaseException e) { throw new PKIException(e); |