Search in sources :

Example 1 with CredentialRequest

use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.

the class CredentialValidatorTest method testValidateAwsCredentialRequestNoAwsParams.

@Test
void testValidateAwsCredentialRequestNoAwsParams() {
    CredentialRequest request = new CredentialRequest();
    request.setCloudPlatform("AWS");
    ValidationResult result = underTest.validateAwsCredentialRequest(request);
    assertTrue(result.hasError());
    assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0));
}
Also used : CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CredentialRequest

use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.

the class CredentialValidatorTest method testValidateAwsCredentialRequestKeyBased.

@Test
void testValidateAwsCredentialRequestKeyBased() {
    CredentialRequest request = new CredentialRequest();
    request.setCloudPlatform("AWS");
    request.setAws(new AwsCredentialParameters());
    ValidationResult result = underTest.validateAwsCredentialRequest(request);
    assertTrue(result.hasError());
    assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0));
}
Also used : CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AwsCredentialParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.AwsCredentialParameters) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CredentialRequest

use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.

the class AuditCredentialV1Controller method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_AUDIT_CREDENTIAL)
public CredentialResponse post(@Valid CredentialRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    Credential credential = credentialConverter.convert(request);
    credential.setType(AUDIT);
    credential.setVerifyPermissions(false);
    notify(ResourceEvent.CREDENTIAL_CREATED);
    Set<Credential> auditCredentialsByPlatfom = credentialService.listAvailablesByAccountId(accountId, AUDIT).stream().filter(c -> c.getCloudPlatform().equals(credential.getCloudPlatform())).collect(Collectors.toSet());
    if (auditCredentialsByPlatfom.isEmpty()) {
        return credentialConverter.convert(credentialService.create(credential, accountId, creator, AUDIT));
    } else {
        throw new BadRequestException(String.format("Audit credential already exist for %s cloud.", credential.getCloudPlatform()));
    }
}
Also used : CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) Credential(com.sequenceiq.environment.credential.domain.Credential) AUDIT(com.sequenceiq.common.model.CredentialType.AUDIT) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) CredentialDeleteService(com.sequenceiq.environment.credential.service.CredentialDeleteService) Controller(org.springframework.stereotype.Controller) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Collectors(java.util.stream.Collectors) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Valid(javax.validation.Valid) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) NotificationController(com.sequenceiq.notification.NotificationController) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) AuditCredentialEndpoint(com.sequenceiq.environment.api.v1.credential.endpoint.AuditCredentialEndpoint) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 4 with CredentialRequest

use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.

the class CredentialV1Controller method interactiveLogin.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_CREDENTIAL)
public InteractiveCredentialResponse interactiveLogin(@Valid CredentialRequest credentialRequest) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    Credential credential = credentialConverter.convert(credentialRequest);
    credential.setType(ENVIRONMENT);
    Map<String, String> result = credentialService.interactiveLogin(accountId, credential);
    return new InteractiveCredentialResponse(result.get("user_code"), result.get("verification_url"));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 5 with CredentialRequest

use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.

the class CredentialTestDto method modifyRequest.

public EditCredentialRequest modifyRequest() {
    EditCredentialRequest editRequest = new EditCredentialRequest();
    CredentialRequest request = getRequest();
    editRequest.setName(request.getName());
    editRequest.setAzure(request.getAzure());
    editRequest.setAws(request.getAws());
    editRequest.setGcp(request.getGcp());
    editRequest.setMock(request.getMock());
    editRequest.setYarn(request.getYarn());
    editRequest.setCloudPlatform(request.getName());
    editRequest.setDescription(request.getName());
    editRequest.setCloudPlatform(getCloudPlatform().name());
    return editRequest;
}
Also used : CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest)

Aggregations

CredentialRequest (com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest)10 Test (org.junit.jupiter.api.Test)8 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)5 AwsCredentialParameters (com.sequenceiq.environment.api.v1.credential.model.parameters.aws.AwsCredentialParameters)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EditCredentialRequest (com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest)4 InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)4 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)3 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)2 InteractiveLoginResult (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult)2 ResourceDefinitionResult (com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult)2 RoleBasedParameters (com.sequenceiq.environment.api.v1.credential.model.parameters.aws.RoleBasedParameters)2 AzureCredentialRequestParameters (com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters)2 RoleBasedRequest (com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest)2 CredentialResponses (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 RightCheck (com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck)1 Maps (com.google.common.collect.Maps)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)1