use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testUpdateByAccountIdAndEnvironmentCredential.
@Test
void testUpdateByAccountIdAndEnvironmentCredential() {
Credential result = new Credential();
result.setId(2L);
result.setResourceCrn("this");
result.setCloudPlatform(PLATFORM);
CREDENTIAL.setId(1L);
CREDENTIAL.setResourceCrn("that");
CREDENTIAL.setCloudPlatform(PLATFORM);
when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
when(repository.save(any())).thenAnswer(i -> i.getArgument(0));
when(credentialValidator.validateCredentialUpdate(any(Credential.class), any(Credential.class), any(CredentialType.class))).thenReturn(ValidationResult.builder().build());
Credential testResult = credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, ENVIRONMENT);
verify(repository).save(CREDENTIAL);
assertEquals(2L, testResult.getId());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentCreationService method initializeEnvironment.
private Environment initializeEnvironment(EnvironmentCreationDto creationDto) {
Environment environment = environmentDtoConverter.creationDtoToEnvironment(creationDto);
environment.setResourceCrn(creationDto.getCrn());
Credential credential = environmentResourceService.getCredentialFromRequest(creationDto.getCredential(), creationDto.getAccountId());
environment.setCredential(credential);
Optional<ProxyConfig> proxyConfig = environmentResourceService.getProxyConfig(creationDto.getProxyConfigName(), creationDto.getAccountId());
proxyConfig.ifPresent(pc -> environment.setProxyConfig(pc));
environment.setCloudPlatform(credential.getCloudPlatform());
environment.setAuthentication(authenticationDtoConverter.dtoToAuthentication(creationDto.getAuthentication()));
environment.setEnvironmentServiceVersion(environmentServiceVersion);
LOGGER.info("Environment is initialized for creation.");
return environment;
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class S3GuardTableDeleteHandler method deleteNoSqlTable.
private ResponseStatus deleteNoSqlTable(LocationAwareCredential locationAwareCredential, String dynamoDbTablename) {
Credential credential = locationAwareCredential.getCredential();
String cloudPlatform = credential.getCloudPlatform();
String location = locationAwareCredential.getLocation();
NoSqlConnector noSqlConnector = getNoSqlConnector(cloudPlatform);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
NoSqlTableMetadataRequest noSqlTableMetadataRequest = NoSqlTableMetadataRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
NoSqlTableMetadataResponse noSqlTableMetaData = noSqlConnector.getNoSqlTableMetaData(noSqlTableMetadataRequest);
if (ResponseStatus.OK.equals(noSqlTableMetaData.getStatus())) {
NoSqlTableDeleteRequest request = NoSqlTableDeleteRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
NoSqlTableDeleteResponse response = noSqlConnector.deleteNoSqlTable(request);
return response.getStatus();
} else {
return ResponseStatus.OK;
}
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentServiceIntegrationTest method testCredentialList.
@Test
public void testCredentialList() {
credentialRepository.save(credential);
CredentialResponses results = client.credentialV1Endpoint().list();
assertTrue(results.getResponses().stream().anyMatch(credentialResponse -> credentialResponse.getName().equals(credential.getName())), String.format("Result set should have credential with name: %s", credential.getName()));
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentServiceIntegrationTest method setup.
@BeforeEach
public void setup() {
client = new EnvironmentServiceClientBuilder(String.format(SERVICE_ADDRESS, port)).withCertificateValidation(false).withDebug(true).withIgnorePreValidation(true).build().withCrn(TEST_USER_CRN);
credential = new Credential();
credential.setName("credential_test");
credential.setResourceCrn(TEST_RESOURCE_CRN);
credential.setAccountId(TEST_ACCOUNT_ID);
credential.setCloudPlatform("AWS");
credential.setCreator(TEST_USER_CRN);
credential.setDescription("description");
credential.setGovCloud(false);
credential.setArchived(false);
credential.setType(ENVIRONMENT);
credentialRequest = new CredentialRequest();
when(entitlementService.azureEnabled(any())).thenReturn(true);
doNothing().when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any(), any());
lenient().when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).then(i -> {
List<RightCheck> rightChecks = i.getArgument(1);
return rightChecks.stream().map(r -> Boolean.TRUE).collect(toList());
});
lenient().when(grpcUmsClient.checkAccountRight(anyString(), anyString(), any(), any())).thenReturn(true);
Map<String, Boolean> rightCheckMap = Maps.newHashMap();
rightCheckMap.put(credential.getResourceCrn(), true);
when(umsResourceAuthorizationService.getRightOfUserOnResources(anyString(), any(), anyList())).thenReturn(rightCheckMap);
when(grpcUmsClient.getResourceRoles(any(), any())).thenReturn(Set.of("crn:altus:iam:us-west-1:altus:resourceRole:Owner", "crn:altus:iam:us-west-1:altus:resourceRole:EnvironmentAdmin"));
}
Aggregations