Search in sources :

Example 1 with CloudAccessConfigs

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method collectAccessConfigsWhenUserIsUnathorizedToGetInfoThenItShouldReturnEmptyList.

@Test
public void collectAccessConfigsWhenUserIsUnathorizedToGetInfoThenItShouldReturnEmptyList() throws Exception {
    AmazonServiceException amazonServiceException = new AmazonServiceException("unauthorized.");
    amazonServiceException.setStatusCode(403);
    when(awsClient.createAmazonIdentityManagement(any(AwsCredentialView.class))).thenReturn(amazonCFClient);
    when(amazonCFClient.listInstanceProfiles()).thenThrow(amazonServiceException);
    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage("Could not get instance profile roles because the user does not have enough permission.");
    CloudAccessConfigs cloudAccessConfigs = underTest.accessConfigs(new CloudCredential(1L, "aws-credential"), region("London"), new HashMap<>());
    Assert.assertEquals(0, cloudAccessConfigs.getCloudAccessConfigs().size());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) Test(org.junit.Test)

Example 2 with CloudAccessConfigs

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method collectAccessConfigsWhenWeGetBackInfoThenItShouldReturnListWithElements.

@Test
public void collectAccessConfigsWhenWeGetBackInfoThenItShouldReturnListWithElements() throws Exception {
    ListInstanceProfilesResult listInstanceProfilesResult = new ListInstanceProfilesResult();
    Set<InstanceProfile> instanceProfileSet = new HashSet<>();
    instanceProfileSet.add(instanceProfile(1));
    instanceProfileSet.add(instanceProfile(2));
    instanceProfileSet.add(instanceProfile(3));
    instanceProfileSet.add(instanceProfile(4));
    listInstanceProfilesResult.setInstanceProfiles(instanceProfileSet);
    when(awsClient.createAmazonIdentityManagement(any(AwsCredentialView.class))).thenReturn(amazonCFClient);
    when(amazonCFClient.listInstanceProfiles()).thenReturn(listInstanceProfilesResult);
    CloudAccessConfigs cloudAccessConfigs = underTest.accessConfigs(new CloudCredential(1L, "aws-credential"), region("London"), new HashMap<>());
    Assert.assertEquals(4, cloudAccessConfigs.getCloudAccessConfigs().size());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with CloudAccessConfigs

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs in project cloudbreak by hortonworks.

the class AwsPlatformResources method accessConfigs.

@Override
public CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    String queryFailedMessage = "Could not get instance profile roles from Amazon: ";
    CloudAccessConfigs cloudAccessConfigs = new CloudAccessConfigs(new HashSet<>());
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonIdentityManagement client = awsClient.createAmazonIdentityManagement(awsCredentialView);
    try {
        ListInstanceProfilesResult listRolesResult = client.listInstanceProfiles();
        for (InstanceProfile instanceProfile : listRolesResult.getInstanceProfiles()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("arn", instanceProfile.getArn());
            properties.put("creationDate", instanceProfile.getCreateDate().toString());
            if (!instanceProfile.getRoles().isEmpty()) {
                String roleName = instanceProfile.getRoles().get(0).getArn();
                properties.put("roleArn", Strings.isNullOrEmpty(roleName) ? instanceProfile.getArn() : roleName);
            }
            cloudAccessConfigs.getCloudAccessConfigs().add(new CloudAccessConfig(instanceProfile.getInstanceProfileName(), instanceProfile.getInstanceProfileId(), properties));
        }
    } catch (AmazonServiceException ase) {
        if (ase.getStatusCode() == UNAUTHORIZED) {
            String policyMessage = "Could not get instance profile roles because the user does not have enough permission.";
            LOGGER.info(policyMessage + ase);
            throw new CloudConnectorException(policyMessage, ase);
        } else {
            LOGGER.error(queryFailedMessage, ase);
            throw new CloudConnectorException(queryFailedMessage + ase.getMessage(), ase);
        }
    } catch (Exception e) {
        LOGGER.error(queryFailedMessage, e);
        throw new CloudConnectorException(queryFailedMessage + e.getMessage(), e);
    }
    return cloudAccessConfigs;
}
Also used : CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) IOException(java.io.IOException) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult)

Example 4 with CloudAccessConfigs

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs in project cloudbreak by hortonworks.

the class PlatformParameterV1Controller method getAccessConfigs.

@Override
public PlatformAccessConfigsResponse getAccessConfigs(PlatformResourceRequestJson resourceRequestJson) {
    resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
    PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
    CloudAccessConfigs cloudAccessConfigs = cloudParameterService.getCloudAccessConfigs(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
    return conversionService.convert(cloudAccessConfigs, PlatformAccessConfigsResponse.class);
}
Also used : CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) PlatformResourceRequest(com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)

Example 5 with CloudAccessConfigs

use of com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs in project cloudbreak by hortonworks.

the class GetPlatformAccessConfigsHandler method accept.

@Override
public void accept(Event<GetPlatformCloudAccessConfigsRequest> getPlatformCloudAccessConfigsRequest) {
    LOGGER.info("Received event: {}", getPlatformCloudAccessConfigsRequest);
    GetPlatformCloudAccessConfigsRequest request = getPlatformCloudAccessConfigsRequest.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudAccessConfigs cloudAccessConfigs = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().accessConfigs(request.getCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformCloudAccessConfigsResult getPlatformCloudAccessConfigsResult = new GetPlatformCloudAccessConfigsResult(request, cloudAccessConfigs);
        request.getResult().onNext(getPlatformCloudAccessConfigsResult);
        LOGGER.info("Query platform access configs finished.");
    } catch (Exception e) {
        request.getResult().onNext(new GetPlatformCloudAccessConfigsResult(e.getMessage(), e, request));
    }
}
Also used : GetPlatformCloudAccessConfigsResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsResult) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) GetPlatformCloudAccessConfigsRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsRequest)

Aggregations

CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)7 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)5 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 Test (org.junit.Test)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)2 ListInstanceProfilesResult (com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult)2 AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)1 GetPlatformCloudAccessConfigsRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsRequest)1 GetPlatformCloudAccessConfigsResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformCloudAccessConfigsResult)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudAccessConfig (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 PlatformResourceRequest (com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BadRequestException (javax.ws.rs.BadRequestException)1