Search in sources :

Example 1 with CloudZone

use of com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone in project vcert-java by Venafi.

the class CloudConnectorUtils method setCit.

public static void setCit(String policyName, CertificateIssuingTemplate cit, CloudPolicy.CAInfo caInfo, String apiKey, Cloud cloud) throws VCertException {
    CloudZone cloudZone = new CloudZone(policyName);
    cit.name(cloudZone.citAlias());
    // getting the CAProductOptionId
    CAAccountInfo caAccountInfo = CloudConnectorUtils.getCAAccountInfo(caInfo, apiKey, cloud);
    String caProductOptionId = caAccountInfo.productId;
    if (caProductOptionId == null)
        throw new VCertException("Specified CA doesn't exist");
    // Setting the CAProductOptionId to the parsed cit
    cit.certificateAuthorityProductOptionId(caProductOptionId);
    // setting the OrganizationId if the CA is DIGICERT
    if (caInfo.caType().equals(CloudConstants.DIGICERT_TYPE))
        if (caAccountInfo.organizationId != null)
            cit.product().organizationId(caAccountInfo.organizationId);
        else
            throw new VCertException("It was not possible to determine the Organization Id from the DIGICERT Product.");
    // Getting the cit from the server
    CertificateIssuingTemplate citFromServer = CloudConnectorUtils.getCIT(cit.name(), apiKey, cloud);
    // if cit already exists
    if (citFromServer != null) {
        // update it
        // the citId can't put directly in the cit because it is not part of the format of the body request that the endpoint is waiting
        cloud.updateCIT(cit, citFromServer.id(), apiKey);
        cit.id(citFromServer.id());
    } else {
        // create it
        // setting the citId resulting of the creation of the cit
        cit.id(createCIT(cit, apiKey, cloud));
    }
    setCitToApp(policyName, cit, apiKey, cloud);
}
Also used : VCertException(com.venafi.vcert.sdk.VCertException) CertificateIssuingTemplate(com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate) CloudZone(com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)

Example 2 with CloudZone

use of com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone in project vcert-java by Venafi.

the class CloudConnectorUtils method setCitToApp.

public static void setCitToApp(String policyName, CertificateIssuingTemplate cit, /*, CloudPolicy.CAInfo caInfo*/
String apiKey, Cloud cloud) throws VCertException {
    // getting the cloud zone
    CloudZone zone = new CloudZone(policyName);
    Application application = null;
    try {
        application = cloud.applicationByName(zone.appName(), apiKey);
    } catch (FeignException exception) {
        if (exception.status() != 404) {
            throw exception;
        }
    }
    // then it will needed to create it
    if (application == null)
        // create the application and related it with the cit
        createAppForCit(cit, zone.appName(), apiKey, cloud);
    else
        // update the application with the relation to the cit if that is not existing
        addCitToApp(cit, application, apiKey, cloud);
}
Also used : FeignException(feign.FeignException) Application(com.venafi.vcert.sdk.connectors.cloud.domain.Application) CloudZone(com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)

Aggregations

CloudZone (com.venafi.vcert.sdk.connectors.cloud.domain.CloudZone)2 VCertException (com.venafi.vcert.sdk.VCertException)1 Application (com.venafi.vcert.sdk.connectors.cloud.domain.Application)1 CertificateIssuingTemplate (com.venafi.vcert.sdk.connectors.cloud.domain.CertificateIssuingTemplate)1 FeignException (feign.FeignException)1