software.amazon.awssdk.services.iam.model.AccessKeyMetadata Java Examples

The following examples show how to use software.amazon.awssdk.services.iam.model.AccessKeyMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsIamUserScannerTest.java    From clouditor with Apache License 2.0 4 votes vote down vote up
@BeforeAll
static void setUpOnce() throws IOException {
  discoverAssets(
      IamClient.class,
      AwsIamUserScanner::new,
      api -> {
        when(api.listUsers())
            .thenReturn(
                ListUsersResponse.builder()
                    .users(
                        User.builder().arn(USER1_ARN).userName("USER1").build(),
                        User.builder().arn(USER2_ARN).userName("USER2").build(),
                        User.builder().arn(USER3_ARN).userName("USER3").build())
                    .build());

        when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER1").build()))
            .thenReturn(ListMfaDevicesResponse.builder().build());

        when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER1").build()))
            .thenReturn(
                ListGroupsForUserResponse.builder()
                    .groups(Group.builder().groupName("some-group").build())
                    .build());

        when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER1").build()))
            .thenReturn(
                ListAccessKeysResponse.builder()
                    .accessKeyMetadata(
                        AccessKeyMetadata.builder().accessKeyId("some-key").build())
                    .build());

        when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER2").build()))
            .thenReturn(
                ListMfaDevicesResponse.builder()
                    .mfaDevices(MFADevice.builder().serialNumber("1234556").build())
                    .build());

        when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER2").build()))
            .thenReturn(
                ListGroupsForUserResponse.builder()
                    .groups(Group.builder().groupName("some-group").build())
                    .build());

        when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER2").build()))
            .thenReturn(
                ListAccessKeysResponse.builder()
                    .accessKeyMetadata(AccessKeyMetadata.builder().accessKeyId("old-key").build())
                    .build());

        when(api.listMFADevices(ListMfaDevicesRequest.builder().userName("USER3").build()))
            .thenReturn(ListMfaDevicesResponse.builder().build());

        when(api.listGroupsForUser(ListGroupsForUserRequest.builder().userName("USER3").build()))
            .thenReturn(ListGroupsForUserResponse.builder().build());

        when(api.listAccessKeys(ListAccessKeysRequest.builder().userName("USER3").build()))
            .thenReturn(
                ListAccessKeysResponse.builder()
                    .accessKeyMetadata(
                        AccessKeyMetadata.builder()
                            .accessKeyId("some-key")
                            .status(StatusType.INACTIVE)
                            .build())
                    .build());

        when(api.getAccessKeyLastUsed(
                GetAccessKeyLastUsedRequest.builder().accessKeyId("some-key").build()))
            .thenReturn(
                GetAccessKeyLastUsedResponse.builder()
                    .accessKeyLastUsed(
                        AccessKeyLastUsed.builder().lastUsedDate(Instant.now()).build())
                    .build());

        when(api.getAccessKeyLastUsed(
                GetAccessKeyLastUsedRequest.builder().accessKeyId("old-key").build()))
            .thenReturn(
                GetAccessKeyLastUsedResponse.builder()
                    .accessKeyLastUsed(
                        AccessKeyLastUsed.builder().lastUsedDate(Instant.MIN).build())
                    .build());
      });
}