use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class SecretAspectsTest method testproceedSaveEntitySecretRawIsNull.
@Test
public void testproceedSaveEntitySecretRawIsNull() throws Exception {
DummyTenantAwareResourceEntity dummyEntity = new DummyTenantAwareResourceEntity(new Secret(null));
when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { dummyEntity });
underTest.proceedOnRepositorySave(proceedingJoinPoint);
verifySecretManagementIgnoredDuringSave(dummyEntity.secret);
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class SecretAspectsTest method testproceedSaveAllEntity.
@Test
public void testproceedSaveAllEntity() throws Exception {
DummyTenantAwareResourceEntity dummyEntity = new DummyTenantAwareResourceEntity(new Secret("raw"));
when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { List.of(dummyEntity) });
when(tenant.getName()).thenReturn("tenant");
underTest.proceedOnRepositorySaveAll(proceedingJoinPoint);
verify(secretService, times(1)).put(anyString(), eq("raw"));
assertThat(dummyEntity.secret, IsInstanceOf.instanceOf(SecretProxy.class));
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class SecretAspectsTest method testproceedDeleteEntitySecretIsNull.
@Test
public void testproceedDeleteEntitySecretIsNull() {
DummyEntity dummyEntity = new DummyEntity(new Secret(null, null));
when(proceedingJoinPoint.getArgs()).thenReturn(new Object[] { dummyEntity });
underTest.proceedOnRepositoryDelete(proceedingJoinPoint);
verify(secretService, times(0)).delete(anyString());
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class SecretAspects method proceedDelete.
private Object proceedDelete(ProceedingJoinPoint proceedingJoinPoint) {
Collection<Object> entities = convertFirstArgToCollection(proceedingJoinPoint);
for (Object entity : entities) {
try {
for (Field field : entity.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(SecretValue.class)) {
LOGGER.debug("Found SecretValue annotation on {}", field);
field.setAccessible(true);
Secret path = (Secret) field.get(entity);
if (path != null && path.getSecret() != null) {
secretService.delete(path.getSecret());
LOGGER.debug("Secret deleted at path: {}", path);
} else {
LOGGER.debug("Secret is null for field: {}.{}", field.getDeclaringClass(), field.getName());
}
}
}
} catch (IllegalArgumentException e) {
LOGGER.error("Given entity isn't instance of TenantAwareResource or AccountIdAwareResource. Secret is not deleted!", e);
throw new CloudbreakServiceException(e);
} catch (Exception e) {
LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
throw new CloudbreakServiceException(e);
}
}
Object proceed;
try {
proceed = proceedingJoinPoint.proceed();
} catch (RuntimeException re) {
LOGGER.warn("Failed to invoke repository delete", re);
throw re;
} catch (Throwable throwable) {
LOGGER.error("Failed to invoke repository delete", throwable);
throw new CloudbreakServiceException(throwable);
}
return proceed;
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class TestUtil method setSecretField.
public static void setSecretField(Class<?> clazz, String fieldName, Object target, String raw, String secret) {
Field field = ReflectionUtils.findField(clazz, fieldName);
field.setAccessible(true);
try {
field.set(target, new Secret(raw, secret));
} catch (IllegalAccessException ignore) {
}
}
Aggregations