use of org.apache.cloudstack.api.response.CertificateResponse in project cloudstack by apache.
the class IssueCertificateCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
if (StringUtils.isEmpty(getCsr()) && getDomains().isEmpty()) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please provide the domains or the CSR, none of them are provided");
}
final Certificate certificate = caManager.issueCertificate(getCsr(), getDomains(), getAddresses(), getValidityDuration(), getProvider());
if (certificate == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to issue client certificate with given provider");
}
final CertificateResponse certificateResponse = new CertificateResponse();
try {
certificateResponse.setCertificate(CertUtils.x509CertificateToPem(certificate.getClientCertificate()));
if (certificate.getPrivateKey() != null) {
certificateResponse.setPrivateKey(CertUtils.privateKeyToPem(certificate.getPrivateKey()));
}
if (certificate.getCaCertificates() != null) {
certificateResponse.setCaCertificate(CertUtils.x509CertificatesToPem(certificate.getCaCertificates()));
}
} catch (final IOException e) {
LOG.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to process and return client certificate");
}
certificateResponse.setResponseName(getCommandName());
setResponseObject(certificateResponse);
}
use of org.apache.cloudstack.api.response.CertificateResponse in project cloudstack by apache.
the class ListCaCertificateCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final String caCertificates;
try {
caCertificates = caManager.getCaCertificate(getProvider());
} catch (final IOException e) {
throw new CloudRuntimeException("Failed to get CA certificates for given CA provider");
}
final CertificateResponse certificateResponse = new CertificateResponse("cacertificates");
certificateResponse.setCertificate(caCertificates);
certificateResponse.setResponseName(getCommandName());
setResponseObject(certificateResponse);
}
Aggregations