com.amazonaws.services.kms.model.EnableKeyRequest Java Examples

The following examples show how to use com.amazonaws.services.kms.model.EnableKeyRequest. 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: KMSManagerTest.java    From strongbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWhenDisabledForce() throws Exception {
    // Mocks the responses from AWS when the key starts in the disabled state.
    when(mockKMSClient.describeKey(describeKeyRequest))
            .thenReturn(disabledKeyResult())
            .thenReturn(disabledKeyResult()) // still waiting for state change
            .thenReturn(enabledKeyResult());

    // Check the result from create method.
    String arn = kmsManager.create(true);
    assertEquals(arn, KMS_ARN);

    // Verify correct number of calls was made to AWS.
    verify(mockKMSClient, times(3)).describeKey(describeKeyRequest);
    verify(mockKMSClient, times(1)).enableKey(new EnableKeyRequest().withKeyId(KMS_ARN));
    verify(mockKMSClient, never()).createKey(any());
    verify(mockKMSClient, never()).cancelKeyDeletion(any());
}
 
Example #2
Source File: KMSManagerTest.java    From strongbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWhenPendingDeletionForce() throws Exception {
    // Mocks the responses from AWS when the key starts in the pending deletion state.
    when(mockKMSClient.describeKey(describeKeyRequest))
            .thenReturn(pendingDeletionKeyResult())
            .thenReturn(pendingDeletionKeyResult()) // still waiting for state change
            .thenReturn(enabledKeyResult());

    // Check the result from create method.
    String arn = kmsManager.create(true);
    assertEquals(arn, KMS_ARN);

    // Verify correct number of calls was made to AWS.
    verify(mockKMSClient, times(3)).describeKey(describeKeyRequest);
    verify(mockKMSClient, times(1)).cancelKeyDeletion(new CancelKeyDeletionRequest().withKeyId(KMS_ARN));
    verify(mockKMSClient, times(1)).enableKey(new EnableKeyRequest().withKeyId(KMS_ARN));
    verify(mockKMSClient, never()).createKey(any());
}
 
Example #3
Source File: EnableCustomerMasterKey.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    final String USAGE =
        "To run this example, supply a key id or ARN\n" +
        "Usage: EnableCustomerMasterKey <key-id>\n" +
        "Example: EnableCustomerMasterKey 1234abcd-12ab-34cd-56ef-1234567890ab\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String keyId = args[0];

    AWSKMS kmsClient = AWSKMSClientBuilder.standard().build();

    // Enable a CMK

    EnableKeyRequest req = new EnableKeyRequest().withKeyId(keyId);
    kmsClient.enableKey(req);

}
 
Example #4
Source File: MockKMSClient.java    From aws-encryption-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public EnableKeyResult enableKey(EnableKeyRequest arg0) throws AmazonServiceException, AmazonClientException {
    throw new java.lang.UnsupportedOperationException();
}