Search in sources :

Example 21 with AmazonIdentityManagement

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement in project aws-doc-sdk-examples by awsdocs.

the class ListUsers method main.

public static void main(String[] args) {
    final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient();
    boolean done = false;
    while (!done) {
        ListUsersRequest request = new ListUsersRequest();
        ListUsersResult response = iam.listUsers(request);
        for (User user : response.getUsers()) {
            System.out.format("Retrieved user %s", user.getUserName());
        }
        request.setMarker(response.getMarker());
        if (!response.getIsTruncated()) {
            done = true;
        }
    }
}
Also used : ListUsersRequest(com.amazonaws.services.identitymanagement.model.ListUsersRequest) User(com.amazonaws.services.identitymanagement.model.User) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) ListUsersResult(com.amazonaws.services.identitymanagement.model.ListUsersResult)

Example 22 with AmazonIdentityManagement

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagement 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)

Aggregations

AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)22 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AttachedPolicy (com.amazonaws.services.identitymanagement.model.AttachedPolicy)2 ListAttachedRolePoliciesRequest (com.amazonaws.services.identitymanagement.model.ListAttachedRolePoliciesRequest)2 ListAttachedRolePoliciesResult (com.amazonaws.services.identitymanagement.model.ListAttachedRolePoliciesResult)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AccessKeyMetadata (com.amazonaws.services.identitymanagement.model.AccessKeyMetadata)1 AttachRolePolicyRequest (com.amazonaws.services.identitymanagement.model.AttachRolePolicyRequest)1 CreateAccessKeyRequest (com.amazonaws.services.identitymanagement.model.CreateAccessKeyRequest)1 CreateAccessKeyResult (com.amazonaws.services.identitymanagement.model.CreateAccessKeyResult)1 CreateAccountAliasRequest (com.amazonaws.services.identitymanagement.model.CreateAccountAliasRequest)1 CreateAccountAliasResult (com.amazonaws.services.identitymanagement.model.CreateAccountAliasResult)1 CreatePolicyRequest (com.amazonaws.services.identitymanagement.model.CreatePolicyRequest)1 CreatePolicyResult (com.amazonaws.services.identitymanagement.model.CreatePolicyResult)1 CreateUserRequest (com.amazonaws.services.identitymanagement.model.CreateUserRequest)1 CreateUserResult (com.amazonaws.services.identitymanagement.model.CreateUserResult)1 DeleteAccessKeyRequest (com.amazonaws.services.identitymanagement.model.DeleteAccessKeyRequest)1 DeleteAccessKeyResult (com.amazonaws.services.identitymanagement.model.DeleteAccessKeyResult)1 DeleteAccountAliasRequest (com.amazonaws.services.identitymanagement.model.DeleteAccountAliasRequest)1