/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.intel.mtwilson.tag.client.jaxrs;
import com.intel.dcsg.cpg.io.UUID;
import com.intel.mtwilson.jaxrs2.client.MtWilsonClient;
import java.net.URL;
import java.util.Properties;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
/**
*
* @author ssbangal
*/
public class ApproveTagCertificateRequest extends MtWilsonClient {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Selections.class);
public ApproveTagCertificateRequest(URL url) throws Exception{
super(url);
}
public ApproveTagCertificateRequest(Properties properties) throws Exception {
super(properties);
}
/**
* This function provided the certificate request ID, and the certificate associated to it (provided
* by an external CA), stores the certificate details in the database and updates the request status to
* completed. Here it is assumed that the external CA would have added the required attributes in the
* certificate it generated.
* @param certificateRequestId Id of the certificate request that was created as a placeholder for external CA to
* generated the certificate.
* @param certificate Certificate generated by the external CA for the specified certificate request.
* @since Mt.Wilson 2.0
* @mtwRequiresPermissions tag_certificates:create,tag_certificate_requests:store
* @mtwContentTypeReturned JSON/XML/YAML
* @mtwMethodType POST
* @mtwSampleRestCall
* <pre>
* https://192.168.1.101:8181/mtwilson/v2/approve-tag-certificate-request
* Input: {"certificate_request_id":"187ec902-c6c6-4dfb-adb4-f240099aa4b0","certificate":"MIIO....ic="}
* </pre>
* @mtwSampleApiCall
* <pre>
* ApproveTagCertificateRequest client = new ApproveTagCertificateRequest(My.configuration().getClientProperties());
* client.provisionTagCertificate("a6544ff4-6dc7-4c74-82be-578592e7e3ba",...);
* </pre>
*/
public void provisionTagCertificate(UUID certificateRequestId, byte[] certificate) {
log.debug("target: {}", getTarget().getUri().toString());
Response obj = getTarget().path("rpc/approve-tag-certificate-request").request().accept(MediaType.APPLICATION_JSON).post(Entity.json(certificateRequestId));
if( !obj.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) {
throw new IllegalStateException("Tag provisioning failed");
}
}
}