use of com.amazonaws.services.identitymanagement.model.InstanceProfile 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());
}
use of com.amazonaws.services.identitymanagement.model.InstanceProfile 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;
}
use of com.amazonaws.services.identitymanagement.model.InstanceProfile in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method instanceProfile.
private InstanceProfile instanceProfile(int i) {
InstanceProfile instanceProfile = new InstanceProfile();
instanceProfile.setArn(String.format("arn-%s", i));
instanceProfile.setCreateDate(new Date());
instanceProfile.setInstanceProfileId(String.format("profilId-%s", i));
instanceProfile.setInstanceProfileName(String.format("profilName-%s", i));
SdkInternalList<Role> roles = new SdkInternalList();
Role role = new Role();
role.setRoleName(String.format("roleArn-%s", i));
roles.add(role);
return instanceProfile;
}
Aggregations