Search in sources :

Example 16 with IamException

use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.

the class ListAccessKeys method listKeys.

// snippet-start:[iam.java2.list_access_keys.main]
public static void listKeys(IamClient iam, String userName) {
    try {
        boolean done = false;
        String newMarker = null;
        while (!done) {
            ListAccessKeysResponse response;
            if (newMarker == null) {
                ListAccessKeysRequest request = ListAccessKeysRequest.builder().userName(userName).build();
                response = iam.listAccessKeys(request);
            } else {
                ListAccessKeysRequest request = ListAccessKeysRequest.builder().userName(userName).marker(newMarker).build();
                response = iam.listAccessKeys(request);
            }
            for (AccessKeyMetadata metadata : response.accessKeyMetadata()) {
                System.out.format("Retrieved access key %s", metadata.accessKeyId());
            }
            if (!response.isTruncated()) {
                done = true;
            } else {
                newMarker = response.marker();
            }
        }
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ListAccessKeysResponse(software.amazon.awssdk.services.iam.model.ListAccessKeysResponse) AccessKeyMetadata(software.amazon.awssdk.services.iam.model.AccessKeyMetadata) ListAccessKeysRequest(software.amazon.awssdk.services.iam.model.ListAccessKeysRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 17 with IamException

use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.

the class ListServerCertificates method listCertificates.

// snippet-start:[iam.java2.list_server_certificates.main]
public static void listCertificates(IamClient iam) {
    try {
        boolean done = false;
        String newMarker = null;
        while (!done) {
            ListServerCertificatesResponse response;
            if (newMarker == null) {
                ListServerCertificatesRequest request = ListServerCertificatesRequest.builder().build();
                response = iam.listServerCertificates(request);
            } else {
                ListServerCertificatesRequest request = ListServerCertificatesRequest.builder().marker(newMarker).build();
                response = iam.listServerCertificates(request);
            }
            for (ServerCertificateMetadata metadata : response.serverCertificateMetadataList()) {
                System.out.printf("Retrieved server certificate %s", metadata.serverCertificateName());
            }
            if (!response.isTruncated()) {
                done = true;
            } else {
                newMarker = response.marker();
            }
        }
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ServerCertificateMetadata(software.amazon.awssdk.services.iam.model.ServerCertificateMetadata) ListServerCertificatesResponse(software.amazon.awssdk.services.iam.model.ListServerCertificatesResponse) ListServerCertificatesRequest(software.amazon.awssdk.services.iam.model.ListServerCertificatesRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 18 with IamException

use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.

the class UpdateAccessKey method updateKey.

// snippet-start:[iam.java2.update_access_key.main]
public static void updateKey(IamClient iam, String username, String accessId, String status) {
    try {
        if (status.toLowerCase().equalsIgnoreCase("active")) {
            statusType = StatusType.ACTIVE;
        } else if (status.toLowerCase().equalsIgnoreCase("inactive")) {
            statusType = StatusType.INACTIVE;
        } else {
            statusType = StatusType.UNKNOWN_TO_SDK_VERSION;
        }
        UpdateAccessKeyRequest request = UpdateAccessKeyRequest.builder().accessKeyId(accessId).userName(username).status(statusType).build();
        iam.updateAccessKey(request);
        System.out.printf("Successfully updated the status of access key %s to" + "status %s for user %s", accessId, status, username);
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : UpdateAccessKeyRequest(software.amazon.awssdk.services.iam.model.UpdateAccessKeyRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Example 19 with IamException

use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.

the class UpdateUser method updateIAMUser.

// snippet-start:[iam.java2.update_user.main]
public static void updateIAMUser(IamClient iam, String curName, String newName) {
    try {
        UpdateUserRequest request = UpdateUserRequest.builder().userName(curName).newUserName(newName).build();
        iam.updateUser(request);
        System.out.printf("Successfully updated user to username %s", newName);
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : IamException(software.amazon.awssdk.services.iam.model.IamException) UpdateUserRequest(software.amazon.awssdk.services.iam.model.UpdateUserRequest)

Example 20 with IamException

use of software.amazon.awssdk.services.iam.model.IamException in project aws-doc-sdk-examples by awsdocs.

the class DeleteAccessKey method deleteKey.

// snippet-start:[iam.java2.delete_access_key.main]
public static void deleteKey(IamClient iam, String username, String accessKey) {
    try {
        DeleteAccessKeyRequest request = DeleteAccessKeyRequest.builder().accessKeyId(accessKey).userName(username).build();
        iam.deleteAccessKey(request);
        System.out.println("Successfully deleted access key " + accessKey + " from user " + username);
    } catch (IamException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteAccessKeyRequest(software.amazon.awssdk.services.iam.model.DeleteAccessKeyRequest) IamException(software.amazon.awssdk.services.iam.model.IamException)

Aggregations

IamException (software.amazon.awssdk.services.iam.model.IamException)24 AttachedPolicy (software.amazon.awssdk.services.iam.model.AttachedPolicy)3 GetPolicyRequest (software.amazon.awssdk.services.iam.model.GetPolicyRequest)3 GetPolicyResponse (software.amazon.awssdk.services.iam.model.GetPolicyResponse)3 IamWaiter (software.amazon.awssdk.services.iam.waiters.IamWaiter)3 AttachRolePolicyRequest (software.amazon.awssdk.services.iam.model.AttachRolePolicyRequest)2 CreatePolicyRequest (software.amazon.awssdk.services.iam.model.CreatePolicyRequest)2 CreatePolicyResponse (software.amazon.awssdk.services.iam.model.CreatePolicyResponse)2 EntityAlreadyExistsException (software.amazon.awssdk.services.iam.model.EntityAlreadyExistsException)2 ListAttachedRolePoliciesRequest (software.amazon.awssdk.services.iam.model.ListAttachedRolePoliciesRequest)2 ListAttachedRolePoliciesResponse (software.amazon.awssdk.services.iam.model.ListAttachedRolePoliciesResponse)2 IOException (java.io.IOException)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 AccessKeyMetadata (software.amazon.awssdk.services.iam.model.AccessKeyMetadata)1 CreateAccessKeyRequest (software.amazon.awssdk.services.iam.model.CreateAccessKeyRequest)1 CreateAccessKeyResponse (software.amazon.awssdk.services.iam.model.CreateAccessKeyResponse)1 CreateAccountAliasRequest (software.amazon.awssdk.services.iam.model.CreateAccountAliasRequest)1 CreateRoleRequest (software.amazon.awssdk.services.iam.model.CreateRoleRequest)1