use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class Cluster method setDpUser.
public void setDpUser(String dpAmbariUser) {
this.dpAmbariUser = new Secret(dpAmbariUser);
dpClusterManagerUser = new Secret(dpAmbariUser);
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class Cluster method setDpPassword.
public void setDpPassword(String dpAmbariPassword) {
this.dpAmbariPassword = new Secret(dpAmbariPassword);
this.dpClusterManagerPassword = new Secret(dpAmbariPassword);
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class ClusterHostServiceRunnerTest method setupMocksForRunClusterServices.
private void setupMocksForRunClusterServices() {
when(umsClient.getAccountDetails(any(), any(), any())).thenReturn(UserManagementProto.Account.getDefaultInstance());
when(stackService.get(any())).thenReturn(stack);
when(stack.getCluster()).thenReturn(cluster);
when(stack.getTunnel()).thenReturn(Tunnel.DIRECT);
when(stack.getCloudPlatform()).thenReturn(CloudPlatform.AWS.name());
when(stack.getResourceCrn()).thenReturn(TEST_CLUSTER_CRN);
when(cluster.getName()).thenReturn("clustername");
when(cluster.getStack()).thenReturn(stack);
when(componentLocator.getComponentLocation(any(), any())).thenReturn(new HashMap<>());
when(exposedServiceCollector.getImpalaService()).thenReturn(mock(ExposedService.class));
when(environmentConfigProvider.getParentEnvironmentCrn(any())).thenReturn("crn:cdp:iam:us-west-1:accid:user:mockuser@cloudera.com");
ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
when(clouderaManagerRepo.getVersion()).thenReturn("7.2.2");
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfig.getPrivateAddress()).thenReturn("1.2.3.4");
when(gatewayConfig.getHostname()).thenReturn("hostname");
when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(any())).thenReturn(clouderaManagerRepo);
when(exposedServiceCollector.getRangerService()).thenReturn(mock(ExposedService.class));
ExposedService cmExposedService = mock(ExposedService.class);
when(cmExposedService.getServiceName()).thenReturn("CM");
when(exposedServiceCollector.getClouderaManagerService()).thenReturn(cmExposedService);
Template template = new Template();
template.setTemporaryStorage(TemporaryStorage.EPHEMERAL_VOLUMES);
Set<InstanceGroup> instanceGroups = new HashSet<>();
createInstanceGroup(template, instanceGroups, "fqdn1", null, "1.1.1.1", "1.1.1.2");
createInstanceGroup(template, instanceGroups, "fqdn2", null, "1.1.2.1", "1.1.2.2");
InstanceGroup gwIg = createInstanceGroup(template, instanceGroups, "gateway1", "gateway2", "1.1.3.1", "1.1.3.2");
lenient().when(stack.getNotTerminatedAndNotZombieGatewayInstanceMetadata()).thenReturn(Lists.newArrayList(gwIg.getAllInstanceMetaData()));
when(stack.getInstanceGroups()).thenReturn(instanceGroups);
RdsConfigWithoutCluster rdsConfigWithoutCluster = mock(RdsConfigWithoutCluster.class);
when(rdsConfigWithoutClusterService.findByClusterIdAndType(any(), eq(DatabaseType.CLOUDERA_MANAGER))).thenReturn(rdsConfigWithoutCluster);
when(rdsConfigWithoutCluster.getType()).thenReturn("asdf");
when(rdsConfigWithoutCluster.getConnectionURL()).thenReturn("jdbc:postgresql:subname://some-rds.1d3nt1f13r.eu-west-1.rds.amazonaws.com:5432/ranger");
when(rdsConfigWithoutCluster.getConnectionUserName()).thenReturn(new Secret("username"));
when(rdsConfigWithoutCluster.getConnectionPassword()).thenReturn(new Secret("password"));
when(loadBalancerSANProvider.getLoadBalancerSAN(stack)).thenReturn(Optional.empty());
ClusterPreCreationApi clusterPreCreationApi = mock(ClusterPreCreationApi.class);
when(clusterApiConnectors.getConnector(cluster)).thenReturn(clusterPreCreationApi);
ServiceLocationMap serviceLocationMap = new ServiceLocationMap();
serviceLocationMap.add(new ServiceLocation("serv", "paath"));
when(clusterPreCreationApi.getServiceLocations()).thenReturn(serviceLocationMap);
ReflectionTestUtils.setField(underTest, "cmHeartbeatInterval", "1");
ReflectionTestUtils.setField(underTest, "cmMissedHeartbeatInterval", "1");
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class SecretAspectService method proceedDelete.
public 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 {}. Secret is not deleted!", AccountIdAwareResource.class.getSimpleName(), e);
throw new SecretOperationException(e.getMessage());
} catch (Exception e) {
LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
throw new SecretOperationException(e.getMessage());
}
}
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 SecretOperationException(throwable);
}
return proceed;
}
use of com.sequenceiq.cloudbreak.service.secret.domain.Secret in project cloudbreak by hortonworks.
the class RecursiveSecretAspectService method proceedSave.
public Object proceedSave(ProceedingJoinPoint proceedingJoinPoint) {
Queue<Object> entities = convertFirstArgToQueue(proceedingJoinPoint);
Object entity;
while ((entity = entities.poll()) != null) {
try {
for (Field field : entity.getClass().getDeclaredFields()) {
if (field.isAnnotationPresent(SecretValue.class)) {
LOGGER.info("Found SecretValue annotation on {} in entity of type {}", field, entity.getClass());
field.setAccessible(true);
Object fieldValue = field.get(entity);
if (fieldValue instanceof Secret) {
Secret value = (Secret) field.get(entity);
if (value != null && value.getRaw() != null && value.getSecret() == null) {
String path = String.format("%s/%s/%s-%s", entity.getClass().getSimpleName().toLowerCase(), field.getName().toLowerCase(), UUID.randomUUID().toString(), Long.toHexString(System.currentTimeMillis()));
String secret = secretService.put(path, value.getRaw());
LOGGER.info("Field: '{}' is saved at path: {}", field.getName(), path);
field.set(entity, new SecretProxy(secretService, secret));
}
} else {
entities.add(fieldValue);
}
}
}
} catch (IllegalArgumentException e) {
LOGGER.error("Given entity isn't instance of TenantAwareResource. Secret is not saved!", e);
throw new SecretOperationException(e);
} catch (Exception e) {
LOGGER.warn("Looks like something went wrong with Secret store. Secret is not saved!", e);
throw new SecretOperationException(e);
}
}
Object proceed;
try {
proceed = proceedingJoinPoint.proceed();
} catch (RuntimeException re) {
LOGGER.warn("Failed to invoke repository save", re);
throw re;
} catch (Throwable throwable) {
LOGGER.error("Failed to invoke repository save", throwable);
throw new SecretOperationException(throwable);
}
return proceed;
}
Aggregations