use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded.
@Test
void testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyAndKnoxAndDefaultSecGroupAdded() {
Environment environment = new Environment();
environment.setCidr("cidr");
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withDefaultSecurityGroupId("sec-group").withSecurityGroupIdForKnox("knox-sec-group").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentApiConverter method initCreationDto.
public EnvironmentCreationDto initCreationDto(EnvironmentRequest request) {
LOGGER.debug("Creating EnvironmentCreationDto from EnvironmentRequest: {}", request);
String accountId = ThreadBasedUserCrnProvider.getAccountId();
String cloudPlatform = credentialService.getCloudPlatformByCredential(request.getCredentialName(), accountId, ENVIRONMENT);
Builder builder = EnvironmentCreationDto.builder().withAccountId(accountId).withCreator(ThreadBasedUserCrnProvider.getUserCrn()).withName(request.getName()).withDescription(request.getDescription()).withCloudPlatform(cloudPlatform).withCredential(request).withCreated(System.currentTimeMillis()).withFreeIpaCreation(freeIpaConverter.convert(request.getFreeIpa(), accountId, cloudPlatform)).withLocation(locationRequestToDto(request.getLocation())).withTelemetry(telemetryApiConverter.convert(request.getTelemetry(), accountTelemetryService.getOrDefault(accountId).getFeatures(), accountId)).withBackup((request.getBackup() != null && isNotEmpty(request.getBackup().getStorageLocation())) ? backupConverter.convert(request.getBackup()) : backupConverter.convert(request.getTelemetry())).withRegions(locationRequestToRegions(request.getLocation(), cloudPlatform)).withAuthentication(authenticationRequestToDto(request.getAuthentication())).withAdminGroupName(request.getAdminGroupName()).withTags(request.getTags()).withCrn(createCrn(ThreadBasedUserCrnProvider.getAccountId())).withExperimentalFeatures(ExperimentalFeatures.builder().withIdBrokerMappingSource(request.getIdBrokerMappingSource()).withCloudStorageValidation(request.getCloudStorageValidation()).withTunnel(tunnelConverter.convert(request.getTunnel())).withOverrideTunnel(request.getOverrideTunnel()).withCcmV2TlsType(request.getCcmV2TlsType()).build()).withParameters(paramsToParametersDto(request, cloudPlatform)).withParentEnvironmentName(request.getParentEnvironmentName()).withProxyConfigName(request.getProxyConfigName());
NullUtil.doIfNotNull(request.getNetwork(), network -> builder.withNetwork(networkRequestToDto(network)));
NullUtil.doIfNotNull(request.getSecurityAccess(), securityAccess -> builder.withSecurityAccess(securityAccessRequestToDto(securityAccess)));
// TODO temporary until CCM not really integrated
if (request.getSecurityAccess() == null && !CloudPlatform.GCP.name().equals(cloudPlatform)) {
SecurityAccessDto securityAccess = SecurityAccessDto.builder().withCidr("0.0.0.0/0").build();
builder.withSecurityAccess(securityAccess);
}
return builder.build();
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class GcpEnvironmentSecurityGroupValidator method validate.
@Override
public void validate(EnvironmentValidationDto environmentValidationDto, ValidationResult.ValidationResultBuilder resultBuilder) {
EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
SecurityAccessDto securityAccessDto = environmentDto.getSecurityAccess();
if (securityAccessDto != null) {
if (onlyOneSecurityGroupIdDefined(securityAccessDto)) {
resultBuilder.error(securityGroupIdsMustBePresent());
} else if (isSecurityGroupIdDefined(securityAccessDto)) {
if (!Strings.isNullOrEmpty(securityAccessDto.getDefaultSecurityGroupId())) {
validateSecurityGroup(environmentDto, resultBuilder, securityAccessDto.getDefaultSecurityGroupId());
}
if (!Strings.isNullOrEmpty(securityAccessDto.getSecurityGroupIdForKnox())) {
validateSecurityGroup(environmentDto, resultBuilder, securityAccessDto.getSecurityGroupIdForKnox());
}
}
}
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editSecurityAccessIfChanged.
private void editSecurityAccessIfChanged(EnvironmentEditDto editDto, Environment environment) {
SecurityAccessDto securityAccessDto = editDto.getSecurityAccess();
if (securityAccessDto != null) {
EnvironmentValidatorService validatorService = environmentService.getValidatorService();
ValidationResult validationResult = validatorService.validateSecurityAccessModification(securityAccessDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
validationResult = validatorService.validateSecurityGroups(editDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
environmentService.editSecurityAccess(environment, securityAccessDto);
}
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromAwsCloudProviderMustUseSubnetId.
@Test
public void testRefreshMetadataFromAwsCloudProviderMustUseSubnetId() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "s1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Aggregations