use of com.sequenceiq.freeipa.client.model.Cert in project cloudbreak by hortonworks.
the class CertFindResponse method handleInternal.
@Override
protected Set<Cert> handleInternal(List<CloudVmMetaDataStatus> metadatas, String body) {
Cert cert = new Cert();
cert.setCacn("dummy");
cert.setIssuer("dummy");
return Set.of(cert);
}
use of com.sequenceiq.freeipa.client.model.Cert in project cloudbreak by hortonworks.
the class CleanupService method revokeCerts.
@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts) throws FreeIpaClientException {
FreeIpaClient client = getFreeIpaClient(stackId);
Set<String> certCleanupSuccess = new HashSet<>();
Map<String, String> certCleanupFailed = new HashMap<>();
Set<Cert> certs = client.findAllCert();
certs.stream().filter(cert -> hosts.stream().anyMatch(host -> substringBefore(host, ".").equals(substringBefore(removeStart(cert.getSubject(), "CN="), ".")))).filter(cert -> !cert.isRevoked()).forEach(cert -> {
try {
client.revokeCert(cert.getSerialNumber());
certCleanupSuccess.add(cert.getSubject());
} catch (FreeIpaClientException e) {
LOGGER.error("Couldn't revoke certificate: {}", cert, e);
certCleanupFailed.put(cert.getSubject(), e.getMessage());
}
});
return Pair.of(certCleanupSuccess, certCleanupFailed);
}
use of com.sequenceiq.freeipa.client.model.Cert in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRevokeCertsWithAlreadyRevokedCert.
@Test
public void testRevokeCertsWithAlreadyRevokedCert() throws FreeIpaClientException {
Set<String> hosts = Set.of("test-wl-1-worker0.env.xyz.wl.cloudera.site", "test-wl-1-worker1.env.xyz.wl.cloudera.site", "test-wl-1-master2.env.xyz.wl.cloudera.site", "test-wl-1-compute3.env.xyz.wl.cloudera.site");
Set<Cert> certs = Set.of(createCert("CN=test-wl-2-master2", 1, false), createCert("CN=test-wl-1-master2", 2, true), createCert("CN=test-wl-3-master1", 3, true), createCert("CN=test-datalake-1-master1", 4, false), createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClient.findAllCert()).thenReturn(certs);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);
verifyRevokeNotInvoked(freeIpaClient, 1, 2, 3, 4, 50);
assertEquals(0, result.getFirst().size());
assertEquals(0, result.getSecond().size());
}
use of com.sequenceiq.freeipa.client.model.Cert in project cloudbreak by hortonworks.
the class CleanupServiceTest method testRevokeCertsWithShortHostnames.
@Test
public void testRevokeCertsWithShortHostnames() throws FreeIpaClientException {
Set<String> hosts = Set.of("test-wl-1-worker0", "test-wl-1-worker1", "test-wl-1-master2", "test-wl-1-compute3");
Set<Cert> certs = Set.of(createCert("CN=test-wl-2-master2", 1, false), createCert("CN=test-wl-1-master2", 2, false), createCert("CN=test-wl-3-master1", 3, false), createCert("CN=test-datalake-1-master1", 4, false), createCert("CN=ipaserver0.env.xyz.wl.cloudera.site,O=ENV.XYZ.WL.CLOUDERA.SITE", 50, false));
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClient.findAllCert()).thenReturn(certs);
when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(freeIpaClient);
Pair<Set<String>, Map<String, String>> result = cleanupService.revokeCerts(STACK_ID, hosts);
verify(freeIpaClient, times(1)).revokeCert(2);
verifyRevokeNotInvoked(freeIpaClient, 1, 3, 4, 50);
assertEquals(1, result.getFirst().size());
assertEquals(0, result.getSecond().size());
assertTrue(result.getFirst().stream().allMatch("CN=test-wl-1-master2"::equals));
}
use of com.sequenceiq.freeipa.client.model.Cert in project cloudbreak by hortonworks.
the class CleanupServiceTest method createCert.
private Cert createCert(String subject, long serialNumber, boolean revoked) {
Cert cert = new Cert();
cert.setSubject(subject);
cert.setRevoked(revoked);
cert.setSerialNumber(serialNumber);
return cert;
}
Aggregations