diff options
author | Fraser Tweedale <ftweedal@redhat.com> | 2014-07-23 02:40:07 -0400 |
---|---|---|
committer | Fraser Tweedale <frase@frase.id.au> | 2015-04-07 22:38:11 -0400 |
commit | c4ee90c89a0b3c61b18f865e6650b27e156a9dcb (patch) | |
tree | 609594bc43d68e67c1d70636ebfc753eaeb26062 /base/common/src/com/netscape/certsrv/profile | |
parent | e4869e62f432b510dc99eb7e00d16a23caa6ea64 (diff) | |
download | pki-c4ee90c89a0b3c61b18f865e6650b27e156a9dcb.tar.gz pki-c4ee90c89a0b3c61b18f865e6650b27e156a9dcb.tar.xz pki-c4ee90c89a0b3c61b18f865e6650b27e156a9dcb.zip |
Update pki-profile CLI commands to work with "raw" format
Update CLI commands for working with the (now LDAP-based)
profiles in the same format as was used by the files, by way of the
--raw option.
Also add the "edit" command to interactively edit a profile.
Diffstat (limited to 'base/common/src/com/netscape/certsrv/profile')
-rw-r--r-- | base/common/src/com/netscape/certsrv/profile/ProfileClient.java | 42 | ||||
-rw-r--r-- | base/common/src/com/netscape/certsrv/profile/ProfileResource.java | 20 |
2 files changed, 61 insertions, 1 deletions
diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java index 51d159aca..7f0b08f0e 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileClient.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileClient.java @@ -17,10 +17,15 @@ //--- END COPYRIGHT BLOCK --- package com.netscape.certsrv.profile; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.net.URISyntaxException; +import java.util.Properties; import javax.ws.rs.core.Response; +import com.netscape.certsrv.base.PKIException; import com.netscape.certsrv.client.Client; import com.netscape.certsrv.client.PKIClient; @@ -45,6 +50,11 @@ public class ProfileClient extends Client { return client.getEntity(response, ProfileData.class); } + public Properties retrieveProfileRaw(String id) { + Response response = profileClient.retrieveProfileRaw(id); + return byteArrayToProperties(client.getEntity(response, byte[].class)); + } + public ProfileDataInfos listProfiles(Integer start, Integer size) { Response response = profileClient.listProfiles(start, size); return client.getEntity(response, ProfileDataInfos.class); @@ -65,13 +75,45 @@ public class ProfileClient extends Client { return client.getEntity(response, ProfileData.class); } + public Properties createProfileRaw(Properties properties) { + Response response = + profileClient.createProfileRaw(propertiesToByteArray(properties)); + return byteArrayToProperties(client.getEntity(response, byte[].class)); + } + public ProfileData modifyProfile(ProfileData data) { Response response = profileClient.modifyProfile(data.getId(), data); return client.getEntity(response, ProfileData.class); } + public Properties modifyProfileRaw(String profileId, Properties properties) { + Response response = + profileClient.modifyProfileRaw(profileId, propertiesToByteArray(properties)); + return byteArrayToProperties(client.getEntity(response, byte[].class)); + } + public void deleteProfile(String id) { Response response = profileClient.deleteProfile(id); client.getEntity(response, Void.class); } + + private Properties byteArrayToProperties(byte[] data) throws PKIException { + Properties properties = new Properties(); + try { + properties.load(new ByteArrayInputStream(data)); + } catch (IOException e) { + throw new PKIException("Failed to decode profile Properties: " + e.toString()); + } + return properties; + } + + private byte[] propertiesToByteArray(Properties properties) throws PKIException { + ByteArrayOutputStream data = new ByteArrayOutputStream(); + try { + properties.store(data, null); + } catch (IOException e) { + throw new PKIException("Failed to encode profile Properties: " + e.toString()); + } + return data.toByteArray(); + } } diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileResource.java b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java index 87449b27e..410f98a46 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileResource.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java @@ -31,12 +31,24 @@ public interface ProfileResource { @ACLMapping("profiles.read") public Response retrieveProfile(@PathParam("id") String id); + @GET + @Path("{id}/raw") + @ClientResponseType(entityType=byte[].class) + @ACLMapping("profiles.read") + public Response retrieveProfileRaw(@PathParam("id") String id); + @POST @ClientResponseType(entityType=ProfileData.class) @ACLMapping("profiles.create") public Response createProfile(ProfileData data); @POST + @Path("raw") + @ClientResponseType(entityType=byte[].class) + @ACLMapping("profiles.create") + public Response createProfileRaw(byte[] data); + + @POST @Path("{id}") @ClientResponseType(entityType=Void.class) @ACLMapping("profiles.approve") @@ -48,9 +60,15 @@ public interface ProfileResource { @ACLMapping("profiles.modify") public Response modifyProfile(@PathParam("id") String id, ProfileData data); + @PUT + @Path("{id}/raw") + @ClientResponseType(entityType=byte[].class) + @ACLMapping("profiles.modify") + public Response modifyProfileRaw(@PathParam("id") String id, byte[] data); + @DELETE @Path("{id}") @ClientResponseType(entityType=Void.class) @ACLMapping("profiles.delete") public Response deleteProfile(@PathParam("id") String id); -}
\ No newline at end of file +} |